Just a simple script that can be used to pause any Campaign or Campaigns that contain some string of text in their name when they surpass a budget cap.
Great for one-off campaigns for specific trips, shows, promotions, etc.
No Google Sheet needed here – just the script, and you can set this up in the account as many times as you'd like!
To get started, go to your Google Ads account, click Tools > Bulk Actions > Scripts
You'll be creating one new scripts. The instructions are below!
Create a new script and name it "<CAMPAIGN> | Budget Cap Script" (or whatever you want)
Copy and paste the script below.
Change the 1000 to whatever you want the lifetime spend of this campaign to be. If you don't want to have this check the lifetime spend, you can quickly change the ALL_TIME in the script below to one of the following values:
TODAY, YESTERDAY, LAST_7_DAYS, THIS_WEEK_SUN_TODAY, LAST_WEEK, LAST_14_DAYS, LAST_30_DAYS, LAST_BUSINESS_WEEK, LAST_WEEK_SUN_SAT, THIS_MONTH, LAST_MONTH, ALL_TIME
Change the ENTER_CAMPAIGN_NAME_HERE to some string of text that would apply to all the campaigns you want to pause when they hit the budget cap.
After changing the 1000 to your Campaign budget and setting the Campaign name, you're all set! Hit Save and Run. Authorize anything needed and Run again.
Set the Frequency of this script to "Hourly"
It might be a good idea to disable this script after the campaign is over, since if you set up a Campaign with a similar name at any point in the future, it may be paused by this script prematurely.
This script is not set up to email you when the campaigns are paused. So just be sure that it's working properly!
function main() {
//update the value of monthlyBudget based on your requirement
var monthlyBudget = 1000;
var totalCost = 0;
var campaignsList = [];
var campaignIterator = AdWordsApp.campaigns()
.withCondition("Name CONTAINS 'ENTER_CAMPAIGN_NAME_HERE'")
.get();
while (campaignIterator.hasNext()) {
var campaign = campaignIterator.next();
//save in campaignsList the list of campaigns object.
campaignsList.push(campaign);
//use THIS_MONTH to get data for all days in the current month
var stats = campaign.getStatsFor('ALL_TIME');
var campaignCost = stats.getCost();
totalCost += campaignCost;
}
//if totalCost of combined campaigns is equal to defined monthlyBudget, pause the campaigns
if (totalCost >= monthlyBudget){
for (var i = 0; i < campaignsList.length; i++) {
var campaign = campaignsList[i];
Logger.log(campaign.getName())
campaign.pause();
}
}
}