Google Ads script. Upload AdWords Campaigns Directly from Google Doc

Have you ever wanted an easy automatic solution that would organize and upload hundreds, or even thousands keywords to your Google Ads account without Editor and Excel? 

We had been spending more then 10,000 hours uploading campaigns using Excel and Google Ads Editor. It was the most time consuming task. Hence we wrote a script allowing us to upload campaigns directly from Google Doc using SKAG structure.  

Relevance is a key success factor in PPC. Being relevant has been rewarded with higher quality scores and as a result, a lower cost per click.

In order to build relevant PPC campaigns you should be able to add separate ad copies for each of your target keywords. This can be achieved by only using the SKAG structure. SKAG means “single keyword per ad group,” meaning in each of your ad groups you are using only one keyword. With SKAG you can:

  1. Create separate, relevant ads for each of your target keywords
  2. Create additional extensions for each of your keywords
  3. Set target CPA bids individually for each keyword on an ad group level

We have been using this structure in all of our accounts for years and it has turned out to be very easy to manage. However, if you didn’t use it before, at first you may be surprised to see something like “Product Broad Match” campaigns in a screenshot. But you will love SKAG and immediately see how sexy is it!

We always create campaigns in exact and BMM match types to reallocate budgets to more profitable campaigns; usually exact match keywords have higher conversion rates.

Now, let’s go through the steps to set up your Google Ads campaign.

Step 1. Prepare Google doc with target keywords

  1. Make a copy of this template 
  2. Paste the list of your target keywords and ads
  3. If you need to create more than 2 campaigns add additional tabs.

Step 2. Upload campaigns

Navigate to Bulk Actions> Scripts

 

To add a script from MMC level copy and paste the following code:

