Script Information
Your Google Ads can be disapproved for many different reasons, this can result in a loss traffic and revenue if not fixed quickly.
When managing multiple accounts, Google’s default checks may not be sent to the right person. This script fixes that issue by allowing you to tailor who alerts are sent too as well as increasing the frequency that ads are scanned.
You can use this manager level script to send an email alert if any of your ads are disapproved in your manager account. This script will only check enabled campaigns, adgroups and ads.
-
Script Type: New Script Experience
-
Script Level: Manager Account
//*** INFO ***//
//*** Used to check for disapproved ads within Enabled Campaigns & Adgroups. Sends email to a listed group of emails. ***//
//add account CIDs as a comma seperate list in the account ID array
let config = {
accountIDs: ['123-345-5678', '123-345-5678'],
emails: ['example@gmail.com', 'example2@gmail.com']
}
function main() {
let disapprovedArray = new Array();
//Google Ads account iterator
let accountIterator = AdsManagerApp.accounts()
.withIds(config.accountIDs) // Comment out this line if you would like to check all accounts in a manager account.
.get();
//Iterates through accounts
while (accountIterator.hasNext()) {
let account = accountIterator.next();
AdsManagerApp.select(account);
let accountName = account.getName();
Logger.log(`Checking Ads for ${accountName}`)
let adIterator = AdsApp.ads()
.withCondition('ad_group_ad.status = ENABLED')
.withCondition('campaign.status = ENABLED')
.withCondition('ad_group.status = ENABLED')
.withCondition('ad_group_ad.policy_summary.approval_status = DISAPPROVED')
.get()
let count = adIterator.totalNumEntities()
Logger.log(`Found ${count} dissaproved ads for ${accountName}`)
if (count > 0) {
disapprovedArray.push([accountName, count])
}
}
if (disapprovedArray.length > 0) {
let email = createEmail(disapprovedArray)
sendEmail(config.emails.join(','), email)
}
else {
Logger.log(`No disapproved ads found for accounts`)
}
}
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">Ads Disapproved</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 count = e[1]
let rowHtml = `<tr><td class="tg-0pky">${accountName}</td><td class="tg-0pky">${count}</td></tr>`
rows.push(rowHtml)
})
return rows.join("")
}
function sendEmail(emailAddress, html) {
MailApp.sendEmail({
to: emailAddress,
name: 'Digital Expanse Scripts',
subject: `Google Ads Disapproved Ads`,
htmlBody: html
});
}