Find anomalies in your campaign spending with this Google Ads script




  • Contributor Daniel Gilbert shares a customizable script that lets you check for overspending or underspending in your Google Ads account by finding changes in spending.

    Find anomalies in your campaign spending with this Google Ads script

     

    Have you ever had a campaign spend a touch more than expected and taken a too long to spot it? No one likes to catch their campaigns underspending, let alone overspending, but even pay-per-click (PPC) superheroes aren’t entirely infallible. If a change or issue pops up, it’s best to be warned about it sooner rather than later!

    Here’s a customizable script that will let you check for unusual behavior in your account by finding changes in spending. It takes the average spend of individual campaigns during a selected time period and compares it to the spend on the day the script runs. If the spend on the current day is higher than it was by a specified percentage, it will send out an alert email.

    There are many ways to modify this script to satisfy your needs. For example, you can tell the script what percentage change threshold should be met so an email alert is sent. This way, you will know when there is an increase or decrease in spending.  You can choose the number of days the script covers to create an average of historic spend (the default time period is a week). You can pick the time of day when the script starts gathering data to alert you, and you can set a minimum value to avoid being warned about small changes in campaigns that are historically low-spending.

    How the script works

    Let’s get started and see how this works.

    Let’s get started and see how this works.

    • Fill in the variables at the top of the script (below) according to your preferences and details. You will add the email addresses you want alerts to be sent to and the campaigns the script looks at.
    • Once you’ve authorized the script and confirmed it’s working with a test run, schedule it to run hourly so you can check spend each hour.

    Here are some pointers to remember about the script:

    • The script records the time of day it’s running and obtains an average of how much has been spent from the current hour over the chosen time period.
    • The script compares this average to the current spend.
    • If the current spend exceeds the specified threshold, it will notify you with an email.

    Find anomalies in your campaign spending with this Google Ads script

    Script outline

    To use this script, go to your account in the Google Ads interface, go to Bulk Actions, choose Scripts, then make a new one and paste in the script below. Don’t forget to edit these options:

    • campaignNameContains and campaignNameDoesNotContain filter which campaigns the script gets data from. For example, if campaignNameContains is [“Brand”, “Generic”] then only campaigns with names containing “brand” or “generic” are included. If campaignNameDoesNotContain is [“Display”, “Competitor”], then any campaigns with names containing “display” or “competitor” are ignored.
      • This is not case-sensitive.
      • Leave [  ] blank to include all campaigns.
      • If you need to put a double quote into campaignNameContains or campaignNameDoesNotContain, put a backslash before it.
    • addressesToNotify is an array of email addresses to notify if spending has exceeded the percentage difference threshold. These should be in a comma-separated list inside square brackets. For example, [“dan@example.com”].
    • percentageDifferenceSpend is the percentage change threshold that today’s spend must exceed for an alert to be sent. For example, 10 means you’ll be told when there’s a change greater than 10 percent (whether that’s a 10 percent increase or a 10 percent decrease).
      • This number must be positive and above zero.
    • If a campaign only spends a little, then natural variations of a few dollars in spend will be a big percentage change. To avoid being warned about small changes in historically low-spending campaigns, you can set the averageSpendMinimumThreshold. If the average historic spend of a campaign is under this threshold, then changes in its spending will be ignored.
      • This is an absolute amount, in your account’s currency. For example, if your account uses dollars, then 100 means $100.
      • It must be positive and greater than zero.
      • Note: This also means you won’t get alerted when a previously paused or non-spending campaign has just been enabled, regardless of how much it spends today — its historic spend will be zero, and therefore under the threshold.
    • As spend is likely to be low in the morning, this can also mean small changes in spend can be large percentage changes.  You are more likely to be asleep and not paying attention to your emails. You can set earliestHour to the first hour of the day you want the script to run on, and it won’t run earlier than what you set it for. Waiting until later on in the day gives the account time to accumulate meaningful data.
      • This is the hour in your account’s time zone.

    There is also one advanced setting:

    • timePeriod is the number of days used to get the average historical spend data. The default is 7, which means the script looks back over a whole week, but you can change it to a custom number of days.
      • This value must be more than 1.

    Notes:

    The script only looks at currently enabled campaigns, so you won’t get alerted when a campaign suddenly stops spending because it’s been paused.

    If you’re having trouble with the script timing out, you could try having multiple copies of the script which each look at different campaigns, using the campaignNameContains and campaignNameDoesNotContain settings.

    Get Script from github

    [Article on Search Engine Land.]


    Opinions expressed in this article are those of the guest author and not necessarily Marketing Land. Staff authors are listed here.


    About The Author

    Daniel Gilbert is founder and CEO of Brainlabs,the smartest performance marketing agency on the planet. As the self-proclaimed superhero of PPC, Daniel’s mission is to change the future of advertising, while creating the best place in the world to work.

    Marketing Land – Internet Marketing News, Strategies & Tips

    (5)