If you would like to customise these scripts for you business. Please get in touch with us via our contact page.
Script Information
This script will check for any accounts that had no spend yesterday and will send an email alert.
let config = {
accountIDs: ['123-345-5678', '123-345-5678'],
emails: ['example@gmail.com', 'example2@gmail.com']
}
function main() {
//** Do not change anything below **//
let accountIterator = MccApp.accounts()
.withIds(config.accountIDs)
.get();
let noSpendAccounts = [];
while (accountIterator.hasNext()) {
let account = accountIterator.next();
AdsManagerApp.select(account);
let accountName = account.getName();
let campaignIterator = AdsApp.campaigns()
.withCondition("metrics.cost_micros > 0")
.forDateRange("YESTERDAY")
.get();
let campaignsWithSpend = campaignIterator.totalNumEntities();
if (campaignsWithSpend == 0) {
noSpendAccounts.push([accountName]);
}
}
if (noSpendAccounts.length > 0) {
let email = createEmail(noSpendAccounts);
sendEmail(config.emails.join(","), email);
}
}
function createEmail(array) {
let htmlHead =
'<html><head><style type="text/css">.tg{border-collapse:collapse;border-spacing:0;}.tg td{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;overflow:hidden;padding:10px 5px;word-break:normal;}.tg th{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;font-weight:normal;overflow:hidden;padding:10px 5px;word-break:normal;}.tg .tg-5w1r{background-color:#212735;border-color:inherit;color:#e0a912;text-align:center;vertical-align:middle}.tg .tg-0pky{border-color:inherit;text-align:center;vertical-align:middle}</style></head>';
let htmlBody =
'<body><table class="tg"><thead><tr><th class="tg-5w1r">Account Name</th></tr></thead><tbody>';
let htmlRows = createTableRows(array);
let fullHtml =
htmlHead +
htmlBody +
htmlRows +
'</tbody></table><div><a href="https://digital-expanse.com/" target="_blank"><img align="left" border="0" src="https://assets.unlayer.com/projects/114688/1668897510641-secondary-logo-fullcolor.png" alt="" title="" style="outline: none;text-decoration: none;-ms-interpolation-mode: bicubic;clear: both;display: inline-block !important;border: none;height: auto;float: none;width: 20%;max-width: 96px;"width="96" /></a></div></body></html>';
return fullHtml;
}
function createTableRows(array) {
let rows = new Array();
array.forEach((e) => {
let accountName = e[0];
let rowHtml = `<tr><td class="tg-0pky">${accountName}</td></tr>`;
rows.push(rowHtml);
});
return rows.join("");
}
function sendEmail(emailAddress, html) {
MailApp.sendEmail({
to: emailAddress,
name: "Digital Expanse Scripts",
subject: `Google Ads Scripts - No spend for Accounts Yesterday`,
htmlBody: html,
});
}