Changing Shared Budgets Based on Day of Week

287 views
Skip to first unread message

Brian Jones

unread,
Dec 21, 2016, 9:37:50 AM12/21/16
to AdWords Scripts Forum
Hey Scripts team,

I'm wanting to change my daily budgets automatically based on day of week so more money can be spent on days that tend to drive more conversions. I know you can do this with Automated Rules, but they don't appear to work when you have a Shared Budget.

Is there any script available that can do this for Shared Budgets?

Here's what I have currently set up in Automated Rules: http://screencast.com/t/FshyAyJGMy

Thanks!

Anthony Madrigal

unread,
Dec 21, 2016, 11:53:38 AM12/21/16
to AdWords Scripts Forum
Hi Brian,

Although there is no script solution that fully does what you want, you can use the snippet below to get you started. You will want to schedule the script to Daily.

This script will check the day of week then change the budget accordingly:
function checkBudget() {
 
var today = new Date();  
 
//Returns a number 0-6. Sunday is 0, Monday is 1, etc.
 
var dayOfWeek = today.getDay();
 
 
//Selects all shared budgets
 
var budgetIterator = AdWordsApp.budgets().withCondition("IsBudgetExplicitlyShared = true").get();
 
while(budgetIterator.hasNext()){
   
var budget = budgetIterator.next();
   
//Checks if it is Wednesday
   
if(dayOfWeek == 3){
     budget
.setAmount(SOME_AMOUNT);
   
}
 
}
}

Regards,
Anthony
AdWords Scripts Team

Anna

unread,
Apr 13, 2017, 5:22:35 AM4/13/17
to AdWords Scripts Forum
Hi Anthony,
I found this script of yours and was going to use it on my account in order to change shared budget on a specific day. I'm getting an error saying  main function is not defined. Expected to find function main()
Would you be able to advise what needs to be changed?
Also, if I need to revert back to the previous budget the next day - is it just a matter of uploading another script with different amount and different day identified, right?
Thanks!
Anna

Anthony Madrigal

unread,
Apr 13, 2017, 9:19:38 AM4/13/17
to AdWords Scripts Forum
Hi Anna,

You can just change the function name from checkBudget to main. If you want to change the budget to a different amount for a different day, you can modify the code as such
function main() {

 
var today = new Date();  
 
//Returns a number 0-6. Sunday is 0, Monday is 1, etc.
 
var dayOfWeek = today.getDay();
 
 
//Selects all shared budgets
 
var budgetIterator = AdWordsApp.budgets().withCondition("IsBudgetExplicitlyShared = true").get();
 
while(budgetIterator.hasNext()){
   
var budget = budgetIterator.next();
   
//Checks if it is Wednesday
   
if(dayOfWeek == 3){
     budget
.setAmount(SOME_AMOUNT);
   
}

   
//Checks if it is Friday
   
else if(dayOfWeek == 5){
      budget
.setAmount(SOME_OTHER_AMOUNT)
   
}
 
}
}

If you are still facing issues, please create a new thread so that we can track the issue more easily.

Cheers,
Anthony
AdWords Scripts Team
Reply all
Reply to author
Forward
0 new messages