Account overview (all time)
(date range export)
This script fetches performance data from a specific account, then writes this data into a spreadsheet on scheduled cadence. It structures the data to show all campaign data in the account.
To set up this script, follow these steps:
Open your Google Ads account.
Go to the "Tools & Settings" menu and select "Scripts".
Click the "Create" or "+" button to create a new script.
Copy and paste the following script.
function main() {
// Replace with the URL of your Google Sheet
var spreadsheetUrl = 'INSERT-SPREADSHEET-URL';
var sheetName = 'INSERT-SHEET-NAME'; // Replace with your sheet name
var sheet = SpreadsheetApp.openByUrl(spreadsheetUrl).getSheetByName(sheetName);
if (!sheet) {
Logger.log('Sheet with name ' + sheetName + ' not found');
return;
}
// Clear the sheet before adding new data
sheet.clear();
// Add headers
sheet.appendRow(['Campaign Name', 'Campaign State', 'Impressions', 'Clicks', 'CPC', 'Cost', 'Conversions', 'Cost/Conversion']);
// Get the campaigns
var campaigns = AdsApp.campaigns().get();
while (campaigns.hasNext()) {
var campaign = campaigns.next();
// Get the stats for the campaign
var stats = campaign.getStatsFor('ALL_TIME');
// Calculate CPC and Cost/Conversion
var cpc = (stats.getCost() / stats.getClicks()) || 0;
var costPerConversion = (stats.getCost() / stats.getConversions()) || 0;
// Determine campaign state
var campaignState = "Unknown";
if (campaign.isEnabled()) {
campaignState = "Enabled";
} else if (campaign.isPaused()) {
campaignState = "Paused";
} else if (campaign.isRemoved()) {
campaignState = "Removed";
}
// Append the data to the sheet
sheet.appendRow([
campaign.getName(),
campaignState,
stats.getImpressions(),
stats.getClicks(),
cpc.toFixed(2),
stats.getCost().toFixed(2),
stats.getConversions(),
costPerConversion.toFixed(2)
]);
}
}
Replace the spreadsheet URL.
Save the script.
Review and authorize the script to access your Google Ads and Google Sheets accounts.
Run the script manually for the first time to populate the initial values in the spreadsheet.
(Optional) Schedule the script to run on a specific cadence (ie: daily, weekly, monthly, etc.)
Note: Ensure that you have the necessary permissions to access and modify the target Google Spreadsheet.
Last updated