How to Convert a Single Account Script to MCC script?

Image result for no "copy paste"

 

If you’re managing multiple Google Ads accounts, running scripts in every one of them can be a pain in the A.

When managing a large number of accounts you might end up spending your whole day copy-pasting scripts all over the place until you banged out the C and V keys from your keyboard. Let alone the time and effort it will take to make minor changes to tens of copies of the same script.

Let’s say you find a bug in a script that you’ve copied to 10 or 25 accounts. Normally you’d need to log in to each account, one-by-one, opening all these different tabs, update the same piece of code over and over again, save the code, test that is actually working, and finally close the tab again. Aaarrrgh.

MCC scripts to the rescue. With MCC scripts you can just do it once, saving you a ton of time, frustration and grey hair. They allow you to manage multiple accounts from within a single script (at scale, in parallel).

Here’s a code snippet, tested and ready for you to use, to convert any simple single account script into a script that can run on the MCC level.

Within the main function, you can set up an iterator that goes through each individual account one-by-one:

function main () {

  var mccAccount = AdWordsApp.currentAccount();

  // OPTIONAL: Select your accounts based on conditions
  // see https://developers.google.com/adwords/scripts/docs/reference/mccapp/mccapp_managedaccountselector#withCondition_1
  // example: this selector selects all accounts with over 100 impressions last month
  var accountSelector = MccApp.accounts()
    .withCondition('Impressions > 100')
    .forDateRange('LAST_MONTH');

  // get the iterator to iterate over all selected accounts
  var accountIterator = accountSelector.get();

  // Iterate through the list of accounts
  while (accountIterator.hasNext()) {

    var account = accountIterator.next();

    // Select the client account.
    MccApp.select(account);

    // now do the thing you want to do on every single account
    runPerAccount();
  }

  // Switch back to MCC account
  MccApp.select(mccAccount);
}

function runPerAccount() {
  // This is where you put the code that you want to run on each account
}

This will execute the code sequentially; one-by-one per account. So, by implementing this simple piece of code you are ready to run your scripts across all accounts.

Go ahead and give it a try on one of your scripts right now.
No more copy-pasting scripts over to multiple accounts. Yay!

But wait, there’s more…

While the above example is an easy way to execute your AdWords scripts across multiple accounts, this mode of operation will quickly cause you to reach the execution time limits of Adwords Scripts; 30min max. That is because the client accounts are handled sequentially, one by one. So if the execution of the script takes 10min on average you will run out of time is you execute the scripts on more than 3 client accounts. When an MCC script times out, your script will simply stop functioning and not all the clients’ accounts will be processed.

To speed things up you will need to execute Google Ads scripts on accounts in parallel. Creating this kind MCC Script that will execute up until 50 accounts in parallel is a bit harder, that’s why I’ve created an Extended Google Ads MCC Script Template to help you with just that.

If you’re interested in the code, just let me know and I will email you the code snippet:

If the button above isn't working for you, you can sign up here to get access.