function main(){

      var mccAccount =  AdWordsApp.currentAccount('644-558-2469');
      var accountID = '443-484-0665'; // Don't forget to change!
      var childAccounts = MccApp.accounts().withIds([accountID]).get();
      var childAccount = childAccounts.next();
      MccApp.select(childAccount);

var SPREADSHEET_ID = '1PLc2IHf2YYeo_O9dSEldN4Jq4s9CXaBynuNHfHWlPXQ'; //Don't forget to change!
var ss = SpreadsheetApp.openById(SPREADSHEET_ID);
SpreadsheetApp.setActiveSpreadsheet(ss);
var sheets = ss.getSheets();
var columnsCampaign = [
'Campaign', 'Budget', 'Bid Strategy type', 'Campaign type', 'Campaign subtype'
];
var columnsAdgroups = ['Campaign', 'Ad group', 'Bid Strategy type', 'Default max. CPC'//, 'Ad', 'Description line 1', 'Description line 2', 'Description line 2', 'Display URL', 'Final URL'
];
var columnsKeywords = ['Campaign', 'Ad group', 'Keyword'
];
var columnsAds = ['Campaign', 'Ad group', 'Headline 1', 'Headline 2', 'Description', 'Path 1', 'Path 2', 'Final URL'
];
var uploadCampaign = AdWordsApp.bulkUploads().newCsvUpload(
	columnsCampaign, {moneyInMicros: false});
var uploadAdgroup = AdWordsApp.bulkUploads().newCsvUpload(
	columnsAdgroups, {moneyInMicros: false});
var uploadKeyword = AdWordsApp.bulkUploads().newCsvUpload(
	columnsKeywords, {moneyInMicros: false});
var uploadAds = AdWordsApp.bulkUploads().newCsvUpload(
  columnsAds, {moneyInMicros: false});
//adding BMM campaigns
for (var sheetNum = 0; sheetNum < sheets.length; sheetNum++){
  	SpreadsheetApp.setActiveSheet(sheets[sheetNum]);
  	var campaign = SpreadsheetApp.getActiveSheet().getName() + " BMM";
  	uploadCampaign.append({
    'Campaign': campaign,
    'Budget': 1,
    'Bid Strategy type': 'cpc',
    'Campaign type': 'Search Only',
    'Campaign subtype' : 'All features'
	});
	var values = SpreadsheetApp.getActiveSheet().getRange('A2:A').getValues();
	var values2 = SpreadsheetApp.getActiveSheet().getRange('B2:G').getValues();
    outer:
    for (var i = 0; i < values.length; i++) {
    var adgroup = values[i][0].toString().trim();
	    if (adgroup != '') {
			uploadAdgroup.append({
			'Campaign': campaign,
			'Ad group': adgroup,
			'Bid Strategy type': 'cpc',
			'Default max. CPC' : 1
			});
			var keyword = "+" + adgroup.replace(/ /g, ' +')
			uploadKeyword.append({
			'Campaign': campaign,
			'Ad group': adgroup,
			'Keyword': keyword
			});
			//Logger.log(keyword);
		      	for (var k = 0; k < values2.length; k++) {
		      	var adHead1 = values2[k][0].toString().trim();
		      	var adHead2 = values2[k][1].toString().trim();
		      	var adDescr = values2[k][2].toString().trim();
		      	var path1 = values2[k][3].toString().trim();
                var path2 = values2[k][4].toString().trim();
		      	var finalURL = values2[k][5].toString().trim();
			      	if (adHead1 != ''){
					uploadAds.append({
					'Campaign': campaign,
					'Ad group': adgroup,
					'Headline 1': adHead1,
					'Headline 2': adHead2,
					'Description': adDescr,
					'Path 1': path1,
                    'Path 2': path2,
					'Final URL' : finalURL
					});
					} else continue outer;
	    //Logger.log([campaign,adgroup,adHead,adDescr1,adDescr2,displURL,finalURL]);
			    }
		}
    }

}
//Adding Exact Campaigns
for (var sheetNum = 0; sheetNum < sheets.length; sheetNum++){
  	SpreadsheetApp.setActiveSheet(sheets[sheetNum]);
  	var campaign = SpreadsheetApp.getActiveSheet().getName() + " Exact";
  	uploadCampaign.append({
    'Campaign': campaign,
    'Budget': 1,
    'Bid Strategy type': 'cpc',
    'Campaign type': 'Search Only',
    'Campaign subtype' : 'All features'
	});
	var values = SpreadsheetApp.getActiveSheet().getRange('A2:A').getValues();
	var values2 = SpreadsheetApp.getActiveSheet().getRange('B2:G').getValues();
	outer:
	for (var i = 0; i < values.length; i++) {
    var adgroup = values[i][0].toString().trim();
	    if (adgroup != '') {
			uploadAdgroup.append({
			'Campaign': campaign,
			'Ad group': adgroup,
			'Bid Strategy type': 'cpc',
			'Default max. CPC' : 1
			});
			var keyword = '[' + adgroup + ']';
			uploadKeyword.append({
			'Campaign': campaign,
			'Ad group': adgroup,
			'Keyword': keyword
			});
		      	for (var k = 0; k < values2.length; k++) {
		      	var adHead1 = values2[k][0].toString().trim();
		      	var adHead2 = values2[k][1].toString().trim();
		      	var adDescr = values2[k][2].toString().trim();
		      	var path1 = values2[k][3].toString().trim();
                var path2 = values2[k][4].toString().trim();
		      	var finalURL = values2[k][5].toString().trim();
			      	if (adHead1 != ''){
					uploadAds.append({
					'Campaign': campaign,
					'Ad group': adgroup,
					'Headline 1': adHead1,
					'Headline 2': adHead2,
					'Description': adDescr,
					'Path 1': path1,
                    'Path 2': path2,
					'Final URL' : finalURL
					});
					} else continue outer;
	    //Logger.log([campaign,values[i][0],values2[k][0],values2[k][4]]);
			    }
			}
    //Logger.log([campaign,values[i][0],values2[0][0],values2[0][4]]);
	}
}

  
uploadCampaign.forCampaignManagement();
uploadAdgroup.forCampaignManagement();
uploadKeyword.forCampaignManagement();
uploadAds.forCampaignManagement();
uploadCampaign.apply();
Utilities.sleep(5000);
uploadAdgroup.apply();
Utilities.sleep(5000);
uploadAds.apply();
Utilities.sleep(5000);
uploadKeyword.apply(); 
}

To add code directly from your AdWords account use this code:

function main(){

var SPREADSHEET_ID = '1PLc2IHf2YYeo_O9dSEldN4Jq4s9CXaBynuNHfHWlPXQ'; //Don't forget to change!
var ss = SpreadsheetApp.openById(SPREADSHEET_ID);
SpreadsheetApp.setActiveSpreadsheet(ss);
var sheets = ss.getSheets();
var columnsCampaign = [
'Campaign', 'Budget', 'Bid Strategy type', 'Campaign type', 'Campaign subtype'
];
var columnsAdgroups = ['Campaign', 'Ad group', 'Bid Strategy type', 'Default max. CPC'//, 'Ad', 'Description line 1', 'Description line 2', 'Description line 2', 'Display URL', 'Final URL'
];
var columnsKeywords = ['Campaign', 'Ad group', 'Keyword'
];
var columnsAds = ['Campaign', 'Ad group', 'Headline 1', 'Headline 2', 'Description', 'Path 1', 'Path 2', 'Final URL'
];
var uploadCampaign = AdWordsApp.bulkUploads().newCsvUpload(
	columnsCampaign, {moneyInMicros: false});
var uploadAdgroup = AdWordsApp.bulkUploads().newCsvUpload(
	columnsAdgroups, {moneyInMicros: false});
var uploadKeyword = AdWordsApp.bulkUploads().newCsvUpload(
	columnsKeywords, {moneyInMicros: false});
var uploadAds = AdWordsApp.bulkUploads().newCsvUpload(
  columnsAds, {moneyInMicros: false});
//adding BMM campaigns
for (var sheetNum = 0; sheetNum < sheets.length; sheetNum++){
  	SpreadsheetApp.setActiveSheet(sheets[sheetNum]);
  	var campaign = SpreadsheetApp.getActiveSheet().getName() + " BMM";
  	uploadCampaign.append({
    'Campaign': campaign,
    'Budget': 1,
    'Bid Strategy type': 'cpc',
    'Campaign type': 'Search Only',
    'Campaign subtype' : 'All features'
	});
	var values = SpreadsheetApp.getActiveSheet().getRange('A2:A').getValues();
	var values2 = SpreadsheetApp.getActiveSheet().getRange('B2:G').getValues();
    outer:
    for (var i = 0; i < values.length; i++) {
    var adgroup = values[i][0].toString().trim();
	    if (adgroup != '') {
			uploadAdgroup.append({
			'Campaign': campaign,
			'Ad group': adgroup,
			'Bid Strategy type': 'cpc',
			'Default max. CPC' : 1
			});
			var keyword = "+" + adgroup.replace(/ /g, ' +')
			uploadKeyword.append({
			'Campaign': campaign,
			'Ad group': adgroup,
			'Keyword': keyword
			});
			//Logger.log(keyword);
		      	for (var k = 0; k < values2.length; k++) {
		      	var adHead1 = values2[k][0].toString().trim();
		      	var adHead2 = values2[k][1].toString().trim();
		      	var adDescr = values2[k][2].toString().trim();
		      	var path1 = values2[k][3].toString().trim();
                var path2 = values2[k][4].toString().trim();
		      	var finalURL = values2[k][5].toString().trim();
			      	if (adHead1 != ''){
					uploadAds.append({
					'Campaign': campaign,
					'Ad group': adgroup,
					'Headline 1': adHead1,
					'Headline 2': adHead2,
					'Description': adDescr,
					'Path 1': path1,
                    'Path 2': path2,
					'Final URL' : finalURL
					});
					} else continue outer;
	    //Logger.log([campaign,adgroup,adHead,adDescr1,adDescr2,displURL,finalURL]);
			    }
		}
    }

}
//Adding Exact Campaigns
for (var sheetNum = 0; sheetNum < sheets.length; sheetNum++){
  	SpreadsheetApp.setActiveSheet(sheets[sheetNum]);
  	var campaign = SpreadsheetApp.getActiveSheet().getName() + " Exact";
  	uploadCampaign.append({
    'Campaign': campaign,
    'Budget': 1,
    'Bid Strategy type': 'cpc',
    'Campaign type': 'Search Only',
    'Campaign subtype' : 'All features'
	});
	var values = SpreadsheetApp.getActiveSheet().getRange('A2:A').getValues();
	var values2 = SpreadsheetApp.getActiveSheet().getRange('B2:G').getValues();
	outer:
	for (var i = 0; i < values.length; i++) {
    var adgroup = values[i][0].toString().trim();
	    if (adgroup != '') {
			uploadAdgroup.append({
			'Campaign': campaign,
			'Ad group': adgroup,
			'Bid Strategy type': 'cpc',
			'Default max. CPC' : 1
			});
			var keyword = '[' + adgroup + ']';
			uploadKeyword.append({
			'Campaign': campaign,
			'Ad group': adgroup,
			'Keyword': keyword
			});
		      	for (var k = 0; k < values2.length; k++) {
		      	var adHead1 = values2[k][0].toString().trim();
		      	var adHead2 = values2[k][1].toString().trim();
		      	var adDescr = values2[k][2].toString().trim();
		      	var path1 = values2[k][3].toString().trim();
                var path2 = values2[k][4].toString().trim();
		      	var finalURL = values2[k][5].toString().trim();
			      	if (adHead1 != ''){
					uploadAds.append({
					'Campaign': campaign,
					'Ad group': adgroup,
					'Headline 1': adHead1,
					'Headline 2': adHead2,
					'Description': adDescr,
					'Path 1': path1,
                    'Path 2': path2,
					'Final URL' : finalURL
					});
					} else continue outer;
	    //Logger.log([campaign,values[i][0],values2[k][0],values2[k][4]]);
			    }
			}
    //Logger.log([campaign,values[i][0],values2[0][0],values2[0][4]]);
	}
}

  
uploadCampaign.forCampaignManagement();
uploadAdgroup.forCampaignManagement();
uploadKeyword.forCampaignManagement();
uploadAds.forCampaignManagement();
uploadCampaign.apply();
Utilities.sleep(5000);
uploadAdgroup.apply();
Utilities.sleep(5000);
uploadAds.apply();
Utilities.sleep(5000);
uploadKeyword.apply(); 
}

Step 3. Preview and run the script. Wait for 5 mins. 

Contact us if you have any questions.