Pausing and labeling Ad Groups with no active keywords

1,618 views
Skip to first unread message

Kamila

unread,
Mar 18, 2014, 11:54:25 AM3/18/14
to adwords...@googlegroups.com
Hi, I'm a beginner and trying to run an easy script for pausing ad groups with no active keywords and labeling them. I don't understand why creating a new label is not possible and keep getting error message "The label No Active Kws does not exist."  Does anyone know how to correct it?


function main() { 
function createLabelIfNecessary(labelName) {
  if (!AdWordsApp.labels()
          .withCondition("LabelName = 'No Active Kws'")
          .get().hasNext()) {
    AdWordsApp.createLabel("No Active Kws","Ad groups with no active kws");
  }}

  var ag_iter = AdWordsApp.adGroups()
  .get();
  
  while(ag_iter.hasNext()) {
    var ag = ag_iter.next();
   
    var kw_iter = ag.keywords()
      .withCondition("Status = ENABLED")
      .get();
    var has_kw = kw_iter.hasNext();

     createLabelIfNecessary("No Active Kws");

    if(!has_kw) {
      ag.applyLabel("No Active Kws");
 ag.pause();
    }
  }}

Anash Oommen

unread,
Mar 19, 2014, 2:50:26 PM3/19/14
to adwords...@googlegroups.com
Hi Kamila,

The script should run fine if you were to Run rather than Previewing it. Labels don't get created in preview mode.

Cheers,
Anash P. Oommen
AdWords Scripts Team.

Carlos Hoffmann

unread,
May 15, 2015, 8:16:19 AM5/15/15
to adwords...@googlegroups.com
Hi. This script works for me. It is the best "Pause and label adgroups without keywords" script I have used yet. Thank you.

ACSI

unread,
May 11, 2016, 10:07:41 AM5/11/16
to AdWords Scripts Forum
Good morning,

I have a question about the script.
Right now, the script also pauses adgroups in the deleted and paused campaigns.
Is it possible to exclude paused and deleted campaigns. I have tried it with the function: .withCondition('CampaignStatus = ENABLED')
This is not working. Also I want to exclude some of the campaigns, like the DSA campaigns. I tried it with the function: .withCondition("CampaignName DOES_NOT_CONTAIN 'DSA'")
But, also this is not working. Could you help me?

Kind regards,
Iris van Eldik

Op woensdag 19 maart 2014 19:50:26 UTC+1 schreef Anash Oommen:

Tyler Sidell (AdWords Scripts Team)

unread,
May 11, 2016, 11:09:09 AM5/11/16
to AdWords Scripts Forum
Hi Iris,

.withCondition("CampaignStatus = ENABLED") should exclude paused and deleted campaigns. You could also provide me with your CID (reply privately to the author) for me to take a look at your full script.  If you are running into issues and also want to include only certain campaigns (excluding DSA), you may be interested in filtering by labels instead.

Thanks,
Tyler Sidell
AdWords Scripts Team

Angeline Loo

unread,
Nov 2, 2017, 3:10:27 AM11/2/17
to AdWords Scripts Forum
May i know where to apply this part of script ".withCondition("CampaignStatus = ENABLED")" ?

Anthony Madrigal

unread,
Nov 2, 2017, 10:43:00 AM11/2/17
to AdWords Scripts Forum
Hi Angeline,

It depends which entity you are looking for. For example, if you want to find ad groups whose campaigns are enabled, you will need to use AdWordsApp.adGroups().withCondition("CampaignStatus = ENABLED").get().

Since this is an old thread, if you have any additional questions, please create a new thread.

Cheers,
Anthony
AdWords Scripts Team

Website Fanack

unread,
May 28, 2018, 6:05:22 AM5/28/18
to AdWords Scripts Forum
Hi, it seems not possible to identify DSA campaigns without manually labeling these campaigns, adgroups and so forth. I received message from Adwords telling me that there where adgroups without any keywords. Since I have multiple scrips running and hundreds of adgroups I would have been nice to exclude the DSA adgroups. In fact in the message I've received from Google they listed only non-DSA adgroups. Sady I can not create a script that gives me the exact same list. hence I can not create an script to pause or remove these empty non-dsa adgroups. 

Joyce Lava (AdWords Scripts Team)

unread,
May 29, 2018, 2:47:30 AM5/29/18
to AdWords Scripts Forum
Hi,

Since there is currently no available field that will return the campaign and adGroup type that will determine if it is DSA or not, then aside from labeling these DSA entities, you may also want to try using Keywordless Query Report which will return search terms on DSA level. It has the AdGroupId and CampaignId fields. However, please take note that this will return search terms information that generated stats since it is a report. 

Another way to get the DSA adGroups is to generate the Ad Group Performance Report and filter for AdGroupType = SEARCH_DYNAMIC_ADS as seen in this detailed guide.

I hope this helps. If you will need further clarifications, please create a new forum thread as this is an old one.

Regards,
Joyce Lava
AdWords Scripts Team

Huong Tran

unread,
May 16, 2019, 11:28:26 AM5/16/19
to Google Ads Scripts Forum
It works if you remove 2 redundant "}" at the end of the scripts. Thanks.

Jack Burnet

unread,
Mar 17, 2020, 12:32:21 PM3/17/20
to Google Ads Scripts Forum
Does anyone know how to remove the label part of this script? I want to pause all ad groups with paused keywords. 

Thanks!

2chainz

unread,
Mar 23, 2020, 4:56:24 AM3/23/20
to Google Ads Scripts Forum
I wanted to just label the ad groups with no K2S and remove the last line ag.pause part but foudn out that only no active kw's label has been created but the ad groups dont have the label :( 

2chainz

unread,
Mar 23, 2020, 5:14:06 AM3/23/20
to Google Ads Scripts Forum
And also another important question since I'm using SA360  inventory management option;

Would my label be removed if some ad groups have active KW's now? 




On Tuesday, 18 March 2014 17:54:25 UTC+2, Kamila wrote:

Google Ads Scripts Forum Advisor

unread,
Mar 23, 2020, 5:39:26 AM3/23/20
to adwords...@googlegroups.com
Hi,

If you just want to label all the ad groups that don't have any keywords in your Google Ads account, then you may use the simplified script below. Please note that the label 'No Active Kws' should be created first before executing the script.
function main() { 
  var ag_iter = AdsApp.adGroups().get();

  
  while(ag_iter.hasNext()) {
    var ag = ag_iter.next();
   
    var kw_iter = ag.keywords()
      .withCondition("Status = ENABLED")
      .get();

    if(kw_iter.totalNumEntities() < 1){
      ag.applyLabel("No Active Keywords")
    }
  }
}


Let me know if you have questions.

Regards,
Ejay
Google Ads Scripts Team

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