Customize Your Google Adwords Anomaly Script

Customize Your Google Adwords Anomaly Script

Susan had her web developer set up Google AdWords Anomaly Alerts so she would know when her AdWords account was underperforming. Shortly after going live with the new code, Susan received an alert. She opened the email and learned that she had an anomaly; but to her frustration, that was all the alert told her. It did not tell her what part of her account had generated the alert, nor did it tell her what outside influences might be causing the decreased performance.
If you follow this website, you have no doubt run across some exciting alternative code written by Optmyzr which greatly expands standard Google AdWords scripts. Recently, Optmyzr introduced the following enhanced version of the Google AdWords Anomaly Alerts code.


An anomaly is a condition where today’s stats are significantly different when compared to averages for the same day last week, last month, last year, or whatever period you are comparing them to. The anomaly detector summarizes the information on one page in an easy-to-compare table format.

The anomaly alerts can be set to run hourly, daily, or on any schedule you choose. Google suggests you set the script to run every hour so you will be notified within an hour of any performance issue.


Website owners choose a day and time for the script to run (i.e. 7 pm on Tuesday). Note that because AdWords statistics may be delayed for up to three hours, the script will stop analyzing stats three hours before your designated time.
The script retrieves statistics for the previous 26 Tuesdays, calculates the average of those dates, and compares that to today’s data.


  • It locates and identifies what part of the account is underperforming.
  • It searches for and reports any extreme deviations causing a change in performance.
  • It analyzes data at every level and reports all areas that are performing poorly.
  • It evaluates not only at the campaign and ad group levels, but also at the keyword level.
  • It adds an email alert if any of these changes go beyond a level chosen by the user.
  • It offers users options to compare today’s data to a variety of date options.


Add Flexible Date Range Comparisons

To add flexible date range comparisons to your Google AdWords Anomaly Alerts, add the following code to your account:

  • How many days ago the current lookback window starts: currentPeriodStartsNDaysAgo = 6;
  • How many days ago the current lookback window ends: currentPeriodEndsNDaysAgo = 1;
  • How many days ago the date range to compare to starts: previousPeriodStartsNDaysAgo = 13;
  • How many days ago the date range to compare to ends: previousPeriodEndsNDaysAgo = 8;

The above code compares the data for the previous five days with the same weekdays from last week: and the data from six days ago through yesterday with 13 days ago through one week ago yesterday. You can compare a different number of days by adjusting the numbers in each step.

Sort Alerts by Degree of Importance

One issue with standard Google AdWords Alerts is all issues are considered the same degree of importance. For example, a stubbed toe, a pulled muscle, a broken bone, and a heart attack would all receive the same alert status. Alerts for red-level emergencies were being ignored as users assumed it was just another low-level alarm.
The following code creates four different alert levels:

Notify of a certain percentage change in absolute numbers

Google’s Anomaly Detector threshold is based only on the percentage change. If you request alerts for deviations equaling more than 10 percent, an alert would be returned if performance changed from ten clicks to eight clicks (a 20-percent decline). Is that really the feedback you want? To avoid these false alerts, add an absolute value to the alert threshold.
Following is the script to notify you when the absolute value of the numbers is large enough:
minAlertImpressions = 20
This code requires at least twenty impressions in either of the date ranges being compared. If a keyword changed from fifteen impressions to two impressions, no alert would be triggered; but a keyword changing from fifteen to twenty may.

Alerts for performance increases, decreases, or both

Some people may only want an alert when performance decreases, Others may want to be alerted for anysignificant change. The following script allows users to set independent thresholds for increases and decreases in performance.
The following example asks for an alert when impressions increase by 10 percent or decrease by 20 percent:

  • minDecreaseForImpressionAlert = -0.2;
  • minIncreaseForImpressionAlert = 0.1;

If you set either value to “0” you will receive NO alerts. To receive alerts for small changes, add small fractions like “0.0001” (0.01%).

Alerts for specfic metrics

Users may choose to receive alerts only when a particular metric is achieved. This script allows users to specify when they do NOT want a metric to trigger an alert.
Continuing with the example from above, set either value to “0” to get NO alerts. If you want to receive alerts for very small changes, you can put in something like “0.0001,” which is 0.01%. So with this setting you’d get no alerts for any changes in impressions:

  • minDecreaseForImpressionAlert = 0;
  • minIncreaseForImpressionAlert = 0;

Alerts for different account elements

This last alert setting will notify users of campaign, ad group, ad or keyword changes.
Set the value for each element to “1” to include it or “0” to exclude it:

  • includeAccountLevel = 0;
  • includeCampaignLevel = 0;
  • includeAdGroupLevel = 1;
  • includeKeywordLevel = 0;
  • includeAdLevel = 0;


The following script can be copied and pasted into any Google AdWords Anomaly Alerts account. It should be scheduled to run once per day, after 3:00 a.m., because of the three-hour delay in processing in AdWords.
Always enter your email address and Google account number when you make changes to your account to ensure that you will have access to the spreadsheet generated by the script and that you will receive email alerts when your account encounters anomalies.


Once your Google AdWords Account Anomaly Detector is optimized, you will be able to spend your time on things that improve account performance. Properly optimized accounts produce far fewer performance alerts.