Managing multiple Google Ads accounts can be challenging, especially when keeping track of spend and ensuring you’re pacing well within your monthly budget. Overspending can eat into profits, while underspending may mean missed opportunities. But what if you could automate this process?
In this blog post, I’ll show you how to use a Google Ads script to automate spend tracking, pacing analysis, and even receive alerts if you’re overspending. It’s a simple yet powerful way to stay on top of your budgets.
What Does the Script Do?
This custom Google Ads script:
1. Tracks Spend Automatically: Logs daily and monthly spend data for multiple accounts into a Google Sheet.
2. Calculates Pacing: Compares actual spend against expected spend based on how far into the month you are.
3. Replaces Old Data: Keeps your Google Sheet clean by replacing old data with fresh, up-to-date numbers after each run.
4. Sends Alerts: Notifies you by email if any account is over-pacing by more than 10% of its monthly budget.
Why You Need This Script
When managing ads, keeping budgets in check can be time-consuming and error-prone if done manually. This script:
• Saves time by automating spend tracking.
• Improves budget control by showing if you’re spending too fast or too slow.
• Prevents overspending with timely email alerts.
Whether you’re managing a single account or multiple accounts through an MCC (My Client Centre), this script provides clear, actionable insights.
How to Set It Up
Follow these steps to set up the script:
1. Prepare Your Google Spreadsheet
• Create a new Google Sheet.
• Add two tabs:
• Sheet1 (for tracking data) with the following headers in Row 1:
• Account Name, Date, Daily Spend, Cumulative Spend, Monthly Budget, Expected Spend (So Far), Pacing Difference (£), Pacing Status
• Budgets (for monthly budget data) with the following headers:
• Column A: Account ID (e.g., 123-456-7890)
• Column B: Monthly Budget (e.g., 1000)
2. Copy the Script
function main() {
var SPREADSHEET_URL = 'YOUR_SPREADSHEET_URL_HERE'; // Replace with your spreadsheet URL
var spreadsheet = SpreadsheetApp.openByUrl(SPREADSHEET_URL);
var dataSheet = spreadsheet.getSheetByName('Sheet1'); // Default sheet name
var budgetSheet = spreadsheet.getSheetByName('Budgets'); // Budget sheet
// Clear previous data (keep headers)
dataSheet.getRange(2, 1, dataSheet.getLastRow() - 1, dataSheet.getLastColumn()).clearContent();
// Get budgets for all accounts from the Budgets sheet
var budgetData = budgetSheet.getDataRange().getValues();
var budgetMap = {};
for (var i = 1; i < budgetData.length; i++) {
var accountId = budgetData[i][0];
var monthlyBudget = budgetData[i][1];
budgetMap[accountId] = monthlyBudget;
}
// Iterate through all accounts
var accountSelector = MccApp.accounts().withCondition("Impressions > 0").get();
while (accountSelector.hasNext()) {
var account = accountSelector.next();
var accountId = account.getCustomerId();
var accountName = account.getName(); // Fetch the account name
var monthlyBudget = budgetMap[accountId];
if (!monthlyBudget) {
Logger.log('No budget data for Account ID: ' + accountId);
continue; // Skip accounts without budget info
}
MccApp.select(account); // Switch to the account
var stats = AdsApp.currentAccount().getStatsFor("TODAY");
var dailySpend = stats.getCost();
var totalSpend = AdsApp.currentAccount().getStatsFor("THIS_MONTH").getCost();
// Calculate pacing
var today = new Date();
var dayOfMonth = today.getDate(); // Current day of the month
var daysInMonth = new Date(today.getFullYear(), today.getMonth() + 1, 0).getDate();
var expectedSpend = (monthlyBudget / daysInMonth) * dayOfMonth; // Expected spend up to today
var pacingDifference = totalSpend - expectedSpend; // Over/Under pacing
// Determine status
var pacingStatus = pacingDifference > 0 ? "Over Pacing" : "Under Pacing";
// Add fresh data to the spreadsheet
dataSheet.appendRow([
accountName, // Use account name here
new Date().toISOString(),
dailySpend.toFixed(2),
totalSpend.toFixed(2),
monthlyBudget,
expectedSpend.toFixed(2),
pacingDifference.toFixed(2),
pacingStatus
]);
// Send alert if significantly over budget
if (pacingDifference > (monthlyBudget * 0.1)) { // Alert if over pacing by 10% of budget
sendEmailAlert(accountName, 'Budget Over Pacing Alert', `Your account "${accountName}" is over pacing by £${pacingDifference.toFixed(2)}.`);
}
}
}
function sendEmailAlert(accountName, subject, body) {
var email = "YOUR_EMAIL_ADDRESS_HERE"; // Replace with your email address
MailApp.sendEmail(email, subject, body);
}
Replace:
• YOUR_SPREADSHEET_URL_HERE with your Google Sheet’s URL.
• YOUR_EMAIL_ADDRESS_HERE with the email address where you want to receive alerts.
3. Add the Script in Google Ads
• Log in to your Google Ads account and go to Tools & Settings > Scripts.
• Paste the script and authorise access to your Google Sheet.
4. Schedule the Script
• Set it to run daily to ensure the spreadsheet is always updated with the latest spend data.
What Will You See?
Once the script is running:
• Your spreadsheet will be updated daily with fresh spend data for all accounts.
• You’ll see:
• Daily spend.
• Total spend for the month.
• How much you should have spent so far (based on pacing).
• Whether the account is over-pacing or under-pacing.
When Will You Get Alerts?
The script sends you an email if any account exceeds its expected spend by more than 10% of the monthly budget. For example:
Subject: Budget Over Pacing Alert - Account: Example Ads 1
Body: Your account “Example Ads 1” is over pacing by £100.00.
This allows you to take immediate action to adjust bids or budgets.
Customisation Options
Want to tweak the script? Here are a few ideas:
• Adjust the pacing alert threshold (e.g., alert at 5% instead of 10%).
• Include additional columns in the spreadsheet, such as impressions or clicks.
• Add support for weekly budgets if needed.
Take Control of Your Google Ads Budgets
With this script, you’ll no longer have to worry about manual spend tracking or pacing analysis. It’s a simple, automated solution to keep your campaigns on budget and performing optimally.
Ready to try it out? Set up the script today and enjoy a clearer view of your Google Ads performance!
If you have any questions or need help setting up the script, feel free to contact me. Happy budgeting!