1. SEJ
  2.  ⋅ 
  3. PPC

AdWords Scripts For MCC: How to Detect Account Anomalies Automatically

Example AdWords Scripts to detect anomalies in the performance of accounts. Script results for all AdWords accounts are aggregated in a dashboard.

If you’re anything like me, one of your least favorite parts of working on AdWords is taking care of all the tedious and repetitive tasks that are part of good account management. While necessary for great results, they’re also are boring tasks we often wish we could hand off to someone else, maybe even leave it for the computer to handle.

That’s where AdWords automations come in handy. There are automated rules and the more advanced AdWords Scripts that can help offload repetitive tasks in AdWords.

Automated Rules – Simple Daily Automations

Automated rules let you set simple daily automations, using a rule based system. You tell AdWords, “If this happens, then do that.”

Here are a few examples of what Automated Rules can do:

  • If the quality score of a keyword is lower than 3, pause it.
  • If the average position of a keyword yesterday was less than 2.5, increase the bid by 10%.
  • If today is Saturday, enable my ads with the label ‘weekend ads’.

While these automations are very useful, they are limited to the rules AdWords provides and they can only be run up to once per day. So if you want to check that an account’s performance is not deviating from expectations, you may need something more powerful that can check stats several times per day. This is where Scripts excel…

AdWords Scripts – Fully Customized Hourly Automations

AdWords Scripts are built on the same technology as Automated Rules, but they let you write the JavaScript code yourself. These scripts can then be run automatically as often as once per hour and can automate things like custom reporting, adding keywords, pausing ads, setting campaign budgets, and creating ad groups from a datafeed. I have been writing scripts since they were introduced in 2012 and will share some tricks for making them easier to use if you’re managing multiple AdWords accounts.

AdWords Script CodeAdWords Script code.
Screenshot taken July 2014

AdWords Scripts in MCC Accounts

Recently, Google made AdWords Scripts available for use in MCC accounts. So now if you manage a lot of accounts, you no longer need to add the script to each one but rather you add it to the MCC account where it can operate on all linked accounts. This is a big improvement from when scripts only worked in non-MCC accounts as it’s no longer necessary to copy-and-paste the same code into multiple accounts and keep track of which accounts you’ve already added the script to.

MCC AdWords Script: Anomaly Detection

One limitation that still exists, however, is that it’s hard to make the script do slightly different things for each account you’re managing. For example, say you want to use Google’s own Anomaly Detection script. This script sends an email if the clicks, impression or cost at any point during the day deviates from the expected level, based on a running average of several weeks of data. You may want to trigger an alert for one account if there’s a 20% deviation and for another at 30%. You may also want to notify different people via email for each account.

With scripts the way they are today, that means maintaining the settings inside the code (which makes version management a nightmare). For the Anomaly script, Google did a smart thing and put the settings for each account in a Google Sheet so that it’s easier to make changes, but you have to access several sheets to see how things are going, and that still takes too much time.

AdWords Anomaly Detector Script For MCCScreenshot of Google Sheet showing AdWords accounts that are performing better or worse than expected based on historical averages.
Screenshot taken July 2014

I was struggling with version management and spreadsheet overload, so I decided to improve the Anomaly Detection script by moving the code out of the script I copy into each account and keeping the settings for all accounts in one place. Then I also added color coded warnings in a Google Sheet so that I can see all my accounts in a dashboard rather than having to watch my email to get alerts.

I’ll walk you through how I did this so you can use the same techniques for your own AdWords Scripts.

Keep All Script Settings in One Google Sheet

Google was smart to write the script in a way where the settings are kept in a spreadsheet. Many marketers are simply not comfortable tweaking settings inside the code and by using a Google Sheet for the settings, they removed a big barrier to adoption.

What I don’t like is that each account gets its own sheet so I changed the script to pull settings for all accounts from a single Sheet. Now when I want to run the script in a new account just added to MCC, I simply add a new line to my existing Sheet. The following code reads the header of the Sheet and assigns the settings to a variable that the script uses:

// SETTINGS.taskSheet needs to open the Google Sheet first
var rows = SETTINGS.taskSheet.getDataRange();
 var numRows = rows.getNumRows();
 var numCols = rows.getNumColumns();
 var values = rows.getValues();
 // Read Header Rows
 var headerNames = new Array();
 var row = values[0];
 for(var i = 0; i < numCols; i++) {
 var value = "" + row[i];
 headerNames[i] = value;
 // Read Data Rows With Settings
 for(var i = 1; i
 var row = values[i];
 for(var j = 0; j < headerNames.length; j++) {
 var headerName = headerNames[j];
 var value = row[j];
 SETTINGS[headerName] = value;

Store The AdWords Script Code Remotely

Even now that we can add scripts in MCC accounts, I still find myself having to copy the same script into multiple accounts, because we have a few different MCCs and sometimes I do account audits where the customer prefers not to link with SalesX’s MCC. Because I don’t want to manually update the code in several accounts whenever I make a script enhancement, I use the following code that fetches the code from my own server (I learned how to do this from

var scriptFile = UrlFetchApp.fetch(fileToFetch);
var scriptText = scriptFile.getContentText();
SETTINGS.className = "remoteScript";
var script = eval('new '+SETTINGS.className+'();');
var done = script.main();

The remotely hosted AdWords script looks like this:

function remoteScript() {
 this.main = function() {
   // The code that does all the work goes here

Finally I made some other tweaks to the script from Google. Rather than making email the main way to find out about anomalies, I use green and red cells in the sheet to highlight which accounts are delivering more or less than expected. I also added the ability to trigger an alert using conversion data, but I’ve found that’s not all that useful since conversion data for many accounts comes from Google Analytics and with the two-day reporting delay it triggers too many alerts.

If you want the full script code for the MCC level Anomaly Detector, you can download it from our AdWords Script Library at where our engineers are working on something really cool that will make AdWords Scripts easier to use for everyone. We’ll make an official announcement about that before the end of this month.

I hope these tips on how to run AdWords Scripts in MCC accounts are useful and if nothing else, that you enjoy the Anomaly Detector script I’ve tweaked to make it more useful in my eyes.


Featured image made by author

Category PPC
VIP CONTRIBUTOR Frederick Vallaeys Optmyzr

Frederick Vallaeys is a Co-Founder of which offers a Historical Quality Score Tracker, One-Click AdWords Optimizations, a custom report ...

AdWords Scripts For MCC: How to Detect Account Anomalies Automatically

Subscribe To Our Newsletter.

Conquer your day with daily search marketing news.