Skip to content

Instantly share code, notes, and snippets.

Created October 12, 2017 11:32
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save anonymous/cf465ee9e388754788c8c16c2a5c7731 to your computer and use it in GitHub Desktop.
Script to control budgets for single campaign or group of campaigns
function main() {
//update the value of monthlyBudget based on your requirement
var monthlyBudget = 1000;
var totalCost = 0;
var campaignsList = [];
var campaignIterator = AdWordsApp.campaigns()
//apply a label to all the campaigns you want to be included in this budget control script and add it here. If you want the budget script to include all campaigns, delete line 9 of the script
.withCondition("LabelNames CONTAINS_ANY ['INSERT LABEL HERE']")
.get();
while (campaignIterator.hasNext()) {
var campaign = campaignIterator.next();
campaignsList.push(campaign);
//use 'THIS_MONTH' as the value in brackets on line 17 to get data for all days in the current month, replace THIS_MONTH with one of the values on line 16 between to change the date range
//TODAY | YESTERDAY | LAST_7_DAYS | THIS_WEEK_SUN_TODAY | THIS_WEEK_MON_TODAY | LAST_WEEK | LAST_14_DAYS | LAST_30_DAYS | LAST_BUSINESS_WEEK | LAST_WEEK_SUN_SAT
var stats = campaign.getStatsFor('THIS_MONTH');
var campaignCost = stats.getCost();
totalCost += campaignCost;
}
if (totalCost >= monthlyBudget){
for (var i = 0; i < campaignsList.length; i++) {
var campaign = campaignsList[i];
Logger.log(campaign.getName())
campaign.pause();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment