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 checks accounts for any broad match search keywords that may be live. This is designed for accounts running Exact / Phrase match combinations and do not wish to run Broad match.
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 broadKeywordCount = [];
while (accountIterator.hasNext()) {
let account = accountIterator.next();
AdsManagerApp.select(account);
let accountName = account.getName();
let keywordIterator = AdsApp.keywords()
.withCondition("ad_group_criterion.keyword.match_type = EXACT")
.withCondition("campaign.status = ENABLED")
.withCondition("ad_group.status = ENABLED")
.withCondition("ad_group_criterion.status = ENABLED")
.withCondition("campaign.advertising_channel_type = SEARCH")
.get();
let totalBroadKeywords = keywordIterator.totalNumEntities();
if (totalBroadKeywords > 0) {
broadKeywordCount.push([accountName, totalBroadKeywords]);
}
}
if (broadKeywordCount.length > 0) {
let email = createEmail(broadKeywordCount);
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><th class="tg-5w1r">Broad Keywords</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 broadKeywords = e[1];
let rowHtml = `<tr><td class="tg-0pky">${accountName}</td><td class="tg-0pky">${broadKeywords}</td></tr>`;
rows.push(rowHtml);
});
return rows.join("");
}
function sendEmail(emailAddress, html) {
MailApp.sendEmail({
to: emailAddress,
name: "Digital Expanse Scripts",
subject: `Google Ads Scripts - Broad Keywords Found`,
htmlBody: html,
});
}