Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

Do you know Google's flexible budgets script that allows you to automatically distribute your monthly budget in an intelligent way?

user-image
Question added by Babu Raj Devi , Head of Marketing - Freelancer , Beyond Autos FZE
Date Posted: 2016/04/17
Ghada Eweda
by Ghada Eweda , Medical sales hospital representative , Pfizer pharmaceutical Plc.

First, thanks for invitation.

Yes, it is a script to set recurring monthly budgets in AdWords, there is a modified version of Google's flexible budgets script that allows you to automatically distribute your monthly budget in an intelligent way. This  AdWords script automation allows you to manage  your budgets. You can skip right to the end to copy and paste the script and run it in your account; or, for those who are interested in learning some AdWords scripting of their own, I’ll explain why and how I took an existing script from Google and adapted it to do something better.

One of the quirks of AdWords is that budgets are daily, rather than monthly. If you hadn’t yet joined Google when you decided to use daily budgets, so you don’t know exactly how that decision came to be, but if you was there for plenty of product meetings that dealt with budgeting issues. One of the most fruitless projects is one where we tried to give advertisers monthly budgets while still using the underlying daily budgeting method the system was built for.

Mohammed  Ashraf
by Mohammed Ashraf , Director of International Business , Saqr Al-Khayala Group

Once again, you are showing your creativity with very good answers Mr.Babu. 

Babu Raj Devi
by Babu Raj Devi , Head of Marketing - Freelancer , Beyond Autos FZE

Here is the process for Writing and Updating the Budget Script

 

My improved flexible budget script  - I wanted my script to automatically start a new budget period on the first of every month. I also wanted it to roll over any unused budgets from the previous month, assuming that the campaign was active all of last month.

Finally, I wanted a script to distribute the budget in a smarter way, based on historical day of week patterns.

Day-of-week budget distribution:

DAy of week

In my version of the script, we added day-of-the week budget allocation that takes into account historical performance. In this example, Wednesday and Thursday are days with big potential, so they get higher budgets than the other days, and in the end, it will be more likely that the full $ will be spent in the remaining days.

Setting daily budgets that account for day-of-week fluctuations

Distributing the budget based on what days remain in the month makes sense because when there are only three days left in the budget period, it makes a big difference what those days are.

Here’s an example. We used our Optmyzr Hour-of-Week Data Insight tool to plot the cost for an account for the various weekdays.

day-of-week-costs

Screen shot from Optmyzr’s Hour-Of-Week tool shows that more of this campaign’s budget is spent on Wednesday than on Sunday. This is important to know when we update budgets daily to help us meet a target monthly spend.

You can see Wednesday tends to have a higher cost than Friday, Saturday and Sunday. So it makes a big difference if the three remaining days in the budget period are Friday, Saturday and Sunday, or if they are Wednesday, Thursday and Friday. Since Friday, Saturday and Sunday usually spend around the same amount, the budget can be distributed evenly, and you will most likely hit your target.

However, an even distribution applied in the second example could reserve too much budget for Thursday and Friday, when there isn’t typically that much opportunity. Most of the budget should be spent on Wednesday.

This is where a day-of-week distribution comes in handy. It knows the typical percentage of the weekly budget that is used for every day of the week and can distribute the remaining budget accordingly.

To make this work, I did two things:

  1. I added a function that calculates the historical day-of-week distributions.
  2. I added a new budget distribution function that Google’s script can use.

Calculating the portion of budget spent on different days

For the first part I wrote a function called calculateDowFluctuations() that uses the reporting capabilities in AdWords Scripts to pull data for several weeks and builds a campaign cost map segmented by day of the week.

That way the code can easily look up how much each campaign spends for any day of the week. I also store the weekly total for each campaign so that I can easily determine what percentage of the week’s cost that represents.

The script produces something like this in the script logs:

CAMPAIGN: Test Campaign --------------------------------------- -

- Monday cost is:.. (% of the weekly total)

- Tuesday cost is:.. (% of the weekly total)

- Wednesday cost is:.. (% of the weekly total)

- Thursday cost is:.. (% of the weekly total)

- Friday cost is:.. (% of the weekly total)

- Saturday cost is:.. (% of the weekly total)

- Sunday cost is:..(% of the weekly total)

TOTAL COST:..

This particular campaign spreads its budget pretty evenly over a typical week, but Saturday and Sunday are slightly lower, at percent, than the percent on the other days.

Writing a new budget distribution function for Google’s script

The second big change I made was to add a function calculateDowWeightedBudget which uses the data I calculated previously to set the new budget based on which days remain in the month.

Google wrote their code nicely generically so that adding a new function to calculate budgets a different way is very easy. In fact, it was so easy I also wrote a function that front-loads the budget. It’s basically the opposite of the back-loaded function they already included in their example..

Final tweaks to the script

I also made some tweaks to Google’s code to allow unused budgets to be rolled over. One trick I used here was to say that we should only roll over budgets if the campaign appeared to have been active the entire previous month, and the way I check this is to see if there were any impressions in the first few days of that month.

If there weren’t any impressions, then the campaign may be new, and rolling over the budget wouldn’t necessarily make sense. Users can specify how many days at the start of the last month should be considered to see if the campaign was active. Note to Google: If we had programmatic access to change history, we could do this check a little bit cleaner and more reliably.

Finally, I added some code that sets the budget periods to monthly by default, so that there’s no need to revisit settings every time a new month starts. The script just continues to run with the same monthly budget for every new period until a change is made.

More Questions Like This