How to map number of ads and keywords in adGroups (fast)?

61 views
Skip to first unread message

Sigurd Fabrin

unread,
Apr 22, 2022, 6:22:26 AM4/22/22
to Google Ads Scripts Forum
Hi,

Can you please advise on how I can map how many ads and keywords I have in my adGroups in a faster way than the code below?

The approach I tried is working, but it seems that it is too demanding i.e. it is super-slow, so in effect not useful.

It would be great if I could somehow use AdsApp.search() instead at least partially, as it is much faster. But I cannot figure out how that can be done since I'm starting from the adGroups and then look at their content, rather than the other way around.

Here's a code snippet to illustrate a case where I wish to do smth when there is not 5 ads and/or 1 keyword in an adGroup

var adGroupIter = AdsApp.adGroups()
        .withCondition('campaign.status = ENABLED')
        .withCondition('ad_group.status = ENABLED')
        .withCondition('campaign.name REGEXP_MATCH ".*some campaign.*"')
        .withCondition('campaign.name NOT REGEXP_MATCH ".*some other campaign.*"')
        .get();
        while (adGroupIter.hasNext()) {
          var adGroup = adGroupIter.next();
          var ads = adGroup.ads()
            .withCondition('ad_group_ad.status = ENABLED')
            .withCondition('ad_group_ad.ad.type = EXPANDED_TEXT_AD')        
            .get();
            if (ads.totalNumEntities() != 5) {
              console.log(adGroup.getCampaign().getName()+' > '+adGroup.getName()+' has '+ads.totalNumEntities()+' active ads');
            }
          var keywords = adGroup.keywords()
            .withCondition('ad_group_criterion.status = ENABLED')
            .get();
            if (keywords.totalNumEntities() != 1) {
              console.log('*'+adGroup.getCampaign().getName()+' > '+adGroup.getName()+' has '+keywords.totalNumEntities()+' active keywords');
            }
        }


Hope you can point my in the direction of a better solution


Thanks
Sigurd

Google Ads Scripts Forum Advisor

unread,
Apr 26, 2022, 3:09:10 AM4/26/22
to adwords...@googlegroups.com
Hi Sigurd,

Thank you for reaching out to us.

With regard to your concern, I could see that your current implementation is align to our best practices. As per alternate solution, you may utilize both Ad Group Ad and Keyword view, then filter it by ad_group.name. However, you will still need to loop through the result and have a counter in it; which is still the same implementation as you have currently. 

Regards,
Google Logo
Teejay Wennie
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2a5nWg:ref

Sigurd Fabrin

unread,
Apr 26, 2022, 3:29:32 AM4/26/22
to Google Ads Scripts Forum
OK, too bad. 

I think I will try to implement a labelling system then,  so the script can go through a few hundred adGroups at a time or how many it has time for - and then pick up next time


Thanks
Sigurd

Google Ads Scripts Forum Advisor

unread,
Apr 27, 2022, 11:00:25 PM4/27/22
to adwords...@googlegroups.com

Hello Sigurd,

I believe that could be also a valid approach. If you need anything else from us, please let us know. We’re happy to assist you.

Regards,

Google Logo
James Howell
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2a5nWg:ref
Reply all
Reply to author
Forward
0 new messages