Log campaign by labels

19 views
Skip to first unread message

Louis-Philippe Savard

unread,
Jan 18, 2020, 2:44:06 AM1/18/20
to Google Ads Scripts Forum
I'm trying log only the campaigns who has the Christmas promotions label applied. So far it logs all the campaigns that have the label available.

var label = AdsApp.labels()
   
.withCondition('Name = "Christmas promotions"')
   
.get().next();
var campaignIterator = label.campaigns().get();
while (campaignIterator.hasNext()) {
 
var campaign = campaignIterator.next();
 Logger.log(campaign.getName());

}

Sigurd

unread,
Jan 20, 2020, 1:03:06 AM1/20/20
to Google Ads Scripts Forum
It seems you haven't specified yet that you only wish campaigns that already have the label applied - your aim could also be to apply the label.

Try adding a .withcondition() to your campaignIterator where your specify that you only wish to have campaigns with said label returned

 sigurd

Google Ads Scripts Forum Advisor

unread,
Jan 20, 2020, 2:06:47 AM1/20/20
to adwords...@googlegroups.com
Hi Sigurd,

Thanks for your suggestion. However, I am afraid that this script will get and log only the campaigns who has the 'Christmas promotions' label applied to it. The reason is that Louis have filtered the label with '.withCondition('Name = "Christmas promotions"')' and access the campaigns using the campaigns() method. With this explanation, it is not needed to add '.withcondition()' to the campaignIterator.

Hi Louis,

Thanks for posting your concern.

Upon checking the script, I can see that it should indeed return only all the campaigns associated with the 'Christmas promotions' label. With this, so that I can further investigate, could you provide the customer ID and the name of script where you encountered the issue? You can provide the requested information via Reply privately to author option?

Regards,
Ejay
Google Ads Scripts Team

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