How to bid position by label name?

209 views
Skip to first unread message

Peter Vretenička

unread,
Oct 18, 2017, 7:30:05 AM10/18/17
to AdWords Scripts Forum
Please how should I adjust this script, when I need to bid the position only for Keywords, that have labels named ,,bid2":

// Copyright 2015, Google Inc. All Rights Reserved.

//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
 * @name Bid To Position
 *
 * @overview The Bid To Position script adjusts your bids and allows you to
 *     steer ads in an advertiser account into a desired position in the search
 *     results. See
 *     https://developers.google.com/adwords/scripts/docs/solutions/bid-to-position
 *     for more details.
 *
 * @author AdWords Scripts Team [adwords...@googlegroups.com]
 *
 * @version 1.0.1
 *
 * @changelog
 * - version 1.0.1
 *   - Refactored to improve readability. Added documentation.
 * - version 1.0
 *   - Released initial version.
 */


// 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;

/**
 * Main function that lowers and raises keywords' CPC to move closer to
 * target position.
 */

function main() {
  raiseKeywordBids
();
  lowerKeywordBids
();
}

/**
 * Increases the CPC of keywords that are below the target position.
 */

function raiseKeywordBids() {
 
var keywordsToRaise = getKeywordsToRaise();

 
while (keywordsToRaise.hasNext()) {
   
var keyword = keywordsToRaise.next();
    keyword
.bidding().setCpc(getIncreasedCpc(keyword.bidding().getCpc()));
 
}
}

/**
 * Decreases the CPC of keywords that are above the target position.
 */

function lowerKeywordBids() {
 
var keywordsToLower = getKeywordsToLower();

 
while (keywordsToLower.hasNext()) {
   
var keyword = keywordsToLower.next();
    keyword
.bidding().setCpc(getDecreasedCpc(keyword.bidding().getCpc()));
 
}
}

/**
 * Increases a given CPC using the bid adjustment coefficient.
 * @param {number} cpc - the CPC to increase
 * @return {number} the new CPC
 */

function getIncreasedCpc(cpc) {
 
return cpc * BID_ADJUSTMENT_COEFFICIENT;
}

/**
 * Decreases a given CPC using the bid adjustment coefficient.
 * @param {number} cpc - the CPC to decrease
 * @return {number} the new CPC
 */

function getDecreasedCpc(cpc) {
 
return cpc / BID_ADJUSTMENT_COEFFICIENT;
}

/**
 * Gets an iterator of the keywords that need to have their CPC raised.
 * @return {Iterator} an iterator of the keywords
 */

function getKeywordsToRaise() {
 
// Condition to raise bid: Average position is greater (worse) than
 
// target + tolerance
 
return AdWordsApp.keywords()
     
.withCondition('Status = ENABLED')
     
.withCondition(
         
'AveragePosition > ' + (TARGET_AVERAGE_POSITION + TOLERANCE))
     
.orderBy('AveragePosition ASC')
     
.forDateRange('LAST_7_DAYS')
     
.get();
}

/**
 * Gets an iterator of the keywords that need to have their CPC lowered.
 * @return {Iterator} an iterator of the keywords
 */

function getKeywordsToLower() {
 
// Conditions to lower bid: Ctr greater than 1% AND
 
// average position better (less) than target - tolerance
 
return AdWordsApp.keywords()
     
.withCondition('Ctr > 0.01')
     
.withCondition(
         
'AveragePosition < ' + (TARGET_AVERAGE_POSITION - TOLERANCE))
     
.withCondition('Status = ENABLED')
     
.orderBy('AveragePosition DESC')
     
.forDateRange('LAST_7_DAYS')
     
.get();
}

Sven Reinhardt

unread,
Oct 18, 2017, 7:42:54 AM10/18/17
to AdWords Scripts Forum
Hi Peter,

just add
.withCondition("LabelNames CONTAINS_ANY ['bid2']")
after each

return AdWordsApp.keywords()
see also: https://developers.google.com/adwords/scripts/docs/reference/adwordsapp/adwordsapp_keywordselector

hth,
sven

Anthony Madrigal

unread,
Oct 18, 2017, 9:35:59 AM10/18/17
to AdWords Scripts Forum
Hi Peter,

Sven's suggestion should work for you. Please let me know if you face any issues.

Cheers,
Anthony
AdWords Scripts Team

Peter Vretenička

unread,
Oct 20, 2017, 7:53:02 AM10/20/17
to AdWords Scripts Forum
Thank you very much. 

At the moment the script does the bidding by labels that are asigned to each key word. Is there a way to make it bid by labels (asigned to each key word)  on the level of advertising groups?

Anthony Madrigal

unread,
Oct 20, 2017, 9:18:07 AM10/20/17
to AdWords Scripts Forum
Hi Peter,

You can make the following changes to the functions getKeywordsToRaise and getKeywordsToLower
/**
 * Gets an iterator of the keywords that need to have their CPC raised.
 * @return {Iterator} an iterator of the keywords
 */

function getKeywordsToRaise() {
 
// Condition to raise bid: Average position is greater (worse) than
 
// target + tolerance

 
var adGroupIds = [];
 
var adGroups = AdWordsApp.adGroups().withCondition("LabelNames CONTAINS_ANY ['label 1', 'label2']").get();
 
while(adGroups.hasNext()){
    adGroupIds
.push(adGroups.next().getId());

 
}
 
return AdWordsApp.keywords()
     
.withCondition('Status = ENABLED')

     
.withCondition('AdGroupId IN [' + adGroupIds + ']')

     
.withCondition(
         
'AveragePosition > ' + (TARGET_AVERAGE_POSITION + TOLERANCE))
     
.orderBy('AveragePosition ASC')
     
.forDateRange('LAST_7_DAYS')
     
.get();
}


/**
 * Gets an iterator of the keywords that need to have their CPC lowered.
 * @return {Iterator} an iterator of the keywords
 */

function getKeywordsToLower() {
 
// Conditions to lower bid: Ctr greater than 1% AND
 
// average position better (less) than target - tolerance

 
var adGroupIds = [];
 
var adGroups = AdWordsApp.adGroups().withCondition("LabelNames CONTAINS_ANY ['label 1', 'label2']").get();
 
while(adGroups.hasNext()){
    adGroupIds
.push(adGroups.next().getId());

 
}
 
return AdWordsApp.keywords()
     
.withCondition('Ctr > 0.01')
     
.withCondition(
         
'AveragePosition < ' + (TARGET_AVERAGE_POSITION - TOLERANCE))
     
.withCondition('Status = ENABLED')

     
.withCondition('AdGroupId IN [' + adGroupIds + ']')

     
.orderBy('AveragePosition DESC')
     
.forDateRange('LAST_7_DAYS')
     
.get();
}

This will give you keywords whose ad groups have any of those labels. You can combine this with Sven's response to also include labels assigned to keywords.

Cheers,
Anthony
AdWords Scripts Team

Reply all
Reply to author
Forward
0 new messages