changing daily budget each day

1,174 views
Skip to first unread message

Yaniv Lev-Ari

unread,
May 5, 2013, 11:18:51 AM5/5/13
to adwords...@googlegroups.com
I want to find a way to change daily budget to 40% on friday,
20% on saturday,
150% on sunday,
and 100% on the rest of the week,

but when I change the daily budget on sunday to 150%,
it becomes like 30% (50% more of saturday).

Any suggestion?

Alan Daitch

unread,
May 5, 2013, 4:08:20 PM5/5/13
to adwords...@googlegroups.com
Hi! How are you doing it? You can do it using automated rules instead of AdWords scripts, I think it's easiest

Kevin Winter (AdWords Scripts Team)

unread,
May 7, 2013, 11:21:01 AM5/7/13
to adwords...@googlegroups.com
If you want to use scripts, there are definitely a few ways to do it.

One approach would be to set up a spreadsheet to embed both the original budget amount as well as the schedule of changes.  Each day the script runs and checks if it should change the budget for TODAY and looks up the appropriate amount, multiply against the original amount and update it.

You could also hardcode the amounts for each day if the amount is more important than the % change - this avoids needing to record the original value, but is less flexible.

If you just wanted to alter bidding (and not budget), you could look into ad scheduling: https://support.google.com/adwords/answer/2404244?hl=en

- Kevin Winter
AdWords Scripts Team

Yaniv Lev-Ari

unread,
Jul 28, 2013, 8:39:57 AM7/28/13
to adwords...@googlegroups.com
Is there any way to check if today is sunday or friday or anything else?

Anash Oommen

unread,
Jul 28, 2013, 11:53:24 PM7/28/13
to adwords...@googlegroups.com
Hi Yaniv,

getDay() should work. See http://www.w3schools.com/jsref/jsref_getday.asp for details.

Cheers,
Anash P. Oommen,
AdWords Scripts Team

Jehrymine Pike

unread,
Aug 8, 2013, 9:17:24 PM8/8/13
to adwords...@googlegroups.com
Can you please give me a copy of the code? Adjusting daily budget with absolute numbers are my problem as well. TIA

Yaniv Lev-Ari

unread,
Aug 9, 2013, 10:09:09 AM8/9/13
to adwords...@googlegroups.com
I have a client that work on sun till thu
the campaign run with the same budget for each day, 
but a week ago he said that he get more leads and phone calls on Sunday and Thursday, more than he wants,
and less than he wants of the other days.

His budget was 600$ a week, so,
instead of using 20% of the weekly budget every day, 
we change it to 13% on Sunday and Thursday, (12.5% * 600 = 75)
and 25% on the other days ( 600 * 0.25 = 150 )

It was easier for me to that, but of course I could write specific numbers instead.
I prefer variables instead of numbers, because that way if I want to change something, 
I only need to change the var, instead of searching it all over the script.


well, I've said enough. let's play:


function main() {
  /* Change campaign name to your campaign name */
  var campaignName = "main";
  var Weekly_Budget = 600;
  var SuThu_BUDGET = Weekly_Budget * 0.125;
  var MoTuWe_BUDGET = Weekly_Budget * 0.25;
  var d = new Date();
  var n = d.getDay();

  var campaignsIterator = AdWordsApp.campaigns()
      .withCondition("Name = '" + campaignName + "'")
      .get();
  

   if (campaignsIterator.hasNext()) 
   {
    var campaign = campaignsIterator.next();
   
/* 0 means sunday, 4.0 means thursday  */  
      if ((n=0)||(n=4.0))
    {  
      
     campaign.setBudget(SuThu_BUDGET);
      
    } else
          {
       campaign.setBudget(MoTuWe_BUDGET);
     }

  }
 
}

JJ

unread,
Aug 12, 2013, 9:51:50 PM8/12/13
to adwords...@googlegroups.com
this is good. i'm trying it now. thank you.

JJ

unread,
Aug 12, 2013, 10:56:45 PM8/12/13
to adwords...@googlegroups.com
Follow up question, i want to set a specific budget from sunday to saturday.
I've set an index, similar to what you did, now i want the script to follow it and I'm lost on the lower end of the script, can someone help me out?

This is my code so far:

function main() {
  var campaignName = "MyCampaignName";
  var Weekly_Budget = 700;
 
  var Su_BUDGET = Weekly_Budget * 0.10;
  var Mo_BUDGET = Weekly_Budget * 0.20;
  var Tu_BUDGET = Weekly_Budget * 0.19;
  var We_BUDGET = Weekly_Budget * 0.16;
  var Th_BUDGET = Weekly_Budget * 0.17;
  var Fr_BUDGET = Weekly_Budget * 0.09;
  var Sa_BUDGET = Weekly_Budget * 0.06; 
 
  var d = new Date();
  var n = d.getDay();

  var campaignsIterator = AdWordsApp.campaigns()
      .withCondition("Name = '" + campaignName + "'")
      .get();
 

   if (campaignsIterator.hasNext())
   {
    var campaign = campaignsIterator.next();

/* I'm lost in this area */  

     if ((n=0))
    { 
     
     campaign.setBudget(Su_BUDGET);
     
    } else
          {
       campaign.setBudget(Mo_BUDGET);

     }

  }
 
}

On Friday, August 9, 2013 10:09:09 PM UTC+8, Yaniv Lev-Ari wrote:

Alexander Wang

unread,
Aug 12, 2013, 11:16:31 PM8/12/13
to adwords...@googlegroups.com
Hi JJ,

That section of code checks if today is Sunday, and if it is, sets the budget to Su_BUDGET. If it is not, it sets it to Mo_BUDGET. It's not complete as if the script runs on a Tuesday (for example), it will set the budget to Mo_BUDGET (rather than Tu_BUDGET, which is what I assume you'd want it set to). FYI, getDay() returns a number between 0 and 6 to represent the day of the week (0 = Sunday, 6 = Saturday). If you want to make use of the other days of the week, you'd need to write additional if statements OR you could use a switch statement:
http://www.w3schools.com/js/js_switch.asp (take a look at the example which uses new Date().getDay()).

Also, as an aside, this code just operates on a single campaign. If you want to take action on more campaigns, you'll need to use a while loop ("while (campaignsIterator.hasNext())" instead of "if (campaignsIterator.hasNext())").

Cheers,
Alex

JJ

unread,
Aug 13, 2013, 12:49:03 AM8/13/13
to adwords...@googlegroups.com
I think I got it. What do you think?

function main() {
 
  var campaignName = "testCampaign";
  var Weekly_Budget = 7000;

 
  var Su_BUDGET = Weekly_Budget * 0.10;
  var Mo_BUDGET = Weekly_Budget * 0.20;
  var Tu_BUDGET = Weekly_Budget * 0.19;
  var We_BUDGET = Weekly_Budget * 0.16;
  var Th_BUDGET = Weekly_Budget * 0.17;
  var Fr_BUDGET = Weekly_Budget * 0.09;
  var Sa_BUDGET = Weekly_Budget * 0.06; 

  var campaignsIterator = AdWordsApp.campaigns()
      .withCondition("Name = '" + campaignName + "'")
      .get(); 

   if (campaignsIterator.hasNext())
   {
    var campaign = campaignsIterator.next();
  
  /* Switch statement */ 

     var day=new Date().getDay();
     switch (day)
     {
       case 0:
         campaign.setBudget(Su_BUDGET);
         break;
       case 1:
         campaign.setBudget(Mo_BUDGET);
         break;
       case 2:
         campaign.setBudget(Tu_BUDGET);
         break;
       case 3:
         campaign.setBudget(We_BUDGET);
         break;
       case 4:
         campaign.setBudget(Th_BUDGET);
         break;
       case 5:
         campaign.setBudget(Fr_BUDGET);
         break;
       case 6:
         campaign.setBudget(Sa_BUDGET);
         break;
     }
  
   }

}

