OR-Condition in var campaignNameContains

1,363 views
Skip to first unread message

Dom Josef

unread,
Aug 19, 2013, 9:52:48 AM8/19/13
to adwords...@googlegroups.com
Hi guys,
if I want to select more than one campain name in this variable:
var campaignNameContains = "Campaign1"
so that I have campaignNameContains = Campaign 1 or Campaign 2 or...
How can I do it? Thank you for your support. :)

naman jindal

unread,
Aug 19, 2013, 11:02:53 AM8/19/13
to adwords...@googlegroups.com
Hey Dom,

You cannot specify multiple campaigns in one variable. You can use an array for that if that helps.

If you want to specify multiple campaigns in your selecter then you can use the following operators :

 CONTAINS_ALL []  CONTAINS_ANY []  CONTAINS_NONE []

You can refer to the following link to get the more understanding on this.


If this is not what you are looking for then please specify a brief description of what you are looking to do, so that I can give you a clear idea on this.


Regards,
Naman Jindal

Dom Josef

unread,
Aug 19, 2013, 12:34:41 PM8/19/13
to adwords...@googlegroups.com
I was already afraid, that it won't be as easy but thank you. Till now I used a specific text in the campaign name. But I can't get it running with multiple specific texts. Here is my a little modified availabilty check script:

function main() {

 var options =
 {
   "muteHttpExceptions" : true
 };

//var campaignNameContains = "Campaign 1"; -> old version

 var campaignSelector = AdWordsApp
       .campaigns()
       .withCondition("campaignName CONTAINS_ANY 'Campaign 1'")
       .withCondition("campaignName CONTAINS_ANY 'Campaign 2'")

 
 var ifThisTextIsOnPageThenPauseAd = "sold out";

 var adSelector = AdWordsApp.ads()
   //.withCondition("CampaignName CONTAINS_IGNORE_CASE '" +
   //campaignNameContains.replace(/[\[\]\"]/g, "") + "'")
   .withCondition("LabelNames CONTAINS_ANY ['xxx']");//to check specific ads destination url
 
  var adIterator = adSelector.get();

 while(adIterator.hasNext()) {
   var ad = adIterator.next();
   var campaign = ad.getCampaign();
   var adGroup = ad.getAdGroup();
   var adId = ad.getId();
   var urlToTest = ad.getDestinationUrl();
   var response = UrlFetchApp.fetch(encodeURI(urlToTest), options);
   if(response != undefined) {
     var responseCode = response.getResponseCode();
     if(responseCode == 200){
       var responseText = response.getContentText();
       if(responseText != "") {
         if(responseText.indexOf(ifThisTextIsOnPageThenPauseAd) != -1) {
           Logger.log("Paused the Campaign:" + campaign);
           campaign.pause();
         } else {
           Logger.log("Activated the Campaign:" + campaign);
           campaign.enable();
         }
       }
     } else if (responseCode == 404,500) {
       Logger.log("Paused the Campaign:" + campaign + " (error)");
       campaign.pause();
     }
   }
 }
}
Now it just ignores the limitation.

naman jindal

unread,
Aug 19, 2013, 1:56:55 PM8/19/13
to adwords...@googlegroups.com
Hey Dom,

I think my previous message was not the correct solution so please ignore it. I will get back to you if I get the right way of doing that.

Regards,
Naman Jindal

Alexander Wang

unread,
Aug 20, 2013, 1:08:01 PM8/20/13
to adwords...@googlegroups.com
Hi Dom,

You should be able to use this if you know the specific campaigns you want to operate on:
AdWordsApp.campaigns().withCondition("CampaignName IN ['Campaign #1', 'Campaign #2']").get();

Naman was close, but the operators he specified are for LabelSets. It seems our documentation is not quite correct though as it would seem to suggest that you can't use the IN or NOT_IN operators for CampaignNames:

Also, we don't support OR'ing conditions. If you specify multiple conditions, they are AND'ed together. So if you want to fetch multiple campaigns via their name, I suggest using the IN, NOT_IN, CONTAINS or DOES_NOT_CONTAIN operators (though CONTAINS and DOES_NOT_CONTAIN will only match or ignore a single String as you mentioned).

Hope this helps,
Alex

Anash Oommen

unread,
Aug 21, 2013, 2:58:42 AM8/21/13
to adwords...@googlegroups.com
Hi Dom,

To add to what Alex mentioned, you can use IN operator only to do an exact name match. You cannot use it do something like "CampaignName contains "Foo" or CampaignName contains "Bar". One workaround would be to apply a label to the campaigns you are interested in, then do something like:

function main() {
 
var labelSelector = AdWordsApp.labels()
       
.withCondition("Name = 'foo'");


   
var labelIterator = labelSelector.get();
   
while (labelIterator.hasNext()) {
     
var label = labelIterator.next();
     
var campaignIterator = label.campaigns().get();
     
while (campaignIterator.hasNext()) {
       
var campaign = campaignIterator.next();
       
// Do your stuff here.
     
}
   
}
}

This way you are worried only about the relevant labels, not about name patterns in Campaigns.

Cheers,
Anash P. Oommen,
AdWords Scripts Team
Message has been deleted

Dom Josef

unread,
Aug 22, 2013, 4:49:52 AM8/22/13
to adwords...@googlegroups.com
Ok, thank you very much. I'll try the workaround with the labels. The labeling seems to get more important with every day passing by. :)
Reply all
Reply to author
Forward
0 new messages