Count of disapproved and/or strongly restricted ads in an account sent by email

106 views
Skip to first unread message

Jesper Eriksson

unread,
Dec 8, 2023, 7:05:19 AM12/8/23
to Google Ads Scripts Forum
Hi, 
We are working in an industry where we often get hit by disapproved and strongly restricted ads due to the nature of the products that we are selling (toys for adults). 
I am trying to figure out if we can set up a script that sends an email each week with the count of disapproved ads, and strongly restricted ads in an account. 

I've asked ChatGPT and Bard and get some suggestions to a script, but both models seem to use fields that are not available. 

The error message I get is " QueryError.UNRECOGNIZED_FIELD: Unrecognized fields in the query: 'approvalSummary.status', 'status'."
And the script I try to use is: 

function main() {
  var disapprovedAds = 0;
  var emailBody = '';

  // Get all ads in the account
  var adIterator = AdsApp.ads()
    .withCondition('approvalSummary.status = DISAPPROVED AND status = ENABLED')
    .get();

  // Count the number of disapproved ads
  while (adIterator.hasNext()) {
    disapprovedAds++;
  }

  // If there are disapproved ads, send an email
  if (disapprovedAds > 0) {
    emailBody = 'There are ' + disapprovedAds + ' disapproved ads in your account.';

    var emailTo = 'yo...@email.com';
    var emailSubject = 'Disapproved Ads Alert';

    var emailContent = {
      from: 'Google Ads Notification',
      to: emailTo,
      subject: emailSubject,
      body: emailBody
    };

    MailApp.sendEmail(emailContent);
  }
}

Would be great if anyone had suggestions to how to get this script up and running, since it would save us considerable time, checking each account we have. 

With best regards

Google Ads Scripts Forum Advisor

unread,
Dec 8, 2023, 9:56:23 AM12/8/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 you are getting a “QueryError.UNRECOGNIZED_FIELD” error while executing the script. I would like to inform you that the script you provided encounters an error because the approvalSummary.status and status fields are not supported in the current version of the Google Ads API. I recommend you use the approvalStatus field Instead of relying on approvalSummary.status. This field provides the ad's current approval status, including disapproval.

If the issue still persists, kindly provide us with the following details to further investigate your concern: 
  • Google Ads account ID / CID
  • Name of the affected script
  • Screenshot of the issue
  • If the script uses a spreadsheet, please provide a shareable link to the spreadsheet. 
You can send the details via Reply privately to the author option, or direct private reply to this email.
 
This message is in relation to case "ref:!00D1U01174p.!5004Q02qXMRr:ref"

Thanks,
 
Google Logo Google Ads Scripts Team

 

Jesper Eriksson

unread,
Dec 11, 2023, 2:49:57 AM12/11/23
to Google Ads Scripts Forum on behalf of adsscripts
Hi, 

I did not have the possibility to "reply privately to the author", so please let me know if this way of sending information is safe. (replying directly to your email) 

I've tried to adjust the script to include approvalStatus instead of approvalSummary.status, but the script still fails. 
" Ca: QueryError.UNRECOGNIZED_FIELD: Unrecognized fields in the query: 'approvalStatus', 'status'. at main (Code:11:21)" function main() {

  var disapprovedAds = 0;
  var emailBody = '';

  // Get all ads in the account
  var adIterator = AdsApp.ads()
    .withCondition('approvalStatus = DISAPPROVED AND status = ENABLED')

    .get();

  // Count the number of disapproved ads
  while (adIterator.hasNext()) {
    disapprovedAds++;
  }

  // If there are disapproved ads, send an email
  if (disapprovedAds > 0) {
    emailBody = 'There are ' + disapprovedAds + ' disapproved ads in your account.';

    var emailTo = 'mye...@mycompany.com';

    var emailSubject = 'Disapproved Ads Alert';

    var emailContent = {
      from: 'Google Ads Notification',
      to: emailTo,
      subject: emailSubject,
      body: emailBody
    };

    MailApp.sendEmail(emailContent);
  }
}
I am new to scripts so there may be some very basic things I have missed here, but would love to learn how I set this up correctly.



--
-- You received this message because you are subscribed to the Google Groups AdWords Scripts Forum group. Please do not reply to this email. To post to this group or unsubscribe please visit https://developers.google.com/adwords/scripts/community.
---
You received this message because you are subscribed to a topic in the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/adwords-scripts/xL8_531LnZU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to adwords-scrip...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-scripts/dfKT1000000000000000000000000000000000000000000000S5CS5J00fLG4YtVrThC9NhUF_ZuGEw%40sfdc.net.


--

Jesper Eriksson

PPC Manager

jesper....@sinful.comsinful.com

Nils Rooijmans

unread,
Dec 11, 2023, 3:29:18 AM12/11/23
to Google Ads Scripts Forum
one way to fix this is to use a GAQL query and iterate over all the rows returned by the results. You would be able to count the number of disapprovals, as well as report the disapproval and the reason in a Google Sheet.

The query would look something like this:
SELECT campaign.name, ad_group.name, ad_group_ad.ad.id, ad_group_ad.ad.type, ad_group_ad.policy_summary.approval_status, ad_group_ad.policy_summary.policy_topic_entries FROM ad_group_ad WHERE ad_group_ad.policy_summary.approval_status = 'DISAPPROVED' AND campaign.status = 'ENABLED' AND campaign.serving_status != 'ENDED' AND ad_group.status = 'ENABLED' AND ad_group_ad.status = 'ENABLED' AND segments.date DURING TODAY

Hope this helps,

Nils Rooijmans
https://nilsrooijmans.com
See my Google Ads Scripts FAQ to avoid the same mistakes I made: https://nilsrooijmans.com/google-ads-scripts-faq/

Jesper Eriksson

unread,
Dec 11, 2023, 5:26:39 AM12/11/23
to Google Ads Scripts Forum
Hi Nils, 

That is awesome! 
I've made it work for two of our accounts and will continue to implement it across our other accounts as well. 
Great that it also sends an email with the number of disapproved ads! That was just what I was looking for :D 

If I want to include in the google sheets, the final URL that is associated with the disapproved ad, how do I adjust the script to also send this through to Google Sheets? 

With best regards
Jesper

Nils Rooijmans

unread,
Dec 12, 2023, 4:06:31 AM12/12/23
to Google Ads Scripts Forum
you would need to add 'ad_group_ad.ad.final_urls'  to the select clause of the GAQL query, parse the result and be sure to add it to the array that reports the issues.

Hope this helps,

Nils Rooijmans
https://nilsrooijmans.com
See my Google Ads Scripts FAQ to avoid the same mistakes I made: https://nilsrooijmans.com/google-ads-scripts-faq/

Reply all
Reply to author
Forward
0 new messages