A script to set recurring monthly budgets in AdWords

google-adwords-yellow1-1920

It’s been a while since I posted an AdWords script here, so this month I’ll share an AdWords automation that manages 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.

Why we need a script to manage monthly budgets

One of the quirks of AdWords is that budgets are daily, rather than monthly. I hadn’t yet joined Google when they decided to use daily budgets, so I don’t know exactly how that decision came to be, but I was there for plenty of product meetings that dealt with budgeting issues.

One of the most fruitless projects I recall was one where we tried to give advertisers monthly budgets while still using the underlying daily budgeting method the system was built for.

Close up of a calendar with some days crossed off.

AdWords uses daily budgets, but many advertisers prefer working with monthly budgets; so we needed an automation to help us manage recurring monthly budgets and make sure the entire budget was spent every month. Image licensed from Fotolia.

Despite months of meetings, the project eventually went nowhere because we could never agree on a reasonable way to translate daily budgets to monthly ones without confusing a large group of advertisers.

The problem was simple: When we asked an advertiser for a monthly budget, some of them would give us a number that was going to be the same every month (a true monthly budget), whereas others who were already used to working with daily budgets would tell us a monthly budget based on multiplying a daily budget by the number of days in the month.

The latter group’s budgets would change monthly depending on the number of days in the month. That may not seem particularly confusing to readers of this site, but believe me, when you have over a million advertisers, even small things can cause a huge amount of confusion. We ended up deciding to avoid confusion and left budgets as daily.

To have a monthly budget in AdWords, you could simply divide your month’s budget by the number of days for the month, but that risks underspending — so an automation that evaluates how much budget is left and how many days are left and then sets a new daily budget is the surest way to get close to spending the full budget every month.

Day-of-week fluctuations impact how well you spend a budget

The reality for many SEM managers, agencies and consultants is that their clients or managers set budgets that are annual, quarterly or monthly.

The math to turn these into daily budgets is easy, but setting the correct budget so that the full amount is spent is a bit harder because the different days of the week can have dramatically different potential.

Let’s take a simple example. Say you have $300 to spend during the 30 days of April, which translates to $10 per day. If you set a budget of $10 every day, you may only deliver $4 on a typical weekend day, when fewer people do searches, and then, during the weekdays, your $10 daily budget could deliver up to $12 worth of clicks (thanks to overdelivery) but that would still leave you short of the target, even if you spent $12 a day for all five weekdays.

Knowing that weekend days garner a fraction of the searches that occur on weekdays, you could increase budgets on weekdays to make up for the shortfall on weekends. Google already has a script that updates budgets daily to help meet an overall budget goal for the entire month, and this might work well because day-of-week fluctuations smooth out over the course of several weeks. But we can do better with a customization of their AdWords Script.

Google’s flexible budget script

Google’s script provides two ways of calculating what the new daily budget should be: evenly distributed or backloaded.

In the even distribution method, it simply figures out how much budget remains for the month and how many days remain, then divides the former by the latter. For example, with $100 of budget remaining and 10 days left in the month, the new budget would be set to $100/10 = $10. It assumes all days are the same, so it spreads the budget evenly.

Even budget distribution:

In an even budget distribution, all days get the same budget.

In an even budget distribution, all days get the same budget. Here, with $100 left to spend in 10 days, every day gets a $10 budget.

In the backloaded method, a larger portion of budget is kept for the end of the month. If you know you’ll be running a big promotion toward the end of the budget period, this can be a good method to preserve budget for a time when you expect your ads to perform better in terms of key metrics like CPA or ROAS.

Backloaded budget distribution:

Back loaded

In the backloaded weighted budget allocation method, most of the budget is preserved for later in the budget period. However, if the last day is a day of the week that normally doesn’t see a lot of traffic, a lot of budget could remain unutilized.

The Google script takes a start and end date as inputs and doesn’t automatically know how to deal with full calendar months. The script doesn’t solve my monthly budget problem out of the box, but it provides a great starting point for some customizations which I’ll describe next.

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 $100 will be spent in the 10 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: 83.31 (15% of the weekly total)
 - Tuesday cost is: 86.53 (15% of the weekly total)
 - Wednesday cost is: 82.59 (15% of the weekly total)
 - Thursday cost is: 84.31 (15% of the weekly total)
 - Friday cost is: 83.18 (15% of the weekly total)
 - Saturday cost is: 73.19 (13% of the weekly total)
 - Sunday cost is: 71.35 (13% of the weekly total)
 TOTAL COST: 564.46

This particular campaign spreads its budget pretty evenly over a typical week, but Saturday and Sunday are slightly lower, at 13 percent, than the 15 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.

You can enter your own settings for campaign name, budget and so on, on lines 44–48.

Conclusion

We took a piece of code from Google and used it as the basis for building an automation that reduces the manual workload of updating budgets daily to help us hit a monthly target, and we solved our need for a recurring monthly budget rather than a daily budget.

I hope you find this script useful for managing your own campaigns. As always, we’ve added this code to our patent-pending Enhanced Scripts on Optmyzr (my company) where we have a nice UI for managing it across many accounts and many campaigns.

The post A script to set recurring monthly budgets in AdWords appeared first on Search Engine Land.