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

Help With Script - Campaign Settings Change

[ Edited ]
Explorer ✭ ✭ ✭
# 1
Explorer ✭ ✭ ✭

Hi All, 

 

I'm new to scripts. One of my clients needs two scripts to change between campaign bidding and budget settings. This is so they can alternate between higher, accelerated budgets and a normal, standard delivery budget. 

 

I managed to find this script for changing the budget but I could only apply it to one campaign and when I tried to preview, nothing came up. 

 

Can I have this apply to multiple campaigns? And if so can I add in the ability to change the delivery to accelerated?

function setCampaignBudget() {
  var campaignIterator = AdWordsApp.campaigns()
      .withCondition('Name = "INSERT_CAMPAIGN_NAME_HERE"')
      .get();
  if (campaignIterator.hasNext()) {
    var campaign = campaignIterator.next();
    campaign.getBudget().setAmount(100);
    Logger.log('Campaign with name = ' + campaign.getName() +
        ' has budget = ' + campaign.getBudget().getAmount());
  }
}

 

Thanks in advance! 

1 Expert replyverified_user

Re: Help With Script - Campaign Settings Change

Top Contributor
# 2
Top Contributor

Hi @Abbie R unfortunately, at the time of writing, Scripts cannot set the delivery method of a budget, only read (get) it, so the idea kind of falls at the first fence.

 

That said, it's an unusual request anyway.  There's really only a couple of instances where accelerated delivery is beneficial to a Campaign, and none at all where the budget is sufficient to reach all potential impressions (in other words, if the Campaign is not limited by budget, there's absolutely no difference in the delivery of accelerated or standard).


What's the reasoning behind the requirement?  If you can provide some more detail there may be another way to script a solution.

 

Jon

AdWords Top Contributor Google+ Profile | Partner Profile | AdWords Audits

Help With Script - Campaign Settings Change

Explorer ✭ ✭ ✭
# 3
Explorer ✭ ✭ ✭

Thanks Jon.

 

Basically, the client has been running duplicate campaigns with different budgets which they switch between when they want more or less work. The issue is they are often left running at the same time and are double serving in lots of areas. 

 

I was trying to think of a better way to give them what they need without them needing to go into the account and pause/unpause campaigns (the client doesn't want to have to contact us every time... ) because they keep leaving other campaigns on at the same time. 

 

It's a set up I haven't seen before, so was unsure what to do. Wouldn't it be better just to change the budget on the same campaign, to keep the historic performance?  Instead of swapping between campaigns?  

Re: Help With Script - Campaign Settings Change

Top Contributor
# 4
Top Contributor

Hi @Abbie R, "Wouldn't it be better just to change the budget on the same campaign, to keep the historic performance?" well, yes, that's what I'd do.  If they're looking to control how much work they get through AdWords, then the best way to do that is to reduce the number of clicks they get and the best way to do that is to reduce the budget.  As an aside, if these two Campaigns are in the same Account, they would never actually have been "double-serving".  AdWords will only show one Ad for one domain name for any auction.

 

Are they able / would you want them to change the budget themselves?  If not, what you could do with a script is set up a shared Google spreadsheet with the Campaign names in column A and their daily (or monthly, whichever is easier/more logical) budget in column B.  The script would read this doc every day (or possibly every hour, depending upon how critical the changes are) then make adjustments as necessary.  That way they'd never have to actually log in to AdWords and would have an easier method of visibly seeing their budgets all in one place.  You, of course, would also have access to this doc and be able to check it periodically and/or you could set up alerts (via email) if their figures looked silly.

 

Jon

AdWords Top Contributor Google+ Profile | Partner Profile | AdWords Audits

Help With Script - Campaign Settings Change

Explorer ✭ ✭ ✭
# 5
Explorer ✭ ✭ ✭

 

I'll have to do some reading up on the use of scripts and Google sheets. Think I used the term double serving incorrectly there. Was just referring to duplicate keywords in different campaigns with the same settings (besides budget), so not double-serving in the auction so to speak. 

 

Great information though thank you, if you can share any example scripts or information I'd really appreciate it!

 

Thanks again Smiley Happy

 

 

Re: Help With Script - Campaign Settings Change

Top Contributor
# 6
Top Contributor

Hi @Abbie R fetching data from a spreadsheet is really easy, you can do it in these few lines of script:

var theSheet = SpreadsheetApp.openByUrl(SPREADURL).getSheetByName("Budgets");
if(theSheet) { // make sure the sheet was fetched OK
  var values = theSheet.getDataRange().getValues();
}

where SPREADURL is the URL of the Google docs spreadsheet (I tend to define this with a line at the top of the script, so it's easy to see and change), obviously you'd use your own sheet name as appropriate (there are other methods of fetching a particular sheet, but I like using a name).  The code above will fetch the complete "range" of filled cells on that sheet, and the variable values will then hold that data in the format values[r][c] (where c is column number and r is row number).  So values[2][4] would contain the value of the cell in row 3, column 5 (all numbers begin at 0!).

 

It's likely you'll want a heading row on your sheet, and if you want to fetch only the valid Campaign name/budget amount pairs, you know you only want those columns, etc. so you'll probably want to follow the above code with something like:

//step through the rows of the spreadsheet, starts at 1 because first row (0) is headings
var budgetArray = []; for (var i = 1;i<values.length;i++) { if(values[i][0] != "" && values[i][1] != "") { // only add rows with data in both column 1 & 2 budgetArray.push([values[i][0],values[i][1]]); } }

So, after this, the variable budgetArray should contain an array of Campaign names and budgets, where budgetArray[n][0] is the Campaign name and budgetArray[n][1] is the budget figure.

 

Once you've got that, all you have to do is use a Campaign selector/iterator to pick up the Campaigns with the listed names and then apply the budget amount.  I'll leave that bit to you!

 

Jon

AdWords Top Contributor Google+ Profile | Partner Profile | AdWords Audits

Re: Help With Script - Campaign Settings Change

Explorer ✭ ✭ ✭
# 7
Explorer ✭ ✭ ✭

Hi Jon,

 

Sorry I'm new to scripts. So I have this:

 

function main() {
  
var theSheet = SpreadsheetApp.openByUrl(https://docs.google.com/spreadsheets/d/1gVnzKo0AXB0TTvUotJQhm0fyWXPTIiVx-6R510iSiy0/edit?usp=sharing).getSheetByName("Fix My Appliances Budget");
if(theSheet) { // make sure the sheet was fetched OK
  var values = theSheet.getDataRange().getValues();
}
  //step through the rows of the spreadsheet, starts at 1 because first row (0) is headings
var budgetArray = [];
for (var i = 1;i<values.length;i++) {
  if(values[i][0] != "" && values[i][1] != "") {  // only add rows with data in both column 1 & 2
    budgetArray.push([values[i][0],values[i][1]]);
  }
}

Obviously leaving your comments in there if I can. 

 

What do I need to change now? is "i" the column? I'm a bit confused.

 

With the campaign selector, I thought having the campaign names in the sheet would apply the changes to those campaigns?