Identify ad groups with no active ads

898 views
Skip to first unread message

Merri Reyes

unread,
Sep 1, 2013, 9:09:23 AM9/1/13
to adwords...@googlegroups.com
Newbie dilemma here. I found a script in a separate thread about finding ad groups with too many active ads, and it's been really helpful. My question now is how can I reverse the code below to alert me when I have ad groups with no active ads this time

Also, how can this be tweaked, so I don't have to manually enter the active campaigns?

Thanks in advance!

function main() {


 
//recipient of the email
 
var recipient = 'te...@example.com';
 
  //array with campaign names for which the data is fetched
 
var campaignList = ['Campaign Name 1', 'Campaign Name 2'];

 
 
//declare all variables needed below

 
//this variable will hold the information that is then sent via email

 
var resultText = '',
      campaignCnt
= campaignList.length,
      campaignName
,
      currAdGroup
,
      currAdsIter
,
      currAdsCount
,
      adGroupIter
;
 
  for(var i=0; i < campaignCnt; i++) {
    campaignName
= campaignList[i];

   
   
//get all active adgroups
    adGroupIter
= AdWordsApp.adGroups()

                   
.withCondition('Status = ENABLED')

                   
.withCondition('CampaignName = "' + campaignName + '"')
                   
.orderBy('Name')
                   
.get();
   
   
while(adGroupIter.hasNext()) {

      currAdGroup
= adGroupIter.next(),
      currAdsCount
= 0;
     
//get all enabled and approved ads in the current adgroup
      currAdsIter
= currAdGroup.ads()
                 
.withCondition('Status = ENABLED')
                 
.withCondition('ApprovalStatus = APPROVED')
                 
.get();
                 
     
//count the ads
     
//once we have reached 4 ads, remember the adGroup name and stop counting
     
while(currAdsIter.hasNext()) {
        currAdsIter
.next();
        currAdsCount
++;
       
if(currAdsCount >= 4) {
         
//remember the adgroup by appending it to the result string

          resultText
+= 'Campaign "' + campaignName + '", AdGroup "' + currAdGroup.getName() + '"' + "\n";

         
//no need to count more
         
break;
       
}
     
}
   
}

   
//Logger.log(resultText);
 
}
 
MailApp.sendEmail(recipient, 'Adwords Script - Text Ads Quantified', resultText);
}


Patrick

unread,
Sep 2, 2013, 2:50:13 AM9/2/13
to adwords...@googlegroups.com
Hi Merri,

Did you already tried to change the "currAdsCount" limit to "if(currAdsCount == 0) {"?
Reply all
Reply to author
Forward
0 new messages