A Simple & Customizable Google Ads Script To Prevent Your Account from Overspending

cropped-adbudgeting-blog.jpg

Google Ads does not make budget management an easy task. As we all know (and roll our eyes at), Google allows campaigns to spend up to 2X their daily “budget”. This creates a need for advertisers to frequently check on daily campaign spend, particularly when they have a very limited budget, launch a new campaign, or make significant changes.

The Problem

While searching for a solution for overspending, we came across this Google Ads scripts forum where an account budget-management script was posted by an unknown user. This script turns all campaigns off if the account spends more than the specified maximum budget in the last 30 days. One issue with this was that we wanted to monitor spend daily (a lot can happen in a day!), which was an easy adjustment to make to the script. However, the script came with a couple of other challenges that were not so simple to fix. First, after implementing the script as we found it online, we noticed that it does not shut down video campaigns. Second, it does not leave any room for flexibility when it comes to campaign structure. If the account overspends, all campaigns will shut down and we have some campaigns that are so important that we simply cannot afford to turn them off.

The Solution

We turned to our development team to adjust the script we found online, allowing us to include video campaigns and exclude select campaigns to ensure their ads run all day, every day. After making these changes, we use this script as the center of a standard, automated budget management system that ensures our Google Ads’ account spend remains under control.

This strategy does have its limitations (which we will dig into later), but since setting this practice into place, we sleep much better at night knowing that if our account has overspent the daily maximum budget that we’ve specified, our campaigns will automatically pause shortly after. This is a 3 part strategy that utilizes a Google Ad’s label, script, and automated rule to keep spend in check while allowing select campaigns to remain unaffected. 

How it works:

The free daily script we’re providing in this post will check your total account spend every hour. If the account has spent more than the maximum amount you’ve set, the script will pause all active campaigns (unless you specify that certain campaigns remain active, we’ll get to that soon).

Oh great, now you’ll have to check all of your accounts every day to see which campaigns were paused the day before and re-enable them, right? 

Wrong! Using an automated rule, we can have Google Ads do that work for us. 

The automated rule will run at midnight every day to check and see if any of the campaigns labeled “active” are paused. If they are, it will re-enable these campaigns for you. 

Keep reading for a step-by-step, fool-proof guide to setting up this strategy. 

Step 1: Leveraging Labels

The most important thing to note when using this Google Ads budget-management strategy is that it is entirely dependent on consistent and up-to-date campaign labels. 

Utilizing the script as-is, you’ll have to create one, or perhaps two, new labels in your account. 

Mandatory:  “active” label for all enabled campaigns. This is vital for the automated rule to work properly. 

Optional: “nopause” label for any active campaigns that you do not want the script to make changes to. 

  • For example, maybe you always want your ads to show up for branded searches. In this case, you would label every campaign with branded keywords “nopause”.

As you’re creating new campaigns or pausing seasonal or under-performing campaigns, it’s absolutely vital that you keep labels accurate and up-to-date. If you pause a campaign manually and forget to remove the “active” label, the automated rule will re-enable that campaign when it runs. 

Step 2: Setting Up the Script

The rest of this process will all take place in the "Bulk Rules" section of Google Ads, where you can set up and manage Google Ads' scripts, automated rules, and uploads.

To enable this script in your account, follow these steps:

1.Under the “Tools & Settings” menu in Google Ads, select “Scripts” under the “Bulk Actions” category. 

2. Click the blue plus sign on the top left side of your screen to add a new script. 

3. Enter a name for your script in the top left corner of the window. We named ours “Pause Campaigns When Max Daily Spend is Reached”.

4. Copy and paste this free script into the editor area:

var MAX_TOTALS = 350;
var TODAYS_SPEND = 0;
function main() {
    processTodaysSpend();
    processCampaignPause();
}
function processTodaysSpend() {
    //Get Ad Spend
    TODAYS_SPEND += getTodaysCosts(AdsApp.campaigns().get());
    //Get Video Spend
    TODAYS_SPEND += getTodaysCosts(AdsApp.videoCampaigns().get());
}
function processCampaignPause() {
    if (TODAYS_SPEND > MAX_TOTALS) {
  
        var adsSelector = AdsApp.campaigns()
        .withCondition("LabelNames CONTAINS_NONE ['nopause']")
        .get();
      
        var videoSelector = AdsApp.videoCampaigns()
        .withCondition("LabelNames CONTAINS_NONE ['nopause']")
        .get();
  
        //Pause Ads
        pauseCampaigns(adsSelector);
        //Pause Videos
        pauseCampaigns(videoSelector);
    }
}
function getTodaysCosts(selector) {
    var totals = 0;
    while(selector.hasNext()) {
        var campaign = selector.next();
        var stats = campaign.getStatsFor("TODAY");
        totals += stats.getCost();
    }
      return totals;
}
function pauseCampaigns(selector) {
    while(selector.hasNext()) {
        var campaign = selector.next();
        campaign.pause();
    } 
}

5. Set your account-wide daily maximum budget

  • You will set this in the first line of javascript. Our script has a pre-filled $500 limit.

6. On the bottom right-hand corner of your screen, hit “Save”, and then “Run”. You’ll see a pop-up asking you whether or not you want to preview the script before running. Select “Run Without Preview”.

7. You’ll then see a yellow banner at the bottom of the Google Ad’s window asking you to authorize the script to run, select “Authorize” and follow the steps for authorization.     

8. Select “Scripts” on the left side of your screen to return to the general scripts page. 

9. From this page, you'll see all of the scripts in the account and can specify how often your scripts will run. Under the “frequency” column for the script you just created, select “hourly”.*

*This script only runs every hour, so it’s still possible to slightly overspend the maximum spend that you set. If your daily spend limit of $500 is hit at 3:15 but the script does not run until 4:00, your ads will continue to run for that 45 minutes.

 Step 3: Regarding the Rule

Now it’s time to set up an automated rule to re-enable all active campaigns the following day.

1.From the bulk actions page, select “Rules”.

2. Press the blue plus sign on the top left side of your screen to add a new rule, then select “campaign” rules.

3. Choose “Enable Campaigns” as your type of rule.

4. Apply to all "enabled or paused campaigns".

5. Add the condition “Label contains all ‘active’”

6. Set the frequency as daily at 12:00 A.M. using data from the same day. 

7. Now, choose whether or not you want an email notification when the rule runs (we recommend you do! If this rule makes changes to your account, then your account overspent the previous day. This probably warrants some investigation to see if something is wrong). 

8. Finally, name your rule. We went with “Daily Re-Enable”.

And there you have it! A fool-proof daily budget management strategy to keep Google Ads from overspending. If you are more advanced in Google Ads or have access to a development team, there is endless opportunity to manipulate this script so it makes sense for your account. We have found that this script is necessary for all of our accounts. For clients with a limited budget, it allows us to pace it evenly throughout the month and not run out of money towards the end. For clients with larger budgets, it's a safety net in case a campaign budget is entered incorrectly or there is an error in campaign targeting. At the very least, if you’re utilizing this strategy, you’ll be able to relax knowing that whether it’s due to limited budget, human error, changes to Google Ads’ policy, or an act of God, your campaigns will automatically pause within an hour of reaching the daily limit you set in this script. 

Let us know in the comments if you make any edits to the script to make it work for your Google Ad's campaigns. Want more practical strategies to optimize your PPC campaigns? Listen to our podcast to hear about what works, what doesn't, and what has us shaking our heads this week. 

Categories: Paid Search Marketing

7 Comments

  1. Author's Headshot
    Andre Lereu January 16, 2020
    Reply

    THANK YOU!!! This is awesome.

  2. Author's Headshot
    Luan Nguyen January 23, 2020
    Reply

    Christine.. you Da MVP!

  3. Author's Headshot
    Onur March 3, 2020
    Reply

    Great script, thank you!

    I was wondering if we could use another label instead of "active" for the script to run. How can we change this in the script?

    Best

    • Author's Headshot
      Christine Zirnheld April 14, 2020

      Thanks for reading! You would not have to adjust the script if you labeled the campaigns in a different way. For this strategy, the "Active" label is only used to re-enable campaigns the next day using the automated rule. So, when you make the rule, you'd have to make sure it reenabled the campaigns based on whatever label you choose. This strategy is fully customizable to make it work for your account. Let us know if you need any more help!

  4. Author's Headshot
    Chris May 12, 2020
    Reply

    Thanks for this! I'm setting it up on all my clients' accounts.

    Script n00b question:
    The editor is pre populated with :
    function main() {

    }

    Should the script go within this or replace this?
    Thanks!

    • Author's Headshot
      Matt Mombrea May 12, 2020

      The script can replace what is pre-populated. There is a new main() function in our script to replace it.

  5. Author's Headshot
    Pavel October 4, 2021
    Reply

    Christine, thanks a lot for this script!
    I am not a JS developer, but idea is: maybe it would be more unversal to get daily budget from campaign settings?

Leave a Reply

Your email address will not be published. Required fields are marked *

Meet the Author

ChristineHeadshot
Senior Digital Marketing Manager

Christine Zirnheld

Christine is a Senior Digital Marketing Manager who joined Cypress North in July 2018 and works in our Buffalo office. Known affectionately among coworkers (and podcast listeners) as Shep, Christine brings seven years of experience to our digital marketing team. She spends most of her time trying to help her clients uncover new leads through the art of paid search and is also a co-host of our weekly Marketing O’Clock podcast

Originally from Ashburn, Virginia, Christine graduated from Canisius University with a bachelor's degree in marketing. She also has an associate's degree in fashion business management from the Fashion Institute of Technology. 

Christine is known for her PPC expertise and was recognized by PPC Hero in 2021 as one of their Rising Stars in PPC. In addition to being published in Search Engine Journal and Search Engine Land, she authored an ultimate playbook for Google Ads. Christine was also featured as a speaker at SMX Next - a search marketing training program - in 2022. 

When she’s not working, Christine can be found singing karaoke or watching Miss Rachel with her toddler, watching Bravo, dining al fresco, and drinking Diet Coke. She’s known for making her Taylor Swift fandom her personality, talking about the royal family to any of her coworkers who will listen, and reading books about wives who kill their husbands. Christine was the 2002 Hula Hoop Champion at Ashburn Elementary School – and may still be undefeated.