No Active Ads in Ad Group

435 views
Skip to first unread message

jono....@phdmedia.com

unread,
Mar 23, 2017, 1:51:11 AM3/23/17
to AdWords Scripts Forum

Hi Guys,

I have found the script below which pauses ad groups with no active keywords.

I am looking for some help to modify the script so it will notify me via email when there are no active ads in an ad group. Any help would be appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*********************************************
* Pause AdGroups With No Active Keywords
* Version 1.1
* Changelog v1.1
*   - Updated for speed and added comments
* Created By: Russ Savage
* FreeAdWordsScripts.com
**********************************************/
function main() {
  // Let's start by getting all of the active AdGroups
  var agIter = AdWordsApp.adGroups()
    .withCondition('CampaignStatus = ENABLED')
    .withCondition('Status = ENABLED')
    .get();
  
  // It is faster to store them and process them all at once later
  var toPause = [];
  // Then we will go through each one
  while(agIter.hasNext()) {
    var ag = agIter.next();
    //get all the keywords that are enabled
    var kwIter = ag.keywords()
      .withCondition("Status = ENABLED")
      .get();
     
    //If .hasNext() is true, there is at least 1 kw in the AdGroup
    var hasKw = kwIter.hasNext();
    if(!hasKw) {
      toPause.push(ag);
    }
  }
   
  // Now we process them all at once to take advantage of batch processing
  for(var i in toPause) {
    toPause[i].pause();
  }
}


Vincent Racaza (AdWords Scripts Team)

unread,
Mar 23, 2017, 2:49:01 AM3/23/17
to AdWords Scripts Forum
Hi,

Based on your use case which is to send an email if there are no active ads in an ad group, the script would be something like this:

function main() {
 
// Let's start by getting all of the active AdGroups
 
var agIter = AdWordsApp.adGroups()
   
.withCondition('CampaignStatus = ENABLED')
   
.withCondition('Status = ENABLED')
   
.get();
 
 
// It is faster to store them and process them all at once later

 
var adGroupsWithNoActiveAds = [];

 
// Then we will go through each one
 
while(agIter.hasNext()) {
   
var ag = agIter.next();

   
//get all the ads that are enabled
   
var adIter = ag.ads()

     
.withCondition("Status = ENABLED")
     
.get();

     
   
//If .hasNext() is true, there is at least 1 ad in the AdGroup
   
var hasEnabledAd = adIter.hasNext();
   
if(!hasEnabledAd) {
      adGroupsWithNoActiveAds
.push(ag);
   
}
 
}
   
 
// Now we will get all the ad groups and concatenate them into one message body
 
var body = '';
 
for(var i in adGroupsWithNoActiveAds) {
    body
= body + adGroupsWithNoActiveAds[i].getId() +' ' + adGroupsWithNoActiveAds[i].getName() +'\n';
 
}
 
 
if (adGroupsWithNoActiveAds.length > 0) {
     
MailApp.sendEmail('INSERT_EMAIL_ADDRESS_HERE',
                   
'List of ad group ids with no active ads',
                    body
);
     
Logger.log("Sending complete!");
 
}
}

Let me know if this helps. Also, since this is third party script, we recommend you to contact the creator of the script if you encountered any issues on this.

Thanks,
Vincent Racaza
AdWords Scripts Team
Reply all
Reply to author
Forward
0 new messages