Created
October 12, 2017 11:32
Star
You must be signed in to star a gist
Script to control budgets for single campaign or group of campaigns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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