AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

Ads
2K members online now
2K members online now
Dive into advanced features like Remarketing, Flexible Bid Strategies, AdWords Editor, and AdWords Scripts
Guide Me
star_border
Reply

SCRIPTING - CampaignName CONTAINS_ANY problems

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hi

-

Im trying to adjust this code below so that it only operates on a list of named campaigns.

 

it seems CampaignName doesnt support 'CONTAINS_ANY' ?

    .withCondition("CampaignName CONTAINS_ANY ['Xmas', '07PRODVIS']")

 

This works as expected.
    .withCondition("CampaignName CONTAINS_IGNORE_CASE '07PRODVIS'")

 

But if I try and pass in the variable it doesnt work
    .withCondition("CampaignName CONTAINS_IGNORE_CASE NAMEZ")

 

please see below

thanks

Tom

 

// Ad position you are trying to achieve.
var TARGET_AVERAGE_POSITION = 3;

// Once the keywords fall within TOLERANCE of TARGET_AVERAGE_POSITION,
// their bids will no longer be adjusted.
var TOLERANCE = 0.1;

// How much to adjust the bids.
var BID_ADJUSTMENT_COEFFICIENT = 1.05;

function main() {
  //raiseKeywordBids();
  var POOZ = "07PRODVIS";
  lowerKeywordBids('07PRODVIS');
}

function raiseKeywordBids() {
  // Condition to raise bid: Average position is below target - tolerance
  var keywordsToRaise = AdWordsApp.keywords()
    .withCondition("Status = ENABLED")
    .withCondition("AveragePosition < " + (TARGET_AVERAGE_POSITION - TOLERANCE))
    .orderBy("AveragePosition ASC")
    .forDateRange("LAST_7_DAYS")
    .get();

  while (keywordsToRaise.hasNext()) {
    var keyword = keywordsToRaise.next();
    keyword.setMaxCpc(keyword.getMaxCpc() * BID_ADJUSTMENT_COEFFICIENT);
  }
}

function lowerKeywordBids(name) {
  var NAMEZ=name;
  // Conditions to lower bid: Ctr greater than 0.1% AND
  // average position above target + tolerance
  var keywordsToLower = AdWordsApp.keywords()
    //.withCondition("CampaignName CONTAINS_ANY ['Xmas', '07PRODVIS']")
    //.withCondition("CampaignName CONTAINS_IGNORE_CASE '07PRODVIS'")
    .withCondition("CampaignName CONTAINS_IGNORE_CASE NAMEZ")
    .withCondition("Ctr > 0.001")
    .withCondition("AveragePosition > " + (TARGET_AVERAGE_POSITION + TOLERANCE))
    .withCondition("Status = ENABLED")
    .orderBy("AveragePosition DESC")
    .forDateRange("LAST_7_DAYS")
    .get();

  Logger.log(NAMEZ);

  while (keywordsToLower.hasNext()) {
    var keyword = keywordsToLower.next();
    keyword.setMaxCpc(keyword.getMaxCpc() / BID_ADJUSTMENT_COEFFICIENT);
  }
}

1 Expert replyverified_user

Re: SCRIPTING - CampaignName CONTAINS_ANY problems

Visitor ✭ ✭ ✭
# 2
Visitor ✭ ✭ ✭

this line doesn act as expected either

 

    .withCondition("CampaignName CONTAINS_IGNORE_CASE '07PRODVIS'" || "CampaignName CONTAINS_IGNORE_CASE '09CORP_ANIM'")

 

Id like that to return a '1' for either of those 2 campaign names, but it seems it only takes the first one there into consideration,

Re: SCRIPTING - CampaignName CONTAINS_ANY problems

Top Contributor
# 3
Top Contributor

Hi Ross, there's two solutions here:

 

Firstly, the problem with using variables in the Conditions is all about the quotes...  To use a variable in a Condition you'll need to ensure the variable is replaced with its value on runtime so in this case your line would look like:

 

.withCondition("CampaignName CONTAINS '" + NAMEZ + "'")

 

it's not easy to see here but there's a single quote before the double-quote after CONTAINS and another one between the double-quote pair at the end.

 

You cannot use CONTAINS_ANY with Campaign Names as this operator can only be applied to StringSet objects such as Labels.  So to choose any number of Campaigns you'll either need to use a common naming convention, or Labels.

 

For example, if you wanted to select all the Campaigns selling shoes, you could make sure the Campaign name contained "shoes" somewhere, e.g.

 

searchShoesCanada

searchShoesUSA

 

then use the withCondition

 

.withCondition("CampaignName CONTAINS 'Shoes'")

 

which would select both these Campaigns.  Or you could Label these Campaigns with a Label such as "Shoe Campaigns" then use the withCondition

 

.withCondition("LabelNames CONTAINS_ANY ['Shoe Campaigns']")

 

Using Labels could be more useful as this allows you more freedom with your Campaign naming, and also does allow the use of CONTAINS_ANY, etc.  So if you wanted to select both shoe & boot Campaigns, you could use two Labels and then use CONTAINS_ANY to select both.


Does this help?

 

Jon

AdWords Top Contributor Google+ Profile | Partner Profile | AdWords Audits

Re: SCRIPTING - CampaignName CONTAINS_ANY problems

Visitor ✭ ✭ ✭
# 4
Visitor ✭ ✭ ✭

Hi

thanks Jon, your new Syntax works great to use the variable.

I couldnt find examples like that in the docs.

I have this working lovely now

Best

Tom