If you’ve ever manually pulled Google Ads campaign reports into Google Sheets, you know how much of a time sink it can be. Not only is it tedious, but it’s also the kind of task that begs to be automated. And let’s face it—automating tasks like this isn’t just smart, it’s what separates a good digital marketer from a great one.
In this post, I’m going to walk you through how to create a Google Ads script that will automatically pull key campaign metrics and drop them into a Google Sheet. We’ll skip the fluff and focus on the real meat: setting up your script to pull data like campaign name, status, campaign type, budget, impressions, clicks, cost, CTR, and average CPC. Sound good? Let’s dive in.
Google Ads provides built-in reports, but let’s be real—they don’t always give you exactly what you need in the way you need it. Maybe you’re reporting weekly, maybe monthly, or maybe you're running some custom calculations (like CPL or ROI) that the Ads UI doesn’t cover. Plus, pulling reports manually? That’s a total productivity killer.
If you’re like me, you want to spend time optimizing ads and scaling campaigns, not crunching numbers manually. Google Ads Scripts can handle the repetitive part for you—by automating this task, you can just sit back and watch as your data flows into Google Sheets in real-time, ready for analysis.
We’re going to pull in some basic metrics for now, but the script I’ll show you is flexible—you can modify it to include additional data fields like conversion metrics later. Here’s what we’re going to grab:
ENABLED
, PAUSED
, or something else.(Clicks / Impressions) * 100
, a key performance indicator for ad engagement.Skipping the manual labor and pulling this data into a Google Sheet automatically? Now we’re talking.
Without further ado, here’s the magic script that does all the heavy lifting for you. It’s like having a personal assistant who just quietly drops a fresh report into Google Sheets every day (minus the need for coffee breaks).
javascriptCopy code<code>function main() {
try {
// Replace with your Google Sheet URL
var SPREADSHEET_URL = 'YOUR_GOOGLE_SHEET_URL'; // Use your Google Sheets URL
var SHEET_NAME = 'YOUR_SHEET_NAME'; // Name of the sheet where data will be written
// Open the spreadsheet and the specific sheet
var spreadsheet = SpreadsheetApp.openByUrl(SPREADSHEET_URL);
var sheet = spreadsheet.getSheetByName(SHEET_NAME);
// If the sheet does not exist, create it
if (!sheet) {
sheet = spreadsheet.insertSheet(SHEET_NAME);
} else {
sheet.clear(); // Clear existing data
}
// Write headers to the sheet
sheet.appendRow(["Campaign", "Status", "Campaign type", "Budget", "Cost", "Impr.", "Clicks", "CTR", "Avg. CPC"]);
// Construct the query to get the campaign performance data
var query =
"SELECT CampaignName, CampaignStatus, AdvertisingChannelType, Amount, Cost, Impressions, Clicks " +
"FROM CAMPAIGN_PERFORMANCE_REPORT " +
"WHERE CampaignStatus IN ['ENABLED', 'PAUSED'] " + // Adjust status filters if necessary
"DURING LAST_30_DAYS";
Logger.log("Query: " + query);
// Fetch the report
var report = AdsApp.report(query);
var rows = report.rows();
// Write each row of data to the sheet
while (rows.hasNext()) {
var row = rows.next();
// Calculate CTR and Avg. CPC
var clicks = parseInt(row['Clicks']);
var impressions = parseInt(row['Impressions']);
var cost = parseFloat(row['Cost']);
var ctr = impressions > 0 ? (clicks / impressions) * 100 : 0;
var avgCpc = clicks > 0 ? cost / clicks : 0;
sheet.appendRow([
row['CampaignName'],
row['CampaignStatus'],
row['AdvertisingChannelType'],
row['Amount'], // Budget column
row['Cost'],
row['Impressions'],
row['Clicks'],
ctr.toFixed(2) + "%",
avgCpc.toFixed(2)
]);
}
Logger.log("Data successfully written to the sheet.");
} catch (e) {
Logger.log('Error: ' + e.message);
}
}
Now, the real beauty of this script is that you can set it to run automatically every day at a fixed time. This means when you roll into the office in the morning, your fresh data is sitting there in the Google Sheet, waiting for you—like a boss.
Here’s how to set up the trigger:
main
.Once this trigger is set, the script will run automatically at the specified time every day, so you’ll always have the latest data without having to lift a finger. It’s like having a virtual assistant who never sleeps.
SPREADSHEET_URL
) and the sheet name (SHEET_NAME
) with placeholders. When you implement this script, just replace 'YOUR_GOOGLE_SHEET_URL'
and 'YOUR_SHEET_NAME'
with the actual values.Want to get more out of this script? You can easily extend it to pull additional metrics like Leads
or calculate your Cost Per Lead (CPL)
by tweaking the query. Heck, you could even automate it to send you daily reports if you want to get really fancy.
At the end of the day, this script is all about making your life easier. Automate what can be automated, so you can focus on strategy, optimization, and growth. Because let’s be honest—there’s a lot more value in that than spending hours pulling reports.
If you’ve got questions or want to tweak this script for your needs, hit me up in the comments or shoot me a message. Happy automating!