Script to Upload Updated Target CPAs from Google Sheets

231 views
Skip to first unread message

daniel...@avast.com

unread,
Jul 18, 2018, 5:45:35 AM7/18/18
to AdWords Scripts Forum
Hi guys,

I have a table in Google Sheets:
Campaign | Ad Group | Target CPA
+5000 rows.

I want to update tCPA bids on ad group level based on the Google Sheet.

Anyone having this script in stock? It must exist :)

DZ

daniel...@avast.com

unread,
Jul 18, 2018, 9:37:52 AM7/18/18
to AdWords Scripts Forum
Like this:

function main() {
  // The format of this spreadsheet should match a valid bulk upload template.
  // for the list of supported bulk upload templates.

  var spreadSheet = SpreadsheetApp.openById("spreadsheet ID")
  var sheet = spreadSheet.getSheetByName("sheetname")
  
  var lastRowOnTheSheet = sheet.getLastRow()
  
  var rangeWithBids = sheet.getRange("A2:"+lastRowOnTheSheet).getValues()
  
  //the [1] gets me just the first row
  Logger.log(rangeWithBids)
  
  for(i=1; i<rangeWithBids.length; i++) {
  
    var campaign = rangeWithBids[i][0];
    var ad_group = rangeWithBids[i][1];
    var targetCpa = rangeWithBids[i][2];
   
    AdWordsApp.adGroups().withCondition("CampaignName = '"+campaign+"'").withCondition("Name = '"+ad_group+"'").get().next().bidding().setCpa(targetCpa);  
    
  }  
  
  Logger.log('script finished')

}


Not that this is very slow and it takes about 20 minutes to update 2500 adgroups. Pretty sure the script could use some help with making it faster.

DZ
Reply all
Reply to author
Forward
0 new messages