Vai al contenuto

Google Ads Scripts for Multi-Account Media Buyers: Limits, Patterns and Code

11 min lettura
MK

Marta Kowalczyk

Agency Operations Lead

Google Ads scripts are JavaScript programs that run inside Google Ads, either in one account or from a manager account across many client accounts. For media buyers who run a portfolio, they turn repetitive checks into scheduled jobs: budget pacing emails, broken link reports, anomaly alerts and search term exports to Google Sheets, all from one place.

Quick answer: Open Tools, then Bulk actions, then Scripts. For many clients, put the script in the manager account and use executeInParallel, which handles up to 50 accounts per run with a 60-minute limit when you add a callback. Start with read-only scripts that only send email, preview them, then schedule hourly or daily.

This guide is about running scripts across many accounts. If you want help writing them with an AI assistant, read our guide to Claude for Google Ads, and if you are still choosing between rules and scripts, start with the Google Ads automated rules guide.

What are Google Ads scripts and where do you find them?

Google Ads scripts are a built-in automation feature that lets you read and change account data with JavaScript, on a schedule, without running your own server. Google's scripts getting started page describes them as a "serverless automation platform" that uses modern JavaScript, runs Google Ads Query Language (GAQL) reports, reads and writes Google Sheets through SpreadsheetApp and calls outside APIs through UrlFetchApp.

In the interface, Google's scripts help page gives the path: click the Tools icon, open the Bulk actions drop-down in the section menu, then click Scripts. To add one:

  1. Click the plus button and give the script a name.
  2. Paste the code into the editor.
  3. Click Authorize now, then Grant access.
  4. Click Preview and read the log and the list of changes.
  5. Run it, or set a frequency to schedule it.

The same page has Script history, where you see when each script ran, its status and its log statements, and a Changes view with the detail of what it modified.

How do account scripts and manager account scripts differ?

Account scripts and manager account scripts use the same language, but a manager account script can work through many client accounts in one run, which is what makes scripts practical for agencies. Google's manager account scripts page introduces AdsManagerApp, which selects client accounts and switches the script's context to each one.

There are two ways to cover several accounts:

  • Sequentially. Loop through the accounts and call AdsManagerApp.select(account). Every call after that applies to the selected account until you select another.
  • In parallel. Call executeInParallel on an account selector. Google runs your function in each account and, if you name a callback, passes all the results to it once every account has finished.
Google Ads scripts: account scripts compared with manager account scripts and their limits
Account script or manager account script

The limits that matter come from Google's scripts limits page:

LimitWhat Google documents
Run time, account script30 minutes
Run time, manager account script30 minutes, or 60 minutes with executeInParallel and a callback
Accounts per executeInParallel runUp to 50
Authorised scripts250 per account
Results from one iteratorUp to 50,000
IDs in withIds()Up to 10,000
Log outputTruncated at 100 KB
Data returned per account to the callbackUp to 10 MB

Two details from the manager account page shape how you build: only client accounts can be selected, not sub-manager accounts, and closed, cancelled and suspended accounts are left out unless you filter on status yourself. If you manage more than 50 accounts, split them with withIds() or withLimit() into several scripts, each covering its own group.

How do you schedule and authorise scripts?

Scheduling and authorisation decide whether a script keeps running after you set it up, and both have details that trip up agencies with many people and many accounts. Google's developer documentation lists hourly, daily, weekly and monthly schedules, plus on-demand runs. The help page describes setting the frequency from the Frequency column with the pencil icon and choosing the date, weekday or day of the month and the hour.

Pick the frequency from the job:

  • Hourly for alerts that lose value if they arrive late, such as overspend or a broken landing page.
  • Daily for summaries and exports. Google's own solution scripts note that Google Ads statistics can be up to 3 hours delayed, so a daily report run after 3 a.m. sees a complete previous day.
  • Weekly or monthly for housekeeping, such as exporting search terms for a negative keyword review.

Authorisation is where agency scripts quietly stop. Google's authorisation page for scripts says scripts take actions on the user's behalf, and that if the original author is removed from the account, "the script will stop running but remain available" until someone with access authorises it again. When someone leaves the team, check every scheduled script they authorised. Our guide to Google Ads account access covers the access side of that clean-up.

Google's help page also notes that bulk actions owned by a top-level manager account are visible only to that account, not to sub-managers or client accounts. A client who looks under Scripts in their own account will not see the manager script that reports on them.

Which scripts are worth running across many accounts?

