Keep Your AdWords Scripts Maintainable With These 3 Tips

If you’ve been using AdWords scripts for any substantial period of time, your account may feel like this messy bookshelf. There are unfinished scripts everywhere. Some scripts were added by the guy who left the company a few months ago, others by your intern who was curious and started tinkering around before she left for the summer. […]

Chat with SearchBot


If you’ve been using AdWords scripts for any substantial period of time, your account may feel like this messy bookshelf.

There are unfinished scripts everywhere. Some scripts were added by the guy who left the company a few months ago, others by your intern who was curious and started tinkering around before she left for the summer.

There are more unnamed scripts than named ones. You may start to think it’s an allegory for your life. Maybe you should bring that up with your therapist next time.

That’s always the problem with any system that grows up organically over time. If you’re not careful, you will end up with something that is impossible to maintain. Tomorrow, you come into work and a script breaks in one of your 300+ accounts. You have no idea how to find it. Logging in and out of accounts can eat up hours of your time in a week.

But you can stop (or at least slow) the process with a little bit of vigilance and planning. Today, I’ll walk through three techniques you can use to help lower the long-term maintenance of scripts in your accounts.

1. Gather Your Existing Scripts Into Your Highest MCC

The first thing to do is to take an inventory of all the scripts you currently have running in your accounts. Some will be extremely customized to a specific account and some will be generic. That’s okay; collect all of them anyway.

If you were developing scripts before the advent of MCC scripts, you probably have the same script copied into multiple accounts. Of course, that means you also have the same bug copied into multiple accounts as well. Bringing scripts like this into the MCC level means that there is a single piece of code to look at when debugging an issue.

This also promotes the discipline of writing generic, reusable code that can be applied to many accounts. It may take a little longer to think through and write the script, but in the long run, it will be worth it when you start amassing hundreds of accounts.

If it turns out you have many more specialized scripts that seemingly can only be run in specific accounts, you may want to look closely and understand if any of them can be made more generic by using configuration parameters or making small changes to the code.

Here is some generic code you can use at the MCC level to start running your scripts across multiple accounts using labels.

var SCRIPT_LABEL = 'GenericScript';
var MAX_ACCOUNTS = 50;
var RUN_HOURLY = false;

function main() {
  var accountsToRunOn = [];
  var hour = Utilities.formatDate(new Date(), 
                                  AdWordsApp.currentAccount().getTimeZone(), "H");
  var labelName = (RUN_HOURLY) ? [SCRIPT_LABEL,hour].join('-') : SCRIPT_LABEL;
  try {
    var accountIterator = MccApp.accounts()
        .withCondition("LabelNames CONTAINS '"+labelName+"'")
    while (accountIterator.hasNext()) {
      var account =;
  } catch (e) {
    if(e.message && e.message.indexOf("does not exist")>=0) {
      //ignore the error if the label does not exist
    } else {
      throw e;
  if(accountsToRunOn.length > 0) {
    if(accountsToRunOn.length > MAX_ACCOUNTS) {
      throw "There are "+accountsToRunOn.length+" accounts in this batch."

function GenericScriptFunction() {
  return true; 


This code will run through all your accounts and search for the ones labeled with the name used in the SCRIPT_LABEL variable. When you schedule this script to run daily, it will process all accounts with that label up to MAX_ACCOUNTS, which is the maximum number of accounts you can run the executeInParallel() function on.

You can schedule this code to run once per day if you have less than MAX_ACCOUNTS accounts that you want to run a single script on. For really large accounts, you can schedule the script to run hourly and set the value of RUN_HOURLY to true.

Now the script will look for the label named SCRIPT_LABEL-HOUR, so when this script runs at 6pm, it will look for all the accounts with the label “GenericScript-18”. Group your accounts into batches of MAX_ACCOUNTS so that the first set has the label “GenericScript-1”, then next one “GenericScript-2”, and so on.  Using this method, you could run any script on up to 1200 accounts in your MCC.

You should replace the GenericScriptFunction() with your specific generic script code that you collected earlier.  Be sure to rename the main() function into something unique, since there can be only one main function per script. Then add that name function to the executeInParallel call as well.

You should repeat this process for each generic script you need to run across multiple accounts. When you are finished, you will have a bunch of scripts in your MCC that are scheduled to run either once per day or hourly.

The next step would be to apply the label names to the accounts you want the script to run on.

2. Create A Test MCC Away From Your Main MCC

After speaking at SMX East a few weeks ago, I was asked how I test my scripts. I think the best way to keep your production accounts safe from script bugs is to open a brand new MCC account and create test accounts underneath it.

Create a test MCC account and fill it with test accounts.

Since most of my stuff is pretty experimental, most of my accounts are test accounts. This set of test accounts and the MCC is where you will do all of your experimenting and testing for new scripts.

You will need to fill these accounts with Keywords, Ads, and default bids (using scripts probably), but they can be anything since these accounts will never be live. In fact, you probably don’t even want to add any billing information just to ensure these never see the light of day.

Now all your Unnamed and half finished weather scripts have a place to live that won’t clutter up your main MCC. If your intern wants to experiment, they can play around as much as they want in here.  Also, if you are working with an agency to build out new scripts, you can give them access to this account without losing any sleep.

3. Create A Code Review Process

In software development, code reviews are an essential part of pushing code into production. The idea is similar to having someone else proofread your writing. Since they are unfamiliar with the writing and topic, they will be objective and find issues or code bugs that you may have missed.

I recommend that before you move any code from your test accounts into your main MCC, you find someone in your company to sit with and walk through how your code works and what the code looks like. Preferably, this would be an engineer with knowledge of JavaScript, but finding someone who is familiar with AdWords and understands the concepts is a good start.

Sit them down, walk them through your logic and thought process for the script, and run the script with them on your test accounts. You may even find a few bugs yourself just by walking someone else through your code.


Scripts have come a long way in the past few years. They have matured into something that I believe most people should be using in their accounts.

Taking a step back from the day-to-day and looking at the overall processes and strategy of creating and deploying these scripts can be a valuable way to keep your account from turing into a maintenance nightmare.

Remember that you may not always be around to look over things. Organizing and documenting a process for your scripting madness gives the next account manager one less thing to talk to their therapist about.

Contributing authors are invited to create content for Search Engine Land and are chosen for their expertise and contribution to the search community. Our contributors work under the oversight of the editorial staff and contributions are checked for quality and relevance to our readers. The opinions they express are their own.

About the author

Russell Savage
Russell Savage is an Application Engineer for Cask Data and loves tinkering with marketing data and automation in his spare time. He is the creator of, where he posts AdWords Scripts for anyone to use.

Get the must-read newsletter for search marketers.