how to select keywords with condition that has no label?

27 views
Skip to first unread message

Yaniv Lev-Ari

unread,
Dec 30, 2018, 8:46:28 AM12/30/18
to Google Ads Scripts Forum
HI,

I am willing to create a script that will pause all the kewords that has 0 impressions the last 30 days.

The problem is, 
that if I add new keyword today,
it will be with no impressions the last 30 days.

so,
I thought about working with labels:

if the keyword has zero impressions the last day - and no label - it will get the label 1
if it has the label 1 - it will removed and change to label 2

if it has the label 30 - it will be pause.

so, my question is -

how to get keywords without any label?

Hiroyuki Miyauchi (Google Ads Scripts Team)

unread,
Jan 2, 2019, 3:35:09 AM1/2/19
to Google Ads Scripts Forum
Hello Yaniv,

If the label you are planning to apply to the keywords has specific labelName, you may filter by withCondition with LabelNames as seen in the sample code snippet below.

var keywords = AdsApp.keywords().withCondition("LabelNames CONTAINS_NONE ['INSERT_LABEL_NAME_HERE']").get();

However, if you are planning to apply different labels to keywords, you would need to check each keyword one by one as seen in the sample code snippet below.

var keywords = AdsApp.keywords().get();

while (keywords.hasNext()) {
   
var keyword = keywords.next();
   
var labels = keyword.labels().get();

   
if (labels.totalNumEntities() == 0) {
       
Logger.log(keyword.getText() + " doesn't have any labels.")
   
}
}

Please let me know if you have further clarifications.

Regards,
Hiroyuki
Google Ads Scripts Team

Peter Valenta

unread,
Jan 4, 2019, 1:53:49 PM1/4/19
to Google Ads Scripts Forum
A tiny bit shorter:

var keywords = AdsApp.keywords().get();

while(keywords.hasNext()) {
   
var keyword = keywords.next();

   
if(!keyword.labels().get().hasNext()) {
Reply all
Reply to author
Forward
0 new messages