Ads Manager Scripts

The AdsManagerApp
class in Google Ads scripts enables you to manage accounts linked under your
Manager 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 manager account level; check out our Solutions
Center for other manager account use case examples.

Retrieving list of accounts

You can retrieve all accounts (except for AdWords Express accounts) under a
manager account using the
accounts
method, e.g.:

The accounts call will retrieve the list of all client accounts under the
manager account 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:

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,

Working on accounts in parallel

Google Ads 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:

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:

The function specified by functionName can optionally accept a string argument (optionalInput).
This parameter may be used to pass an additional parameter to all the parallel
methods that is called by executeInParallel method. E.g.

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.

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
Ads Manager scripts execution time limits.