Changing shared budgets automatically over the weekend

664 views
Skip to first unread message

ppc0r

unread,
Mar 23, 2021, 6:06:45 PM3/23/21
to Google Ads Scripts Forum
Dear team,

I'm looking for an option to adapt a shared budget or several shared budgets automatically over weekend ( + 20%). What is the best way to do that?

So far I tried this:

function main()
{
  var Iterator = AdWordsApp.budgets().withCondition(“BudgetName = ‘SB2’“).get();
  while(Iterator.hasNext())
  {
  var budget = Iterator.next();
  budget.setAmount(5);
  }
}

So I set two budgets, one for under the week one for the weekend and the script should update those automatically. Unfortuntely this doesn't work, is there a better way to do it? 

Best regards
Paul

Google Ads Scripts Forum Advisor

unread,
Mar 23, 2021, 11:15:23 PM3/23/21
to adwords...@googlegroups.com
Hi Paul, 

Thanks for reaching out. I am Harry from the Google Ads Scripts Team. Allow me to assist you on this.

It does seem to me that the script you have provided should work as expected. Can you kindly provide context as to how this is not working at your end? On the other hand, I am assuming that you have two separate scripts in this regard as you you would like to manage two budgets? Or are you aiming to have a single script that would update the budget when it is a weekend, then change it back to its budget for when it's a weekday?

Let me know your thoughts. 

 
Thanks,
Google Logo
Harry Cliford Rivera
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2EmdSN:ref

ppc0r

unread,
Mar 24, 2021, 4:33:01 AM3/24/21
to Google Ads Scripts Forum
Hey Harry,

thank you so much so your quick reply!

I get the following error: 

Illegal character. (line 3)

2021-03-24 09_31_46-Otago - Google Ads.png

So I have two Shared Budgets called SB1 and SB2: The goal is either to change SB1 to SB2 on Friday and change it back on Monday or simply lowering or raising the Budget by 20% (or set a new amount).So if that's possible with just one script it would be totally fine for me.

Thank you!

Google Ads Scripts Forum Advisor

unread,
Mar 24, 2021, 6:02:12 AM3/24/21
to adwords...@googlegroups.com
Hi Paul,
 

Thanks for providing the error screenshot. It seems that the quotes are encoded into different characters. Kindly try this syntax: "withCondition("BudgetName = 'SB1' ")" instead and let me know how it goes. You may opt to write two separate code blocks for changing the amount of the two shared budgets.

In addition, you can have the script to execute daily to check whether today is a weekday or a weekend by making use of the Date.getDay JavaScript method which returns an integer number, between 0 and 6, corresponding to the day of the week for the given date, according to local time: 0 for Sunday, 1 for Monday, 2 for Tuesday, and so on., then change the budgets accordingly.

Let me know if you have questions.

Kratzwald, Paul

unread,
Mar 24, 2021, 6:41:43 AM3/24/21
to Google Ads Scripts Forum on behalf of adsscriptsforumadvisor
Hi Harry,

thank you so much for your support. Guess the Date.getDay function is still a bit too advanced for me, I'm just starting out with scripts and javascript :))

But as you mentioned previously, I can just set up two rules and let them run weekly...that should do the trick.

Additionally, if I may ask, how can I add an automated email showing me the amount the budget is set when the script executes? Like every Friday and Monday automatically so I know everything is fine?

Best
Paul

--
-- You received this message because you are subscribed to the Google Groups AdWords Scripts Forum group. Please do not reply to this email. To post to this group or unsubscribe please visit https://developers.google.com/adwords/scripts/community.
---
You received this message because you are subscribed to a topic in the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/adwords-scripts/gngmUxIxU-s/unsubscribe.
To unsubscribe from this group and all its topics, send an email to adwords-scrip...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-scripts/5Y2YA000000000000000000000000000000000000000000000QQGX7J00OTvxwwn1QSSqVVNbtyHp5w%40sfdc.net.

Google Ads Scripts Forum Advisor

unread,
Mar 24, 2021, 11:14:47 PM3/24/21
to adwords...@googlegroups.com
Hi Paul,

Thanks for pointing that out. Allow me to explain and illustrate the Date.getDay further. I was suggesting this JavaScript method as scheduling Google Ads Scripts currently does not support day of the week (Eg. Monday or Friday). You can choose the script to run at an exact date, a day of the week, or a day of the month. You can also choose the time you'd like your script to run, but not in a specific day. Please see Scheduling a script section in this link.

The Date.getDay() returns an integer which corresponds to a day of the week. 1 is equal to Monday and 5 is Friday. With this method, you can check when should the script change/adjust the budget amounts. The script will have to run daily and check if it is a Monday or a Friday, then proceed accordingly. Please see example code snippet below:
 
var today = new Date();
if(today.getDay() == 1) {
// Adjust Budget for a Monday
}
else if(today.getDay() == 5) {
// Adjust Budget for a Friday
} else {
// Other days. Do nothing.
}

Let me know if you would need further assistance. I'd be happy to help out.

ppc0r

unread,
Mar 25, 2021, 1:04:21 PM3/25/21
to Google Ads Scripts Forum
Dear Harry,

thank you so much for your great support, highly appreciated. Works flawlessly now, maybe you could be so kind and also help me out with my last request for this script:

Additionally, if I may ask, how can I add an automated email showing me the amount the budget is set when the script executes? Like every Friday and Monday automatically so I know everything is fine?

Best 
Paul


Google Ads Scripts Forum Advisor

unread,
Mar 25, 2021, 11:11:17 PM3/25/21
to adwords...@googlegroups.com
Hi Paul,

You may retrieve a budget's details like this example and send these details with an email by using the MailApp service. Kindly refer to this example on sending a simple email.
Reply all
Reply to author
Forward
0 new messages