AdsApp.ads().get() did not return all ad.

28 views
Skip to first unread message

luke

unread,
Aug 21, 2024, 7:16:37 AM8/21/24
to Google Ads Scripts Forum
this is my code.
function main() {
  var adsCount = AdsApp.ads().get().totalNumEntities();
  console.log("ads count:" + adsCount);
 }

But the output is ads count:0

Google Ads Scripts Forum Advisor

unread,
Aug 21, 2024, 10:13:09 AM8/21/24
to adwords...@googlegroups.com
Hi,

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

Based on the provided information, I understand that you are getting the ad count as 0 while running the script. I have executed the given script in my test account, and I'm able to retrieve the ad count successfully with the given script. I would suggest you try running the script again and let us know how it goes at your end.

If you are still facing the issues, In order to investigate further, kindly provide us with the following details:
  • Google Ads account ID / CID
  • Name of the affected script
  • Error details or the screenshot of the issue (if any).
  • 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.!5004Q02vFCTA:ref" (ADR-00264191)

Thanks,
 
Google Logo Google Ads Scripts Team


 

Sigurd Fabrin

unread,
Aug 21, 2024, 11:20:05 AM8/21/24
to Google Ads Scripts Forum
Your code looks fine, but not all ad types are supported by that method.

You can try this code to see if you can find more ads in your account using AdsApp.search() than AdsApp.ads()

function main() {
    const adsIter = AdsApp.ads().get();
    const count = adsIter.totalNumEntities();
    const adTypes = [];
    const campaigns = [];
    while (adsIter.hasNext()) {
      const ad = adsIter.next();
      adTypes.push(ad.getType());
      campaigns.push(ad.getCampaign().getName());
    }
    const query =
      `SELECT
        ad_group_ad.ad.id,
        ad_group_ad.ad.type,
        campaign.name
      FROM
        ad_group_ad`;
    const response = AdsApp.search(query);
    const gaqlCount = response.totalNumEntities();
    const gaqlCampaigns = [];
    const gaqlTypes = [];
    while (response.hasNext()) {
      const row = response.next();
      gaqlCampaigns.push(row.campaign.name);
      gaqlTypes.push(row.adGroupAd.ad.type);
    }
    console.log(`Using AdsApp.ads(), found ${count} ads of these ad types:\n${returnUnique(adTypes).join('\n')}\n*\nFrom these campaigns:\n${returnUnique(campaigns).join('\n')}\n\n*\n\n`);
    console.log(`Using AdsApp.search(), found ${gaqlCount} ads of these ad types:\n${returnUnique(gaqlTypes).join('\n')}\n*\nFrom these campaigns:\n${returnUnique(gaqlCampaigns).join('\n')}`);
}
function returnUnique(data) {
  const arr = [];
  for (i=0;i<data.length;i++) {
    if (arr.indexOf(data[i]) === -1) {
      arr.push(data[i])
    }
  }
  return arr
}



Sigurd
Reply all
Reply to author
Forward
0 new messages