Skip to content

Instantly share code, notes, and snippets.

@adhummer
Created September 19, 2016 09:30
Show Gist options
  • Save adhummer/80afdcb0145c051bb11e3c5fdf824f11 to your computer and use it in GitHub Desktop.
Save adhummer/80afdcb0145c051bb11e3c5fdf824f11 to your computer and use it in GitHub Desktop.
Hard Cap, pause campaigns
function main() {
// GET THE TOTAL SPEND OF THE ACCOUNT
// https://developers.google.com/adwords/scripts/docs/reference/adwordsapp/adwordsapp_keywordselector
var costReport = AdWordsApp.report("Select Cost from ACCOUNT_PERFORMANCE_REPORT");
var reportRow = costReport.rows().next();
var totalCost = reportRow["Cost"].replace(',', ''); // Remove thousand separator
var costReport = AdWordsApp.report("Select Cost from ACCOUNT_PERFORMANCE_REPORT DURING THIS_MONTH");
// PAUSE THE ACTIVE CAMPAIGNS IF THE BUDGET IS REACHED. REPLACE "XXXX" WITH YOUR BUDGET.
if (totalCost > XXXX){
var campaignIterator = AdWordsApp.campaigns().withCondition("Status = ENABLED").get();
while (campaignIterator.hasNext()){
var campaign = campaignIterator.next();
campaign.pause();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment