Campaign Spending Alert Script
Have you ever had a campaign spend a touch more than expected and taken a too long to spot it? Here’s a customizable script that will warn you about unusual spending behavior in your account.
How does the script work?
This is a customizable script that checks 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, and sends an alert email if spend on the current day is higher or lower than your chosen percentage change threshold.
You can choose the number of days the script covers to create an average of historic spend (the default time period is a week), and you can pick the time of day when the script starts gathering data to alert you. You can also set a minimum value to avoid being warned about small changes in campaigns that are historically low-spending.
How do I use it?
In 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 fill in the variables at the top according to your preferences and details.
You need to add the email addresses you want alerts to be sent to and the campaigns the script looks at, and schedule your script.
- 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, [“email@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.
- 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.
The Campaign Spending Alert Script code