Script for keyword count per ad group?

539 views
Skip to first unread message

Joshua Barsch

unread,
Jun 8, 2015, 4:45:45 PM6/8/15
to adwords...@googlegroups.com
Hi, everyone. I was wondering if anyone out there knows of a script that will pull the number of keywords within each ad group (and, ideally, apply a label to those groups containing more than X keywords)? 

We have a lot of very large account with tens of thousands of ad groups and god-knows-how-many keywords, and it would be a fantastic work-saver to be able to see, at a glance, which groups have more than X amount of keywords.

Or, if anyone knows another (Adwords Editor or otherwise-based) solution to this...would love to hear it!!

Thanks!

Josh Barsch

Anthony Madrigal

unread,
Jun 8, 2015, 5:08:29 PM6/8/15
to adwords...@googlegroups.com
Hi Josh,

Here is a small snippet of code that applies a label to an AdGroup if it has more than X keywords
  var adGroupIterator = AdWordsApp.adGroups()
       
.withCondition('Name = "ADGROUP_NAME"')
       
.get();
 
if (adGroupIterator.hasNext()) {
   
var adGroup = adGroupIterator.next();  
   
var kw = adGroup.keywords().get().totalNumEntities();
   
Logger.log('AdGroup Name: ' + adGroup.getName());
   
Logger.log('# of Keywords ' +kw);
   
if(kw > X) //where X is an int
      adGroup
.applyLabel('label-name');
 
}

Cheers,
Anthony
AdWords Scripts Team

Joshua Barsch

unread,
Jun 8, 2015, 6:15:58 PM6/8/15
to adwords...@googlegroups.com
That is awesome, Anthony, thank you. But did I screw it up somehow? Here's the full code of my script, and it just runs in two seconds and applies no labels. I just put your snippet inside the function main(){ and } , and then changed X to 50 and added a label.



function main() {
  var adGroupIterator = AdWordsApp.adGroups()
        .withCondition('Name = "ADGROUP_NAME"')
        .get();
  if (adGroupIterator.hasNext()) {
    var adGroup = adGroupIterator.next();  
    var kw = adGroup.keywords().get().totalNumEntities();
    Logger.log('AdGroup Name: ' + adGroup.getName());
    Logger.log('# of Keywords ' +kw);
    if(kw > 50) //where X is an int
      adGroup.applyLabel('over50kw');

Anthony Madrigal

unread,
Jun 9, 2015, 9:00:25 AM6/9/15
to adwords...@googlegroups.com
Hello,

The script I gave you will check for all AdGroups called "ADGROUP_NAME". If you want to get all the AdGroups, just remove .withCondition('Name = "ADGROUP_NAME"') and change if(adGroupIterator.hasNext()) to while(adGroupIterator.hasNext()).

Joshua Barsch

unread,
Jun 9, 2015, 11:43:00 AM6/9/15
to adwords...@googlegroups.com
Holy cow. Thank you so very much, Anthony, that is a HUUUUGE timesaver for us, hours and hours. VIVA ANTHONY! :)
Reply all
Reply to author
Forward
0 new messages