Skip to content

Instantly share code, notes, and snippets.

@postman31
Last active February 11, 2022 04:30
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save postman31/c895fc6157ed3670762d8372789483ac to your computer and use it in GitHub Desktop.
Dissaproved Extensions Report Script
/*
Disapproved Extensions Report Script.
This scripts generates an email if there are some non-removed disapproved extensions.
Disapproval reasons are taken from PLACEHOLDER_FEED_ITEM_REPORT.
Check the nameMapping veriable below for the list of supported extensions.
Email message could also include a long list of dissaproved remarketing feed items, so adjust settings to skip this if necessary.
Developed by Dmytro Bulakh, 2020, bulakh@ppchead.com
*/
// SCRIPT SETIINGS:
// EMAIL: add recipients emails, like ['john@doe.com', 'doe@john.com']
// If there are no emails, like [] , the script would only log the report
var EMAIL = ['john@doe.com']
// SKIP DYNAMIC REMARKETING: set to true to skip remarketing feed items report or false otherwise
var SKIP_DYNAMIC_REMARKETING = true
function main() {
// PlaceholderType mapping as of API version v201809 (https://developers.google.com/adwords/api/docs/appendix/placeholders)
var nameMapping = {
"1": "Sitelink",
"2": "Call",
"3": "App",
"7": "Location",
"30": "Affiliate location",
"17": "Callout",
"24": "Structured snippet",
"31": "Message",
"35": "Price",
"38": "Promotion",
"10": "Ad customizers",
"12": "Dynamic remarketing item: Education",
"13": "Dynamic remarketing item: Flights",
"14": "Dynamic remarketing item: Custom Feed",
"15": "Dynamic remarketing item: Hotels",
"16": "Dynamic remarketing item: Real estate",
"17": "Dynamic remarketing item: Travel",
"19": "Dynamic remarketing item: Local",
"20": "Dynamic remarketing item: Jobs"
}
var query = "SELECT PlaceholderType, DisapprovalShortNames, FeedId, FeedItemId, AttributeValues, Status " +
"FROM PLACEHOLDER_FEED_ITEM_REPORT " +
"WHERE DisapprovalShortNames != '' " +
"AND Status != REMOVED " +
"DURING TODAY"
var report = AdsApp.report(query)
var rows = report.rows(), values = [], iterator = {}, reasons = {}, total = 0
var unknownTypes = {}
while (rows.hasNext()) {
var row = rows.next()
if (SKIP_DYNAMIC_REMARKETING && nameMapping[row.PlaceholderType] && nameMapping[row.PlaceholderType].match('Dynamic')) continue
row.ExtensionType = nameMapping[row.PlaceholderType]
total++
if (!row.ExtensionType) {
if (!unknownTypes[row.PlaceholderType]) unknownTypes[row.PlaceholderType] = 0.0
unknownTypes[row.PlaceholderType]++
continue
}
iterator[row.ExtensionType] = iterator[row.ExtensionType] || []
iterator[row.ExtensionType].push({
'id': row.FeedItemId,
'attr': row.AttributeValues,
'status': row.Status
})
reasons[row.FeedItemId] = row.DisapprovalShortNames
if (values.indexOf(row.DisapprovalShortNames) == -1) {
values.push(row.DisapprovalShortNames)
}
}
if (total < 1) {
Logger.log('found no dissaproved extensions')
return 'no dissaproved'
}
var message = ''
for (var type in iterator) {
message += '\n>>' + type + ': ' + (iterator[type].length) + ' disapproved extensions:\n'
Logger.log('there are %s disapproved %s extensions:', iterator[type].length, type)
var typeMessage = iterator[type].map(function (item) {
var reason = JSON.parse(reasons[item.id])[0].split('\t')[0]
return 'reason: ' + reason + ' (id:' + item.id + ')\n' + flat(JSON.parse(item.attr))
})
message += typeMessage.join('\n') + '\n'
}
Logger.log(message)
if (EMAIL && EMAIL.length && EMAIL.length > 0) {
MailApp.sendEmail(EMAIL, 'Disapproved Extensions Report for ' + AdsApp.currentAccount().getName(), message)
}
}
// Helper function for displaying extensions
function flat(record) {
var s = []
for (var key in record) {
if (key > 3) {
s.push('...')
break
}
var val = record[key].join ? record[key].join(',') : record[key]
s.push(val)
}
return s.join('\n')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment