أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.
Once again, you are showing your creativity with very good answers Mr.Babu.
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:
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.
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.
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:
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.
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 scriptI 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.