Everyone knows that since October 2017, campaigns in Google Ads can spend twice as much money as set in their daily budget. There are different kinds of scripts for Adwords, but we have written our own.
There are different types of scripts for Adwords that allow you to check the cost of campaigns and stop them when they go beyond the specified budget. However, we ran into problems with all the scripts we found:
- When the campaign type is Search with Display Select, the getCost function does not take into account the cost of the campaign in the Display Network.
- The situation is similar with Youtube campaigns, where you need to call a separate API function to get the expense.
Therefore, we wrote a script for ourselves that uses the report function and receives the total expense for the account, and takes into account all types of campaigns and placements. It’s great when you need:
- Keep track of your account’s daily spending and be sure that you don’t spend 2 times more than your planned budgets.
- Keep track of weekly or monthly expenses, this is especially true when your monthly expenses are confirmed by acts, with amounts previously agreed upon in them.
Checks account spend for the time period you specified in the script settings, day, week, month, etc.
If the expense is greater than the value you set in the script settings, it stops active campaigns.
Further, the script will continue to check, and when it sees that a new day, week, month has come and, accordingly, we have a new budget, it will turn back on the companies that received impressions before the pause.
Basically, you can set up points 2 and 3 as you need, for example, add a condition so as not to stop the Brand campaign, or include back not all campaigns, but with certain names. The main point of this script is in 1 paragraph and the report function that accurately shows the entire expense of the account and any type of campaigns in it.
google ads
google scripts
account
budget
function main() {
var budget = 10000;//set target budget value
var report = AdWordsApp.report(‘SELECT Cost ‘ + ‘FROM ACCOUNT_PERFORMANCE_REPORT ‘ +
‘DURING THIS_MONTH’);//choose: TODAY YESTERDAY LAST_7_DAYS LAST_WEEK LAST_30_DAYS THIS_MONTH LAST_MONTH ALL_TIME
var rows = report.rows();//log actual account costs
while (rows.hasNext()) {
var row = rows.next();
var cost = row[‘Cost’];
Logger.log(cost);
}
var EnabledCampaignsList = [];//get currently enabled campaigns list
var campaignIterator1 = AdWordsApp.campaigns().withCondition(“Status = ENABLED”).get();
while (campaignIterator1.hasNext()) {
var campaign = campaignIterator1.next();
EnabledCampaignsList.push(campaign);
}
if (cost > budget){//pause enabled campaigns if actual account costs > target budget value
for (var i = 0; i < EnabledCampaignsList.length; i++) {
var campaign = EnabledCampaignsList[i];
Logger.log(campaign.getName())
campaign.pause();
}
}
var WasEnabledCampaignsList = [];//get campaigns with impressions before list
var campaignIterator2 = AdWordsApp.campaigns().withCondition(“Impressions > 0”)
.forDateRange(“LAST_7_DAYS”).get();//choose date range YESTERDAY LAST_7_DAYS LAST_30_DAYS for impressions > 0 rule
while (campaignIterator2.hasNext()) {
var campaign = campaignIterator2.next();
WasEnabledCampaignsList.push(campaign);
}
if (cost < budget){//enable campaigns with impressions before if actual account costs > target budget value
for (var i = 0; i < WasEnabledCampaignsList.length; i++) {
var campaign = WasEnabledCampaignsList[i];
Logger.log(campaign.getName())
campaign.enable();
}
}
}
Send your details and we will find a solution for You
Leave a request and discuss with a marketer
tasks and detailed price calculation
Schedule a free call with our CEO
We will contact you shortly.