What This Script Does
This script creates a detailed spreadsheet report of all accounts managed under a Google Ads Manager Account (formerly known as MCC – My Client Center). It extracts budget and spending information for each campaign within every account, allowing you to quickly assess spending patterns across your entire portfolio of managed accounts.
function main() {
var spreadsheet = SpreadsheetApp.create("Google Ads Account Report " + new Date().toISOString().split('T')[0]);
var sheet = spreadsheet.getActiveSheet();
sheet.appendRow(["Account ID", "Account Name", "Account Budget", "Total Account Spend", "Campaign Name", "Daily Budget", "Percent Spent"]);
var accountIterator = AdsManagerApp.accounts().get();
var rowIndex = 2;
while (accountIterator.hasNext()) {
var account = accountIterator.next();
AdsManagerApp.select(account);
var accountId = account.getCustomerId();
var accountName = AdsApp.currentAccount().getName();
var accountBudget = getAccountBudget();
var campaigns = AdsApp.campaigns().get();
var totalSpent = 0;
while (campaigns.hasNext()) {
var campaign = campaigns.next();
var campaignName = campaign.getName();
var dailyBudget = campaign.getBudget().getAmount();
var stats = campaign.getStatsFor("ALL_TIME");
var spent = stats.getCost();
totalSpent += spent;
var percentSpent = accountBudget ? (spent / accountBudget) * 100 : "N/A";
sheet.getRange(rowIndex, 1, 1, 7).setValues([[
accountId,
accountName,
accountBudget || "No account budget",
totalSpent,
campaignName,
dailyBudget,
percentSpent !== "N/A" ? percentSpent.toFixed(2) + '%' : "N/A"
]]);
rowIndex++;
}
// Add a blank row between accounts
sheet.getRange(rowIndex, 1, 1, 7).setValues([['', '', '', '', '', '', '']]);
rowIndex++;
}
// Autosize columns
sheet.autoResizeColumns(1, 7);
Logger.log("Report created: " + spreadsheet.getUrl());
}
function getAccountBudget() {
var accountBudgetIterator = AdsApp.budgets().get();
if (accountBudgetIterator.hasNext()) {
var accountBudget = accountBudgetIterator.next();
var amount = accountBudget.getAmount();
// Check if the amount is a meaningful budget value
if (amount > 10) { // Assuming any real budget would be more than 10
return amount;
}
}
return null;
}
Example Output
Here’s what the generated spreadsheet:
Account ID | Account Name | Account Budget | Total Account Spend | Campaign Name | Daily Budget | Percent Spent |
---|---|---|---|---|---|---|
123-456-XXXX | A1 Industries | 20000 | 4500 | Brand Keywords | 100 | 22.50% |
123-456-XXXX | A2 Industries | 20000 | 2800 | Competitor Terms | 80 | 14.00% |
123-456-XXXX | A1 Marketing Ltd | 20000 | 3200 | Product Keywords | 120 | 16.00% |
234-567-XXXX | Global Services Inc | 15000 | 3750 | Service Offerings | 150 | 25.00% |
234-567-XXXX | XY Services Inc | 15000 | 2250 | Location Targeting | 70 | 15.00% |
345-678-XXXX | L2 Marketing Ltd | No account budget | 1200 | Local Awareness | 40 | N/A |
345-678-XXXX | Local Business | No account budget | 800 | Spring Promotion | 25 | N/A |
Key Components Breakdown
- Spreadsheet Setup:
- Creates a new Google Sheet with the current date in the title
- Adds headers for account and campaign data columns
- Formats the report for readability with auto-sized columns
- Account Iteration:
- Uses
AdsManagerApp.accounts().get()
to fetch all accounts under the manager account - Loops through each account using the
select()
method to switch context
- Uses
- Data Collection Per Account:
- Extracts basic account information:
- Account ID and name
- Account-level budget (if available)
- For each campaign within the account, collects:
- Campaign name
- Daily budget
- Total spend (all-time)
- Percentage of account budget spent
- Extracts basic account information:
- Budget Analysis:
- The
getAccountBudget()
helper function attempts to find the account-level budget - Applies validation to ensure only meaningful budget values are reported
- Calculates spending percentages relative to the account budget
- The
- Report Formatting:
- Adds empty rows between accounts for better visual separation
- Auto-resizes columns to fit content
- Formats percentage values with two decimal places
- Output:
- Logs the URL of the completed spreadsheet in the Google Ads script console
- The example shows a successful output to a Google Sheet with ID “12-4H0Pplfsw652lts6ofqMVBwhXzDvmFjlC0W9H49DI”
Why This Is Useful?
It is particularly valuable for agencies and marketing teams managing multiple Google Ads accounts because it:
- Provides Portfolio-Wide Visibility: Consolidates data from all managed accounts into one view, saving time from having to check each account individually
- Budget Management: Shows both the absolute spend amounts and relative percentages of budgets used across all campaigns and accounts
- Identifies Outliers: Makes it easy to spot accounts or campaigns with unusual spending patterns
- Facilitates Client Reporting: Creates a ready-to-share document showing how budgets are being utilized
- Improves Resource Allocation: Helps account managers prioritize which accounts need attention based on budget utilization
The script handles cases where account budgets might not be set, gracefully displaying “No account budget” rather than errors, and includes all campaigns regardless of their status to give a complete picture of the account structure.
Steps to Implement Google Ads Script
To implement Google Ads scripts effectively, I’ll walk you through the process step by step:
- Access Google Ads Scripts
- Log into your Google Ads account
- Click on “Tools & Settings” in the top navigation
- Select “Scripts” under the “Bulk Actions” section
- Create a New Script
- Click the blue “+” button
- Give your script a descriptive name that reflects its purpose
- Write or Paste Your Script
- Use the built-in editor to write JavaScript code
- Google Ads scripts use a specialized JavaScript API specific to Google Ads
- Test Your Script
- Click “Preview” to test your script without making changes
- Review logs and check for errors in the execution panel
- Authorize API Access
- Grant appropriate permissions when prompted
- This allows the script to interact with your account data
- Schedule Your Script (Optional)
- Set frequency (hourly, daily, weekly, monthly)
- Choose specific times for execution
- Save and Run Your Script
- Click “Save” to store your script
- Click “Run” to execute it immediately if needed