The scripts worth running across a portfolio are the ones that watch for problems you would otherwise find by opening each account, because those checks scale badly by hand. Four patterns cover most of it.

Budget pacing alerts. A script compares spend so far today, or this month, with the budget and emails the campaigns that are running hot. Remember that Google can spend up to twice the average daily budget on a single day, so set the threshold with that in mind. Our guide to Google Ads budget pacing covers the monthly maths.

Broken final URLs. Google's Link Checker solution goes through ads, keywords and sitelinks, requests each final URL and saves the broken ones to a spreadsheet, with optional emails. Google recommends scheduling it hourly; it keeps track of progress across runs so large accounts finish over several executions. The documentation does not say it pauses anything, so treat it as a report and decide yourself what to pause.

Anomaly alerts. Google's Account Anomaly Detector solution compares today's impressions, clicks, conversions and cost with the same weekday in previous weeks and sends one email per alert per day. It is documented as a single-account script, so for a portfolio you either install it in each account or build your own manager version.

Search term exports to Sheets. A weekly script can run a GAQL query on search_term_view and write the results to a Google Sheet per client, ready for the negative keyword review. Google's scripts reports page shows the query and notes that AdsApp.search returns fields in lowerCamelCase, while AdsApp.report keeps the dotted names and can write straight to a sheet with exportToSheet().

Of the four, only the link check needs UrlFetchApp; the others need only AdsApp, MailApp and SpreadsheetApp, which keeps them simple to review.

Example: a daily budget alert for one account

The first sample is a read-only budget alert for a single account: it emails the enabled campaigns that have already spent more than 150% of their daily budget today, and it changes nothing. It uses only AdsApp.search with a GAQL query and MailApp.sendEmail.

// Emails enabled campaigns that have spent more than 150% of their
// daily budget today. Read-only: it changes nothing in the account.
const EMAIL = 'you@example.com';
const THRESHOLD = 1.5;

function main() {
  const rows = AdsApp.search(
    'SELECT campaign.name, campaign_budget.amount_micros, ' +
      'metrics.cost_micros FROM campaign ' +
      "WHERE campaign.status = 'ENABLED' " +
      'AND segments.date DURING TODAY'
  );
  const lines = [];
  while (rows.hasNext()) {
    const row = rows.next();
    const budget = Number(row.campaignBudget.amountMicros) / 1e6;
    const cost = Number(row.metrics.costMicros) / 1e6;
    if (budget > 0 && cost > budget * THRESHOLD) {
      lines.push(`${row.campaign.name}: ${cost.toFixed(2)} of ${budget.toFixed(2)}`);
    }
  }
  if (lines.length > 0) {
    const account = AdsApp.currentAccount();
    MailApp.sendEmail(
      EMAIL,
      `Budget alert: ${account.getName()}`,
      lines.join('\n')
    );
  }
}

Three notes before you schedule it. Amounts are in the account's currency, divided from micros. A shared budget shows the shared amount on every campaign that uses it, so read those lines with care. And because MailApp is not covered by preview, a preview run sends the email for real, which is fine for a read-only alert as long as EMAIL is your own address.

Example: one summary email for every client account

The second sample moves the same check to a manager account, so one script covers up to 50 client accounts and you get a single email instead of one per account. It uses executeInParallel with a callback, the pattern Google's manager account page documents.

// Manager account version: checks up to 50 client accounts in parallel
// and sends one summary email. Read-only.
const EMAIL = 'you@example.com';
const THRESHOLD = 1.5;

function main() {
  AdsManagerApp.accounts()
    .withLimit(50)
    .executeInParallel('checkAccount', 'sendSummary');
}

function checkAccount() {
  const rows = AdsApp.search(
    'SELECT campaign.name, campaign_budget.amount_micros, ' +
      'metrics.cost_micros FROM campaign ' +
      "WHERE campaign.status = 'ENABLED' " +
      'AND segments.date DURING TODAY'
  );
  const flagged = [];
  while (rows.hasNext()) {
    const row = rows.next();
    const budget = Number(row.campaignBudget.amountMicros) / 1e6;
    const cost = Number(row.metrics.costMicros) / 1e6;
    if (budget > 0 && cost > budget * THRESHOLD) {
      flagged.push(`${row.campaign.name}: ${cost.toFixed(2)} of ${budget.toFixed(2)}`);
    }
  }
  return JSON.stringify({ name: AdsApp.currentAccount().getName(), flagged });
}

function sendSummary(results) {
  const lines = [];
  for (const result of results) {
    if (result.getStatus() !== 'OK') {
      lines.push(`${result.getCustomerId()}: ${result.getStatus()}`);
      continue;
    }
    const data = JSON.parse(result.getReturnValue());
    for (const item of data.flagged) {
      lines.push(`${data.name}: ${item}`);
    }
  }
  if (lines.length > 0) {
    MailApp.sendEmail(EMAIL, 'Budget alerts across clients', lines.join('\n'));
  }
}

The callback also reports accounts whose run ended in ERROR or TIMEOUT, the two failure statuses Google documents for ExecutionResult, so a silent failure in one client account still shows up. Accounts can use different currencies, so add AdsApp.currentAccount().getCurrencyCode() to the returned data if your clients do.

How do you test a script safely before it touches clients?

Testing a script safely means proving what it reads and what it would change before it runs on a schedule, and Google's preview mode does only part of that job. Google's preview mode page says scripts in preview "make no changes to the actual campaign data" and show the changes that would have been made, but preview "only affects calls that use AdsApp as an entry point". Emails go out and spreadsheets are updated in preview too.

A routine that holds up across many accounts:

  1. Start read-only. Log or email, never pause or edit, until the output has been right for a week.
  2. Test on one account first, then widen the manager selector with withIds().
  3. Use your own address and a copy of the sheet while testing, never a client's.
  4. Read the Changes view after the first scheduled runs.
  5. Limit any write step with a label or a campaign name condition, so a bug touches a known set of campaigns.
  6. Watch the email quota. Google's limits page points to the Apps Script quotas, which list 100 email recipients a day for a consumer Google account and 1,500 for Google Workspace; check which applies to the account that authorises the script.

An hourly alert that emails five people from twenty accounts can reach a consumer quota quickly, which is another reason to send one summary from a manager script rather than one email per account.

When should you use automated rules or a tool instead?

Scripts are the right choice when the logic is custom, but automated rules or an outside tool are often simpler when the job is a standard threshold check or spans several ad platforms. Google Ads automated rules handle pauses, budget changes and Send email alerts without code, although Google says they can run up to two hours after the scheduled time. Our guide to ad spend alerts compares the native options on Google, Meta and TikTok.

A practical split for a media buyer running many accounts:

  • Automated rules for simple guardrails a colleague without JavaScript can read and change.
  • Scripts for custom logic, reports into Sheets, link checks and anything that needs data from outside Google Ads.
  • A tool above the platforms when the same alert has to cover Meta, TikTok or native accounts too, because a Google Ads script sees only Google Ads.

Scripts also carry a maintenance cost. Each one needs an owner, a review when Google changes its API, and re-authorisation when people change. The official Google Ads MCP server is a different tool again: it lets an AI assistant read account data, but it does not replace scheduled scripts.

Where Wevion fits

Wevion does not run Google Ads scripts, edit them or replace the custom logic you write in them; it fits the alerting and reporting side of the job when your accounts span more than Google.

Wevion connects Google, Meta, TikTok, Snapchat, Taboola and Outbrain ad accounts through each platform's official API and syncs data about every 15 minutes, so spend and results for every client sit in one view without a script per account or a summary email to build.

Its automated rules on Google Ads can just notify you, without changing anything, or pause a campaign or change its budget by a percentage when a threshold you set is crossed, with a cooldown so a rule does not fire again on the same item too soon and a daily cap on runs. Rules run per platform today; cross-platform rules are in beta. Link checks, search term exports and custom GAQL reports stay in scripts.

You can try it on your own ad accounts with 14 days free on any plan, no card.

Key takeaways

  • Google Ads scripts live under Tools, Bulk actions, Scripts, and need authorising before preview or run.
  • A manager account script can cover up to 50 client accounts per run with executeInParallel, with up to 60 minutes when you add a callback.
  • Scripts stop when the person who authorised them is removed from the account, so track every script's owner.
  • Preview blocks only AdsApp changes; emails and spreadsheet updates still happen during preview.
  • Start with read-only patterns: budget pacing alerts, Link Checker reports, anomaly alerts and search term exports to Sheets.
  • Use automated rules for simple guardrails and a cross-platform tool when the same alert must cover more than Google Ads.
Torna al Blog
Condividi

Domande Frequenti

The Ad Signal

Insight settimanali per media buyer che non tirano a indovinare. Una email, solo sostanza.

Pronto ad Automatizzare le Tue Operazioni?

Inizia a lanciare campagne in blocco su ogni piattaforma. Prova Wevion gratis per 14 giorni su ogni piano, senza carta.