Google Ads Ad Assets/Ad Extension Disapproval

65 views
Skip to first unread message

Sindy T

unread,
Nov 21, 2023, 8:28:48 PM11/21/23
to Google Ads Scripts Forum
Hi there, we had a script to check for ad extension disapproval, but with the new script experience, it is no longer working. I am not a developer so am unfamiliar with coding, any help to modify the codes below is greatly appreciated!  

var config = { ACCOUNT_LABEL : "ABC"
  }
  var EMAIL = ['a...@gmail.com']
  var SKIP_DYNAMIC_REMARKETING = true
 
function main () {
 
  var mccAccount = AdWordsApp.currentAccount();
 
 
  // OPTIONAL: Select your accounts based on conditions
  // see https://developers.google.com/adwords/scripts/docs/reference/mccapp/mccapp_managedaccountselector#withCondition_1
  // example: this selector selects all accounts with over 100 impressions last month
  var accountSelector = MccApp.accounts()
    .withCondition("LabelNames CONTAINS '" + config.ACCOUNT_LABEL + "'")
 
 
  // get the iterator to iterate over all selected accounts
  var accountIterator = accountSelector.get();
 
  // Iterate through the list of accounts
  while (accountIterator.hasNext()) {
 
    var account = accountIterator.next();
 
    // Select the client account.
    MccApp.select(account);
 
    // now do the thing you want to do on every single account
    runPerAccount();
  }
 
  // Switch back to MCC account
  MccApp.select(mccAccount);
}
 
function runPerAccount() {
  // This is where you put the code that you want to run on each account
  // 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 disapproved extensions')
    return 'no disapproved'
  }

  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 (message && EMAIL && EMAIL.length && EMAIL.length > 0) {
    Logger.log(message)
    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')
}

Google Ads Scripts Forum Advisor

unread,
Nov 21, 2023, 11:49:45 PM11/21/23
to adwords...@googlegroups.com
Hi,

Thank you for reaching out to the Google Ads Scripts support team.

By reviewing your concern, I understand that your script is not working.

Upon checking your script snippet, it appears that you are referring to the legacy version of Google Ads Scripts. Kindly note that the script will not perform as expected because it is already deprecated. I would recommend that you follow the Google Ads Scripts document. You need to migrate your existing scripts to the latest version, and you can follow this guide for migration. Also, you can refer to this document Ads Manager Scripts for sample code implementation.

I hope this helps. Please feel free to get back to us if you have any further queries.

 This message is in relation to case "ref:!00D1U01174p.!5004Q02qUREH:ref"

Thanks,
 
Google Logo Google Ads Scripts Team


Reply all
Reply to author
Forward
0 new messages