Created
September 19, 2016 09:30
-
-
Save adhummer/80afdcb0145c051bb11e3c5fdf824f11 to your computer and use it in GitHub Desktop.
Hard Cap, pause 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() { | |
// 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