AdWords
5.1K members online now
5.1K members online now
Dive into advanced features like Remarketing, Flexible Bid Strategies, AdWords Editor, and AdWords Scripts
Guide Me
star_border
Reply

Using external data from a spreadsheet in a script

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hello everyone,

 
I'm using a script that pauses my campaign when a certain budget is reached.
 
here is the script :
 
var CUTOFF_COST = 120;
 
function main() {
var campaignIterator = AdWordsApp.campaigns()
      .withCondition('Name = "name_of_campaign"')
      .get();
  
  while (campaignIterator.hasNext()) {
   var campaign = campaignIterator.next();
   if (campaign.getStatsFor("ALL_TIME").getCost() > CUTOFF_COST) {
      campaign.pause();
   }
  }
}
 
 
Now I would like to use a online spreadsheet to containing 2 columns : 'campaign' and 'budget' where I would put all my campaigns & budgets to be used in the script
So my var CUTOFF_COST looks in the budget column 
and the name_of_campaign in my campaign column
 
 
Does anyone know how to do this ? 

Thanks a lot !
 
Cyrille
1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author Cyrille B
March 2017

Re: Using external data from a spreadsheet in a script

Follower ✭ ✭ ✭
# 2
Follower ✭ ✭ ✭

Hi Cyrille

 

Please try following code.

 

var sheet = SpreadsheetApp.openByUrl('YOUR_SPREADSHEET_URL').getSheetByName('YOUR_SHEET_NAME');
var items = sheet.getDataRange().getValues();

// if first row is header, i = 0 replace to i = 1 for (var i = 0; i < items.length; i++) { var campaign_name = items[i][0]; // First Column var cutoff_cost = items[i][1]; // Second Column Logger.log(campaign_name + ' : ' + cutoff_cost); }

View solution in original post

Marked as Best Answer.
Solution
Accepted by topic author Cyrille B
March 2017

Re: Using external data from a spreadsheet in a script

Follower ✭ ✭ ✭
# 2
Follower ✭ ✭ ✭

Hi Cyrille

 

Please try following code.

 

var sheet = SpreadsheetApp.openByUrl('YOUR_SPREADSHEET_URL').getSheetByName('YOUR_SHEET_NAME');
var items = sheet.getDataRange().getValues();

// if first row is header, i = 0 replace to i = 1 for (var i = 0; i < items.length; i++) { var campaign_name = items[i][0]; // First Column var cutoff_cost = items[i][1]; // Second Column Logger.log(campaign_name + ' : ' + cutoff_cost); }

Using external data from a spreadsheet in a script

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

It works ! THanks so much !