Google Ads Script to Monitor Change History
If you work at an agency or manage several Google Ads accounts, it can be difficult to keep track of everything. Sometimes certain accounts don’t receive enough attention or optimization, which can have negative consequences on performance. To address this challenge, I have developed this Google Ads Scripts that perform the following tasks:
• Check for any accounts that haven’t had any change history within a specific time frame, such as the past 7 days.
• Review the full change history of an account to ensure that all necessary updates have been made.
• Monitor any changes that have been made automatically through Google’s recommendation system.
• Keep track of how much time is being spent on each account, allowing for more effective allocation of resources.
By utilizing these scripts, managing multiple Google Ads accounts becomes much more manageable and ensures that all accounts receive the attention and optimization they require.
Manager Account Script
This script scans all of the accounts under your MCC and retrieves the last user activity in each account. This data can then be used to identify and flag any accounts that require attention. The results will be displayed in a format similar to the following:
By using this script, account managers can quickly assess the activity level of their accounts and prioritize their attention accordingly. This helps ensure that all accounts receive the necessary attention and optimization for optimal performance. To use the script, simply copy and paste the code provided below. Don’t forget to add the URL of your spreadsheet and the name of the sheet or tab within the spreadsheet that you want to use. By default, the script assumes that you will be using a sheet named ‘Main’, but you can change this to any name you prefer.
function main() {
//add your spreadsheet url here
const SPREAD_SHEET_URL = 'https://docs.google.com/spreadsheets/d/XXXXXXXXXXXXXXX/';
//add your sheet name here
const SHEET_NAME = 'Main';
const ss = SpreadsheetApp.openByUrl(SPREAD_SHEET_URL);
const sheet = ss.getSheetByName(SHEET_NAME);
// get last 30 days - this is the max you can get in this report
const today = new Date();
const startDate = Utilities.formatDate(new Date(today.getTime() - 29 * 24 * 60 * 60 * 1000), AdsApp.currentAccount().getTimeZone(), 'yyyyMMdd');
const endDate = Utilities.formatDate(today, AdsApp.currentAccount().getTimeZone(), 'yyyyMMdd');
// schema of the report
const fields = [
'customer.descriptive_name',
'customer.id',
'change_event.user_email',
'change_event.change_date_time',
'change_event.change_resource_type',
'campaign.name',
'ad_group.name',
'change_event.changed_fields',
'change_event.client_type',
'change_event.feed',
'change_event.feed_item',
'change_event.new_resource',
'change_event.old_resource',
'change_event.resource_change_operation',
'change_event.resource_name',
]
// clear the sheet
sheet.clearContents();
// set the headers
const headers = fields.map(function (field) {
return field.replace('change_event.', '');
});
sheet.getRange(1, 1, 1, fields.length).setValues([headers]);
// build the select clause
let selectClause = fields.join(', ');
// Select your accounts
const managerAccount = AdsApp.currentAccount();
const accountIterator = AdsManagerApp.accounts()
for (const account of accountIterator) {
Logger.log('Getting data for account: ' + account.getName());
// Select the client account.
AdsManagerApp.select(account);
let report = AdsApp.report(
`SELECT ${selectClause} ` +
`FROM change_event ` +
`where change_event.change_date_time BETWEEN '${startDate}' and '${endDate}' and change_event.user_email != 'Recommendations Auto-Apply' ` +
`ORDER BY change_event.change_date_time DESC ` +
`limit 1`
);
let rows = report.rows();
while (rows.hasNext()) {
let row = rows.next();
let rowValues = fields.map(function (field) {
return row[field];
});
sheet.appendRow(rowValues);
}
}
}
Single Account Script
This script will return all the account activity within the last 30 days including Automatic Recommendations. Please note that the maximum date range for this script is 30 days, which is enforced by Google. To use the script, simply copy and paste the code provided below. Don’t forget to add the URL of your spreadsheet and the name of the sheet or tab within the spreadsheet that you want to use. By default, the script assumes that you will be using a sheet named ‘Main’, but you can change this to any name you prefer.
function main() {
//add your spreadsheet url here
const SPREAD_SHEET_URL = 'https://docs.google.com/spreadsheets/d/XXXXXXXXXXXXXXX/';
//add your sheet name here
const SHEET_NAME = 'Main';
const ss = SpreadsheetApp.openByUrl(SPREAD_SHEET_URL);
const sheet = ss.getSheetByName(SHEET_NAME);
// get last 30 days - this is the max you can get in this report
const today = new Date();
const startDate = Utilities.formatDate(new Date(today.getTime() - 29 * 24 * 60 * 60 * 1000), AdsApp.currentAccount().getTimeZone(), 'yyyyMMdd');
const endDate = Utilities.formatDate(today, AdsApp.currentAccount().getTimeZone(), 'yyyyMMdd');
// schema of the report
const fields = [
'customer.descriptive_name',
'customer.id',
'change_event.user_email',
'change_event.change_date_time',
'change_event.change_resource_type',
'campaign.name',
'ad_group.name',
'change_event.changed_fields',
'change_event.client_type',
'change_event.feed',
'change_event.feed_item',
'change_event.new_resource',
'change_event.old_resource',
'change_event.resource_change_operation',
'change_event.resource_name',
]
// clear the sheet
sheet.clearContents();
// set the headers
const headers = fields.map(function (field) {
return field.replace('change_event.', '');
});
sheet.getRange(1, 1, 1, fields.length).setValues([headers]);
// build the select clause
let selectClause = fields.join(', ');
let report = AdsApp.report(
`SELECT ${selectClause} ` +
`FROM change_event ` +
`where change_event.change_date_time BETWEEN '${startDate}' and '${endDate}' and change_event.user_email != 'Recommendations Auto-Apply' ` +
`ORDER BY change_event.change_date_time DESC ` +
`limit 10000`
);
let rows = report.rows();
while (rows.hasNext()) {
let row = rows.next();
let rowValues = fields.map(function (field) {
return row[field];
});
sheet.appendRow(rowValues);
}
}
Entrepreneur focused on building MarTech products that bridge the gap between marketing and technology. Check out my latest products Marketing Auditor & GA4 Auditor – discover all my products here.