AdWords Scripts Grows Up With MCC Level Scripts

So far, many have dismissed AdWords scripts as a toy that you can only use for small AdWords account setups. There are some ways to build out larger script frameworks that span multiple accounts, but it is clunky and still requires you to install a snippet of code into each account. Worse yet, if you […]

Chat with SearchBot

So far, many have dismissed AdWords scripts as a toy that you can only use for small AdWords account setups. There are some ways to build out larger script frameworks that span multiple accounts, but it is clunky and still requires you to install a snippet of code into each account.google-adwords-featured1

Worse yet, if you find a bug in a script that you’ve copied to 10 or 25 accounts, you’ll need to log into each one and update them manually to apply the fix. This breaks one of the fundamental rules of software development: “Don’t Repeat Yourself.”

Welcome to MCC Level Scripts

My Client Center (MCC) level scripts — a function that was announced last month and is still in beta — solve some of these problems by allowing you to host all of your scripts in your MCC and apply them to each of the accounts at the same time.

You can apply logic using the executeInParallel() function to up to 50 accounts at the same time and collect the results in a single place for reporting. Also, your scripts can now run up to an hour total if you design them properly.

ScriptRunning40Mins

Before you read any further, you should sign up for AdWords MCC level scripts access. Approval usually takes a few business days.

Still Some Limitations

Even with these new additions, AdWords scripts may not be ready to handle your massive accounts. The processing for each account is still limited to 250,000 entities, and each iterator can only access 50,000 entities at a time.

Also, the executeInParallel function can only be called once per script, so if you have more than 50 accounts you need to run this on, you will need to store the list of accounts in a file on Google Drive and process them in chunks.

Accessing The MCC Scripts

MCC_Level_Scripts

After you have requested access, you should see a new navigation link in your MCC account called “Scripts.”  From there, it works just like the rest of the AdWords scripts you know and love.

You can find the full documentation on the AdWords Scripts documentation portal.

The MccApp object is now the place to start when building your scripts. It allows you to build an Account selector which you can use to iterate through your accounts.

With these new features, it is now possible to build a reporting spreadsheet that allows you to see how all of your accounts are doing on a daily basis.

Building Your First MCC Script

This script will pull your account level data into a Google Spreadsheet with each tab representing an account. In addition, all of the results will be summed together and reported in a separate tab.

MCC_Account_Report 2

To get started, this is the main() function that will be executing:

function main() {
  MccApp.accounts()
    .withLimit(50)
    .executeInParallel('runOnEachAccount', 'finished');
}

This code is saying “run the function runOnEachAccount() on each of my accounts and when you are done, call the function finished().” Next, we can define the two functions we told executeInParallel to call:

function runOnEachAccount() {
  Logger.log('Starting on: '+
    AdWordsApp.currentAccount().getCustomerId());
  var results = getAccountReport();
  return JSON.stringify(results);
}

function finished(resultsArray) {
  var spreadsheetName = 'MCC Account Report';
  var spreadsheet = getSpreadsheet(spreadsheetName);
  var totalResults;
  for(var i in resultsArray) {
    var accountResults = JSON.parse(resultsArray[i].getReturnValue());
    var customerIdIndex = getCols().indexOf('ExternalCustomerId');
    var sheetName = accountResults[customerIdIndex];
    if(!sheetName) { continue; }
    addResultsToSpreadsheet(spreadsheet,accountResults,sheetName);
    totalResults = addToTotalResults(totalResults,accountResults);
  }
  var totalsSheetName = 'All Accounts';
  addResultsToSpreadsheet(spreadsheet,totalResults,totalsSheetName);
  if(spreadsheet.getSheetByName('Sheet1')) {
    spreadsheet.deleteSheet(spreadsheet.getSheetByName('Sheet1'));
  }
}

Let’s start with the function runOnEachAccount(). This is the function that executeInParallel will execute on each account (clever name, I know).

I’ve made it really simple so that it just grabs the Account Performance Report for yesterday and returns that data to be processed later. Note that these are just snippets and do not contain all the function calls. The full script can be found for free on GitHub.

The only stipulation for this function is that it needs to return a string, which is why we use the JSON.stringify() method that quickly turns our array into a string. You can see that in the finished() function, we convert it back into an array using JSON.parse().

The finished() function is where we process all the data from each of the accounts. The resultsArray variable contains all the ExecutionResults from running the runOnEachAccount() function, which we then iterate through to build our report.

There are other calls that help create and manage the Google Spreadsheet, but nothing you can’t handle. You can find the full code for this example on GitHub. Just copy and paste the code into your MCC level script and hit Preview.

AdWords Scripts is Growing Up

With this release, Google is really demonstrating some of the awesome power of scripts and reaffirming their dedication to the platform. Building something like this using the AdWords API would probably take weeks and would require ongoing costs like storage and hosting fees. With AdWords scripts, it can be done in an hour.

If you’ve held off from using AdWords Scripts before, now is a good time to take another look. If you are paying for a third-party tool, maybe there are ways to get similar functionality at a fraction of the cost.

While the AdWords API is still more powerful, you can do more than ever using AdWords scripts, and you don’t need a degree in computer science to do it.


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


About the author

Russell Savage
Contributor
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 FreeAdWordsScripts.com, where he posts AdWords Scripts for anyone to use.

Get the must-read newsletter for search marketers.