Anash Oommen

unread,
Aug 13, 2013, 6:21:19 AM8/13/13
to adwords...@googlegroups.com
Yep, that should work fine. Just have to schedule your script to run daily.

Cheers,
Anash P. Oommen,
AdWords Scripts Team

Tuong Nguyen

unread,
Mar 5, 2014, 11:34:41 PM3/5/14
to adwords...@googlegroups.com
Hi Anash,
Can you please help explain why I ran the var today = new Date().getDay(); and the result is 3 (wednesday) instead of 4(thursday) ??
My Time now is 11:34 AM Thursday 6 March 2014
Thank you very much

Tuong Nguyen

unread,
Mar 5, 2014, 11:50:50 PM3/5/14
to Tuong Nguyen via AdWords Scripts Forum, adwords...@googlegroups.com
+and the time zone in my account setting is GMT +7
don't really know when script runs it will take what time zone?

Tuong Nguyen | SEM & Display Account Manager | Skype: cattuong89 | www.lazada.com | TH: +66851905611 | VN: +84903973627
Like and follow us                Download our app 
         


--
-- 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 the Google Groups "AdWords Scripts Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-scrip...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Anash Oommen

unread,
Mar 7, 2014, 12:54:09 PM3/7/14
to adwords...@googlegroups.com
Hi Tuong,

I think the script gives you the server's time zone if you do new Date(). You should use the account timezone from https://developers.google.com/adwords/scripts/docs/reference/adwordsapp/adwordsapp_account#getTimeZone_0 if you need to adjust it to your account's timezone.

Cheers,
Anash P. Oommen,
AdWords Scripts Team


On Wednesday, March 5, 2014 11:50:50 PM UTC-5, Tuong Nguyen wrote:
+and the time zone in my account setting is GMT +7
don't really know when script runs it will take what time zone?

Tuong Nguyen | SEM & Display Account Manager | Skype: cattuong89 | www.lazada.com | TH: +66851905611 | VN: +84903973627
Like and follow us                Download our app 
         


Yaniv Lev-Ari

unread,
Mar 13, 2014, 5:11:11 AM3/13/14
to adwords...@googlegroups.com
H,

I have the same problem.
I must run the script after 10am,
if I want to get yesterday's report,
because the server's time is gmt +7,
and I am gmt -2 

I know my timezone, 
but how can I use it, 

to ran the script at night,
instead of at 10am, like now?


בתאריך יום שישי, 7 במרץ 2014 19:54:09 UTC+2, מאת Anash Oommen:

LiefLokket

unread,
Mar 18, 2014, 10:32:45 PM3/18/14
to adwords...@googlegroups.com
Did Anyone get this script to work???

Looks promising, but i am not skilled enough to know how to complete the function.

Yaniv Lev-Ari

unread,
Mar 19, 2014, 3:22:46 AM3/19/14
to adwords...@googlegroups.com
It works great for me
:)

בתאריך יום רביעי, 19 במרץ 2014 04:32:45 UTC+2, מאת LiefLokket:

Yaniv Lev-Ari

unread,
Mar 19, 2014, 4:06:54 AM3/19/14
to adwords...@googlegroups.com
use this one:

function main() {
  // Replace with the name of your campaign.
  var campaignName = "main";
  var Weekly_Budget = 6000;
   
  var Su_BUDGET = Weekly_Budget * 0.125;
  var Mo_BUDGET = Weekly_Budget * 0.25;
  var Tu_BUDGET = Weekly_Budget * 0.25;
  var We_BUDGET = Weekly_Budget * 0.25;
  var Th_BUDGET = Weekly_Budget * 0.125;
  var Fr_BUDGET = 1;
  var Sa_BUDGET = 1;  

  var campaignsIterator = AdWordsApp.campaigns()
      .withCondition("Name = '" + campaignName + "'")
      .get();  

   if (campaignsIterator.hasNext()) 
   {
    var campaign = campaignsIterator.next();
   
Reply all
Reply to author
Forward
0 new messages