Google Ads Script | Daily Cost Export (Single Account)
Google Ads Script | Daily Cost Export (Single Account)
Zac Cannon
December 11, 2024
The Problem: Keeping track of Google Ads spend across multiple campaigns can be time-consuming and error-prone. Manual exports are tedious, and you might miss important spending trends or budget overruns until it's too late.
What this script does: This script automatically exports your daily Google Ads costs at the campaign level to a Google Sheet. It captures essential metrics including:
Daily spend by campaign
Monthly aggregation
Impressions, clicks, and conversions
Conversion value
How this script will save you time & money:
Eliminates manual data exports (avoids Supermetrics)
Provides daily spend tracking without logging into Google Ads
Helps identify campaigns that are overspending or underperforming
Creates a historical record for better budget planning
Enables quick month-over-month spend analysis
Setup Requirements:
Google Ads account with script access
Google Sheet to store the data
Basic configuration (2-minute setup)
How to Install:
Create a new Google Sheet
Create a new tab named according to your preference
Copy the Sheet URL
In Google Ads:
Go to Tools & Settings > Bulk Actions > Scripts
Click the plus button to create a new script
Copy and paste the provided code
Update the settings variable with your Sheet URL and tab name
Save and authorise the script
Schedule the Script:
Click the plus button in the frequency column
Set to run daily (recommended time: early morning)
The script will automatically populate your sheet with the previous day's data
Understanding the Output: The script exports the following columns:
Date: The day the costs were incurred
Month: For easy monthly aggregation
Campaign Name: Individual campaign identification
Cost: Daily spend in your account's currency
Impressions: Number of ad shows
Clicks: Number of ad clicks
Conversions: Number of recorded conversions
Conversion Value: Total value from conversions
Customisation Options: You can modify the script to:
Change the date range (currently set from 2022)
Add additional metrics like CTR or CPA
Include other dimensions like ad groups or device
Adjust the output format
Troubleshooting: If you encounter issues:
Verify your Google Sheet URL and tab name are correct
Ensure the script has proper authorization
Check that your Sheet isn't at maximum row capacity
Confirm your date ranges are valid
This script provides a foundation for automated cost tracking that you can build upon based on your specific needs. Whether you're managing a small account or a large portfolio, having automated daily cost exports will save time and improve your ability to manage budgets effectively.
Access the script here: https://docs.google.com/document/d/1v4mV65k3x-KEBj555wQFGsDWbCjIxsGjAalfnFaOaIA/edit?tab=t.0
/**
* Google Ads Cost Export (Single Account) -
* Written By Zac Cannon
*
* This script will export google ads cost at the campaign level by day to a Google Sheet, helping you keep track of ad spend.
* Update url and sheet with Google sheets spreadsheet url and tab name in settings variable before using
* Date starts 01/01/2022 to yesterday - adjust accordingly
* Version: 1.0
* Created: 25-07-2024
*/
// Export to sheet
// settings
let settings = {
url: '',
sheet: '',
}
// date
let MILLIS_PER_DAY = 1000 * 60 * 60 * 24;
let now = new Date();
let from = new Date(now.getTime() - 4 * MILLIS_PER_DAY);
let to = new Date(now.getTime() - 1 * MILLIS_PER_DAY); // yesterday
let timeZone = AdsApp.currentAccount().getTimeZone();
function main() {
let data = [];
let query = 'SELECT ' +
'segments.date, segments.month, campaign.name, metrics.cost_micros, metrics.impressions, metrics.clicks, metrics.conversions, metrics.all_conversions_value ' +
'FROM campaign ' +
'WHERE segments.date BETWEEN "' + '2022-01-01' + '" AND "' + Utilities.formatDate(to, timeZone, 'yyyy-MM-dd') + '"';
let result = AdsApp.search(query);
while (result.hasNext()) {
let row = result.next();
data.push([row.segments.date, row.segments.month, row.campaign.name, row.metrics.costMicros/1000000, row.metrics.impressions, row.metrics.clicks, row.metrics.conversions, row.metrics.all_conversions_value])
}
let ss = SpreadsheetApp.openByUrl(settings.url);
let sheet = ss.getSheetByName(settings.sheet);
sheet.getRange("A2:H").clearContent(); // delete any old data from sheet */
// get last row for column A in export sheet
var columnToCheck = sheet.getRange("A:A").getValues();
var lastRow = getLastRowSpecial(columnToCheck);
sheet.getRange(lastRow+1,1,data.length,data[0].length).setValues(data) // export data to sheet
}
// get last row special
function getLastRowSpecial(range){
var rowNum = 0;
var blank = false;
for(var row = 0; row < range.length; row++){
if(range[row][0] === "" && !blank){
rowNum = row;
blank = true;
}else if(range[row][0] !== ""){
blank = false;
};
};
return rowNum;
};
Google Ads Script | Daily Cost Export (Single Account)
Google Ads Script | Daily Cost Export (Single Account)
Zac Cannon
December 11, 2024
The Problem: Keeping track of Google Ads spend across multiple campaigns can be time-consuming and error-prone. Manual exports are tedious, and you might miss important spending trends or budget overruns until it's too late.
What this script does: This script automatically exports your daily Google Ads costs at the campaign level to a Google Sheet. It captures essential metrics including:
Daily spend by campaign
Monthly aggregation
Impressions, clicks, and conversions
Conversion value
How this script will save you time & money:
Eliminates manual data exports (avoids Supermetrics)
Provides daily spend tracking without logging into Google Ads
Helps identify campaigns that are overspending or underperforming
Creates a historical record for better budget planning
Enables quick month-over-month spend analysis
Setup Requirements:
Google Ads account with script access
Google Sheet to store the data
Basic configuration (2-minute setup)
How to Install:
Create a new Google Sheet
Create a new tab named according to your preference
Copy the Sheet URL
In Google Ads:
Go to Tools & Settings > Bulk Actions > Scripts
Click the plus button to create a new script
Copy and paste the provided code
Update the settings variable with your Sheet URL and tab name
Save and authorise the script
Schedule the Script:
Click the plus button in the frequency column
Set to run daily (recommended time: early morning)
The script will automatically populate your sheet with the previous day's data
Understanding the Output: The script exports the following columns:
Date: The day the costs were incurred
Month: For easy monthly aggregation
Campaign Name: Individual campaign identification
Cost: Daily spend in your account's currency
Impressions: Number of ad shows
Clicks: Number of ad clicks
Conversions: Number of recorded conversions
Conversion Value: Total value from conversions
Customisation Options: You can modify the script to:
Change the date range (currently set from 2022)
Add additional metrics like CTR or CPA
Include other dimensions like ad groups or device
Adjust the output format
Troubleshooting: If you encounter issues:
Verify your Google Sheet URL and tab name are correct
Ensure the script has proper authorization
Check that your Sheet isn't at maximum row capacity
Confirm your date ranges are valid
This script provides a foundation for automated cost tracking that you can build upon based on your specific needs. Whether you're managing a small account or a large portfolio, having automated daily cost exports will save time and improve your ability to manage budgets effectively.
Access the script here: https://docs.google.com/document/d/1v4mV65k3x-KEBj555wQFGsDWbCjIxsGjAalfnFaOaIA/edit?tab=t.0
/**
* Google Ads Cost Export (Single Account) -
* Written By Zac Cannon
*
* This script will export google ads cost at the campaign level by day to a Google Sheet, helping you keep track of ad spend.
* Update url and sheet with Google sheets spreadsheet url and tab name in settings variable before using
* Date starts 01/01/2022 to yesterday - adjust accordingly
* Version: 1.0
* Created: 25-07-2024
*/
// Export to sheet
// settings
let settings = {
url: '',
sheet: '',
}
// date
let MILLIS_PER_DAY = 1000 * 60 * 60 * 24;
let now = new Date();
let from = new Date(now.getTime() - 4 * MILLIS_PER_DAY);
let to = new Date(now.getTime() - 1 * MILLIS_PER_DAY); // yesterday
let timeZone = AdsApp.currentAccount().getTimeZone();
function main() {
let data = [];
let query = 'SELECT ' +
'segments.date, segments.month, campaign.name, metrics.cost_micros, metrics.impressions, metrics.clicks, metrics.conversions, metrics.all_conversions_value ' +
'FROM campaign ' +
'WHERE segments.date BETWEEN "' + '2022-01-01' + '" AND "' + Utilities.formatDate(to, timeZone, 'yyyy-MM-dd') + '"';
let result = AdsApp.search(query);
while (result.hasNext()) {
let row = result.next();
data.push([row.segments.date, row.segments.month, row.campaign.name, row.metrics.costMicros/1000000, row.metrics.impressions, row.metrics.clicks, row.metrics.conversions, row.metrics.all_conversions_value])
}
let ss = SpreadsheetApp.openByUrl(settings.url);
let sheet = ss.getSheetByName(settings.sheet);
sheet.getRange("A2:H").clearContent(); // delete any old data from sheet */
// get last row for column A in export sheet
var columnToCheck = sheet.getRange("A:A").getValues();
var lastRow = getLastRowSpecial(columnToCheck);
sheet.getRange(lastRow+1,1,data.length,data[0].length).setValues(data) // export data to sheet
}
// get last row special
function getLastRowSpecial(range){
var rowNum = 0;
var blank = false;
for(var row = 0; row < range.length; row++){
if(range[row][0] === "" && !blank){
rowNum = row;
blank = true;
}else if(range[row][0] !== ""){
blank = false;
};
};
return rowNum;
};
Google Ads Script | Daily Cost Export (Single Account)
Google Ads Script | Daily Cost Export (Single Account)
Zac Cannon
December 11, 2024
The Problem: Keeping track of Google Ads spend across multiple campaigns can be time-consuming and error-prone. Manual exports are tedious, and you might miss important spending trends or budget overruns until it's too late.
What this script does: This script automatically exports your daily Google Ads costs at the campaign level to a Google Sheet. It captures essential metrics including:
Daily spend by campaign
Monthly aggregation
Impressions, clicks, and conversions
Conversion value
How this script will save you time & money:
Eliminates manual data exports (avoids Supermetrics)
Provides daily spend tracking without logging into Google Ads
Helps identify campaigns that are overspending or underperforming
Creates a historical record for better budget planning
Enables quick month-over-month spend analysis
Setup Requirements:
Google Ads account with script access
Google Sheet to store the data
Basic configuration (2-minute setup)
How to Install:
Create a new Google Sheet
Create a new tab named according to your preference
Copy the Sheet URL
In Google Ads:
Go to Tools & Settings > Bulk Actions > Scripts
Click the plus button to create a new script
Copy and paste the provided code
Update the settings variable with your Sheet URL and tab name
Save and authorise the script
Schedule the Script:
Click the plus button in the frequency column
Set to run daily (recommended time: early morning)
The script will automatically populate your sheet with the previous day's data
Understanding the Output: The script exports the following columns:
Date: The day the costs were incurred
Month: For easy monthly aggregation
Campaign Name: Individual campaign identification
Cost: Daily spend in your account's currency
Impressions: Number of ad shows
Clicks: Number of ad clicks
Conversions: Number of recorded conversions
Conversion Value: Total value from conversions
Customisation Options: You can modify the script to:
Change the date range (currently set from 2022)
Add additional metrics like CTR or CPA
Include other dimensions like ad groups or device
Adjust the output format
Troubleshooting: If you encounter issues:
Verify your Google Sheet URL and tab name are correct
Ensure the script has proper authorization
Check that your Sheet isn't at maximum row capacity
Confirm your date ranges are valid
This script provides a foundation for automated cost tracking that you can build upon based on your specific needs. Whether you're managing a small account or a large portfolio, having automated daily cost exports will save time and improve your ability to manage budgets effectively.
Access the script here: https://docs.google.com/document/d/1v4mV65k3x-KEBj555wQFGsDWbCjIxsGjAalfnFaOaIA/edit?tab=t.0
/**
* Google Ads Cost Export (Single Account) -
* Written By Zac Cannon
*
* This script will export google ads cost at the campaign level by day to a Google Sheet, helping you keep track of ad spend.
* Update url and sheet with Google sheets spreadsheet url and tab name in settings variable before using
* Date starts 01/01/2022 to yesterday - adjust accordingly
* Version: 1.0
* Created: 25-07-2024
*/
// Export to sheet
// settings
let settings = {
url: '',
sheet: '',
}
// date
let MILLIS_PER_DAY = 1000 * 60 * 60 * 24;
let now = new Date();
let from = new Date(now.getTime() - 4 * MILLIS_PER_DAY);
let to = new Date(now.getTime() - 1 * MILLIS_PER_DAY); // yesterday
let timeZone = AdsApp.currentAccount().getTimeZone();
function main() {
let data = [];
let query = 'SELECT ' +
'segments.date, segments.month, campaign.name, metrics.cost_micros, metrics.impressions, metrics.clicks, metrics.conversions, metrics.all_conversions_value ' +
'FROM campaign ' +
'WHERE segments.date BETWEEN "' + '2022-01-01' + '" AND "' + Utilities.formatDate(to, timeZone, 'yyyy-MM-dd') + '"';
let result = AdsApp.search(query);
while (result.hasNext()) {
let row = result.next();
data.push([row.segments.date, row.segments.month, row.campaign.name, row.metrics.costMicros/1000000, row.metrics.impressions, row.metrics.clicks, row.metrics.conversions, row.metrics.all_conversions_value])
}
let ss = SpreadsheetApp.openByUrl(settings.url);
let sheet = ss.getSheetByName(settings.sheet);
sheet.getRange("A2:H").clearContent(); // delete any old data from sheet */
// get last row for column A in export sheet
var columnToCheck = sheet.getRange("A:A").getValues();
var lastRow = getLastRowSpecial(columnToCheck);
sheet.getRange(lastRow+1,1,data.length,data[0].length).setValues(data) // export data to sheet
}
// get last row special
function getLastRowSpecial(range){
var rowNum = 0;
var blank = false;
for(var row = 0; row < range.length; row++){
if(range[row][0] === "" && !blank){
rowNum = row;
blank = true;
}else if(range[row][0] !== ""){
blank = false;
};
};
return rowNum;
};
Google Ads Script | Daily Cost Export (Single Account)
Google Ads Script | Daily Cost Export (Single Account)
Zac Cannon
December 11, 2024
The Problem: Keeping track of Google Ads spend across multiple campaigns can be time-consuming and error-prone. Manual exports are tedious, and you might miss important spending trends or budget overruns until it's too late.
What this script does: This script automatically exports your daily Google Ads costs at the campaign level to a Google Sheet. It captures essential metrics including:
Daily spend by campaign
Monthly aggregation
Impressions, clicks, and conversions
Conversion value
How this script will save you time & money:
Eliminates manual data exports (avoids Supermetrics)
Provides daily spend tracking without logging into Google Ads
Helps identify campaigns that are overspending or underperforming
Creates a historical record for better budget planning
Enables quick month-over-month spend analysis
Setup Requirements:
Google Ads account with script access
Google Sheet to store the data
Basic configuration (2-minute setup)
How to Install:
Create a new Google Sheet
Create a new tab named according to your preference
Copy the Sheet URL
In Google Ads:
Go to Tools & Settings > Bulk Actions > Scripts
Click the plus button to create a new script
Copy and paste the provided code
Update the settings variable with your Sheet URL and tab name
Save and authorise the script
Schedule the Script:
Click the plus button in the frequency column
Set to run daily (recommended time: early morning)
The script will automatically populate your sheet with the previous day's data
Understanding the Output: The script exports the following columns:
Date: The day the costs were incurred
Month: For easy monthly aggregation
Campaign Name: Individual campaign identification
Cost: Daily spend in your account's currency
Impressions: Number of ad shows
Clicks: Number of ad clicks
Conversions: Number of recorded conversions
Conversion Value: Total value from conversions
Customisation Options: You can modify the script to:
Change the date range (currently set from 2022)
Add additional metrics like CTR or CPA
Include other dimensions like ad groups or device
Adjust the output format
Troubleshooting: If you encounter issues:
Verify your Google Sheet URL and tab name are correct
Ensure the script has proper authorization
Check that your Sheet isn't at maximum row capacity
Confirm your date ranges are valid
This script provides a foundation for automated cost tracking that you can build upon based on your specific needs. Whether you're managing a small account or a large portfolio, having automated daily cost exports will save time and improve your ability to manage budgets effectively.
Access the script here: https://docs.google.com/document/d/1v4mV65k3x-KEBj555wQFGsDWbCjIxsGjAalfnFaOaIA/edit?tab=t.0
/**
* Google Ads Cost Export (Single Account) -
* Written By Zac Cannon
*
* This script will export google ads cost at the campaign level by day to a Google Sheet, helping you keep track of ad spend.
* Update url and sheet with Google sheets spreadsheet url and tab name in settings variable before using
* Date starts 01/01/2022 to yesterday - adjust accordingly
* Version: 1.0
* Created: 25-07-2024
*/
// Export to sheet
// settings
let settings = {
url: '',
sheet: '',
}
// date
let MILLIS_PER_DAY = 1000 * 60 * 60 * 24;
let now = new Date();
let from = new Date(now.getTime() - 4 * MILLIS_PER_DAY);
let to = new Date(now.getTime() - 1 * MILLIS_PER_DAY); // yesterday
let timeZone = AdsApp.currentAccount().getTimeZone();
function main() {
let data = [];
let query = 'SELECT ' +
'segments.date, segments.month, campaign.name, metrics.cost_micros, metrics.impressions, metrics.clicks, metrics.conversions, metrics.all_conversions_value ' +
'FROM campaign ' +
'WHERE segments.date BETWEEN "' + '2022-01-01' + '" AND "' + Utilities.formatDate(to, timeZone, 'yyyy-MM-dd') + '"';
let result = AdsApp.search(query);
while (result.hasNext()) {
let row = result.next();
data.push([row.segments.date, row.segments.month, row.campaign.name, row.metrics.costMicros/1000000, row.metrics.impressions, row.metrics.clicks, row.metrics.conversions, row.metrics.all_conversions_value])
}
let ss = SpreadsheetApp.openByUrl(settings.url);
let sheet = ss.getSheetByName(settings.sheet);
sheet.getRange("A2:H").clearContent(); // delete any old data from sheet */
// get last row for column A in export sheet
var columnToCheck = sheet.getRange("A:A").getValues();
var lastRow = getLastRowSpecial(columnToCheck);
sheet.getRange(lastRow+1,1,data.length,data[0].length).setValues(data) // export data to sheet
}
// get last row special
function getLastRowSpecial(range){
var rowNum = 0;
var blank = false;
for(var row = 0; row < range.length; row++){
if(range[row][0] === "" && !blank){
rowNum = row;
blank = true;
}else if(range[row][0] !== ""){
blank = false;
};
};
return rowNum;
};
We grow e-commerce brands.
Get in touch: sales@vida-digital.co.uk
Vida Digital Marketing Limited
Registered in England and Wales
Company number: 14162188
© Copyright 2024
Vida Digital Marketing Limited
Crafted by kreated
We grow e-commerce brands.
Get in touch: sales@vida-digital.co.uk
Vida Digital Marketing Limited
Registered in England and Wales
Company number: 14162188
© Copyright 2024
Vida Digital Marketing Limited
Crafted by kreated
We grow e-commerce brands.
Get in touch: sales@vida-digital.co.uk
Vida Digital Marketing Limited
Registered in England and Wales
Company number: 14162188
© Copyright 2024
Vida Digital Marketing Limited
Crafted by kreated
We grow e-commerce brands.
Get in touch: sales@vida-digital.co.uk
Vida Digital Marketing Limited
Registered in England and Wales
Company number: 14162188
© Copyright 2024
Vida Digital Marketing Limited
Crafted by kreated