Google Ads Scripts
Find Auto Applied Recommendations
Cum funcționează?
Acest script verifică zilnic istoricul modificărilor din toate conturile conectate la MCC.
Rolul său este să detecteze modificările efectuate prin recomandările aplicate automat.
Dacă sunt identificate astfel de modificări, scriptul trimite un raport detaliat la adresa de e-mail specificată.
Cu alte cuvinte, această soluție oferă un plus de siguranță și control asupra recomandărilor automate din Google Ads.
Configurarea Scriptului
Setează adresa ta de e-mail în variabila
EMAIL_SETTINGS
.Programează scriptul să ruleze o dată pe zi, dimineața.
Opțional, setează numărul de zile pentru care să verifice în trecut în variabila
LOOKBACK_DAYS
. Valoarea implicită este 3, cu un maxim de 30 de zile.
/*
Copyright 2023 Krzysztof Bycina
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// --------------------------------------- Configuration:
const EMAIL_SETTINGS = {
RECIPIENT: 'YOUR EMAIL HERE',
SUBJECT: 'Auto-apply Recommendations have been found.'
};
const LOOKBACK_DAYS = 5; // Specify the number of days to look back (Max 30)
// --------------------------------------- End of the configuration
function main() {
const dateRange = computeDateRange(LOOKBACK_DAYS);
const managerAccount = AdsApp.currentAccount();
const allAccounts = AdsManagerApp.accounts();
let formattedEmailContent = '';
for (const account of allAccounts) {
Logger.log('Checking account: ' + account.getName());
AdsManagerApp.select(account);
const reportData = fetchReportData(dateRange);
const accountContent = formatReportData(reportData);
if (accountContent) {
Logger.log('Auto-apply Recommendations have been found in account: ' + account.getName());
}
formattedEmailContent += accountContent;
}
formattedEmailContent += '';
if (formattedEmailContent !== '') {
sendEmail(formattedEmailContent, EMAIL_SETTINGS);
} else {
Logger.log("No changes found. Email not sent.");
}
}
function computeDateRange(days) {
const today = new Date();
const lookbackDate = new Date(today.getTime() - (days - 1) * 24 * 60 * 60 * 1000);
const formattedStartDate = Utilities.formatDate(lookbackDate, AdsApp.currentAccount().getTimeZone(), 'yyyyMMdd');
const formattedEndDate = Utilities.formatDate(today, AdsApp.currentAccount().getTimeZone(), 'yyyyMMdd');
return { start: formattedStartDate, end: formattedEndDate };
}
function fetchReportData(dateRange) {
const reportFields = [
'customer.descriptive_name',
'change_event.change_date_time',
'campaign.name',
'ad_group.name',
'change_event.resource_change_operation',
'change_event.change_resource_type',
];
const selectStatement = reportFields.join(', ');
return AdsApp.report(
`SELECT ${selectStatement} ` +
`FROM change_event ` +
`WHERE change_event.change_date_time BETWEEN '${dateRange.start}' AND '${dateRange.end}' AND change_event.user_email = 'Recommendations Auto-Apply' ` +
`ORDER BY change_event.change_date_time DESC ` +
`LIMIT 100`
);
}
function formatReportData(report) {
const fieldMapping = {
'customer.descriptive_name': 'Account name',
'change_event.change_date_time': 'Date and time',
'campaign.name': 'Campaign name',
'ad_group.name': 'Ad group name',
'change_event.resource_change_operation': 'Change type',
'change_event.change_resource_type': 'Change in'
};
let emailContent = '';
let rows = report.rows();
while (rows.hasNext()) {
let row = rows.next();
emailContent += '';
for (const field in fieldMapping) {
let fieldName = fieldMapping[field];
let fieldValue = field === 'change_event.change_date_time' ? reformatDate(row[field]) : row[field];
emailContent += `${fieldName}: ${fieldValue}
`;
}
emailContent += '';
}
return emailContent;
}
function reformatDate(dateTimeString) {
const options = {
year: 'numeric', month: 'long', day: 'numeric',
hour: '2-digit', minute: '2-digit',
hour12: true
};
const dateObj = new Date(dateTimeString);
return dateObj.toLocaleDateString('en-US', options);
}
function sendEmail(content, settings) {
MailApp.sendEmail({
to: settings.RECIPIENT,
subject: settings.SUBJECT,
htmlBody: content
});
}
Cum să Implementezi Scriptul
- Navighează la interfața Google Ads.
- Mergi la “Instrumente și Setări” (pictograma cheii) în colțul din dreapta sus.
- Sub “Acțiuni în masă”, selectează “Scripturi”.
- Click pe butonul albastru plus pentru a crea un nou script.
- Copiază și lipeste scriptul furnizat în editor.
- Autorizează scriptul să acceseze contul tău Google Ads urmând instrucțiunile.
- Salvează și previzualizează scriptul pentru a te asigura că rulează corect.
- Programează scriptul să ruleze zilnic pentru a menține actualizați parametrii personalizați.
Copyright 2023 Krzysztof Bycina
Articole recente
- Cuvinte Cheie – Ghidul complet pentru SEO & Google Ads May 9, 2025
- Google lansează AI Max pentru campaniile Search May 6, 2025
- Promovarea online în alegerile prezidentiale 2024 si 2025 May 5, 2025
- TikTok trimite datele utilizatorilor europeni in China May 5, 2025
- ChatGPT introduce funcția de shopping May 5, 2025