MCC Scripts

The MccApp class in AdWords scripts enables you to manage accounts linked under your My Client Center account. This allows you to manage all your advertiser accounts through a single script, so that you do not need to create separate scripts for each account. One popular use is running reports at the MCC level; check out our Solutions Center for other MCC use case examples.

Retrieving list of accounts

You can retrieve all accounts (except for AdWords Express accounts) under an MCC using the accounts method, e.g.

var accountSelector = MccApp.accounts()
    .withCondition("Impressions > 100")
    .orderBy("Clicks DESC");

var accountIterator = accountSelector.get();

The accounts call will retrieve the list of all client accounts under the MCC hierarchy by default. You can use the withLimit method of ManagedAccountSelector class to restrict the number of accounts that your script retrieves. Another option is to select the accounts by their customer ids using the withIds method, as shown below:

var accountSelector = MccApp.accounts()
    .withIds(['918-501-8835', '320-368-4437', '925-591-3280']);

Working on client accounts

Once you retrieve the client accounts, you can iterate through them using the ManagedAccountIterator's hasNext and next methods. You need to use the select method to switch the execution context to a client account. After you select a client account, any further API calls will apply to the client account until you explicitly select another account. For example,

// Keep track of the MCC account for future reference.
var mccAccount = AdWordsApp.currentAccount();

// Select your accounts

// Iterate through the list of accounts
while (accountIterator.hasNext()) {
  var account = accountIterator.next();

  // Select the client account.

  // Select campaigns under the client account
  var campaignIterator = AdWordsApp.campaigns().get();

  // Operate on client account

// Switch back to MCC account

Working on accounts in parallel

AdWords scripts allows you to operate on multiple client accounts in parallel, using the executeInParallel method of the ManagedAccountSelector class. The executeInParallel method has the following signature:

function executeInParallel(functionName, optionalCallbackFunctionName);

The executeInParallel method executes a function specified by functionName on each ManagedAccount that the ManagedAccountSelector matches. Once all accounts have been processed, the callback function, if specified by optionalCallbackFunctionName, is executed once, passing an array of all response objects as its argument for any further processing. The typical usage is shown below:

function main() {
  var accountSelector = MccApp.accounts()
      .withCondition("Impressions > 100")
      .orderBy("Clicks DESC");

  accountSelector.executeInParallel("processClientAccount", "afterProcessAllClientAccounts");

function processClientAccount() {
  var clientAccount = AdWordsApp.currentAccount();

  // Process your client account here.

  // optionally, return a result, as a text.
  return "";

function afterProcessAllClientAccounts(results) {
  for (var i = 0; i < results.length; i++) {
    var result = results[i].getReturnValue();
    // Process the result further

The function specified by functionName can optionally return a string. If you want to return a JavaScript object instead, you could convert it into a string using the JSON.stringify method, e.g.

var jsonObj = {value: 10, list: [1,2,3,4,5,6], name: "Joe Smith"};
return JSON.stringify(jsonObj);

The returned values will be passed into the callback function in a list of ExecutionResult objects. If you returned a JSON string from the function, you could convert it back into a JavaScript object using JSON.parse method, e.g.

function callbackFunctionName(results) {
  for (var i = 0; i < results.length; i++) {
    var resultObj = JSON.parse(results[i].getReturnValue());

The executeInParallel method will operate on a maximum of 50 accounts, so you'll have to implement your own restrictions to limit the number of accounts that your script retrieves. You can use the withLimit or withIds method of ManagedAccountSelector class to restrict the number of accounts that your script retrieves.

Execution time limits

See this page for details on MCC execution time limits.

Send feedback about...

AdWords Scripts