How to add minBid and maxBid?

42 views
Skip to first unread message

Peter Vretenička

unread,
Feb 20, 2018, 6:02:13 AM2/20/18
to AdWords Scripts Forum
Hello AdWords Scripts Team,

please how to add minBid and maxBid to this script?

var TARGET_AVERAGE_POSITION = 2.5;

var TOLERANCE = 0.1;

var BID_ADJUSTMENT_COEFFICIENT = 1.1;

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

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

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

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

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

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

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

function getKeywordsToRaise() {

  var adGroupIds = [];
  var adGroups = AdWordsApp.adGroups().withCondition("LabelNames CONTAINS_ANY ['bid-to-2.5']").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();
}


function getKeywordsToLower() {
 
  var adGroupIds = [];
  var adGroups = AdWordsApp.adGroups().withCondition("LabelNames CONTAINS_ANY ['bid-to-2.5']").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();
}

Adrian Catambay (AdWords Scripts Team)

unread,
Feb 20, 2018, 6:22:53 AM2/20/18
to AdWords Scripts Forum
Hello Peter,

Could you please further elaborate how you would like the minBid and maxBid to be used in the script you posted so I could provide you with proper recommendations? What would be the purpose of minBid and maxBid in the functioning of the script?

Thanks,
Adrian
AdWords Scripts Team

Peter Vretenička

unread,
Feb 20, 2018, 7:01:10 AM2/20/18
to AdWords Scripts Forum
The purpose of minBid and maxBid should be the option to set the minimal and maximal values cpc.


Dňa utorok, 20. februára 2018 12:22:53 UTC+1 Adrian Catambay (AdWords Scripts Team) napísal(-a):

Adrian Catambay (AdWords Scripts Team)

unread,
Feb 20, 2018, 9:39:48 AM2/20/18
to AdWords Scripts Forum
Hello Peter,

Based on my understanding, you want minBid and maxBid to serve as limits for the new Cpc to be set in raiseKeywordBids() and lowerKeywordBids() functions. If my understanding is correct then you may add new variables minBid and maxBid on your script like in the sample code below:
var minBid = YOUR_MIN_CPC_BID_HERE;
var maxBid = YOUR_MAX_CPC_BID_HERE;

then I would aslo suggest that you modify the getIncreasedCpc() function at line 30 from:
function getIncreasedCpc(cpc) {
   
return cpc * BID_ADJUSTMENT_COEFFICIENT;
}
to the following sample code below:
function getIncreasedCpc(cpc) {
   
var res = cpc * BID_ADJUSTMENT_COEFFICIENT;
   
if (res < minBid) { // check if the result of the increased CPC is less than the minimum bid. If true then return minBid
       
return minBid
   
} else if (res > maxBid) { // check if the result of the increased CPC is greater than the maximum bid. If true then return maxBid
       
return maxbid
   
}
   
return res; // return the default computation
}

and the getDecreasedCpc() function at line 34 from:
function getDecreasedCpc(cpc) {
   
return cpc / BID_ADJUSTMENT_COEFFICIENT;
}
to the following sample code below:
function getDecreasedCpc(cpc) {
   
var res = cpc / BID_ADJUSTMENT_COEFFICIENT;
   
if (res < minBid) { // check if the result of the increased CPC is less than the minimum bid. If true then return minBid
       
return minBid;
   
} else if (res > maxBid) { // check if the result of the increased CPC is greater than the maximum bid. If true then return maxBid
       
return maxbid;
   
}
   
return res; // return the default computation
}

If I have misunderstood you inquiry then could you please further elaborate you requirement so that I could provide you with the proper recommendations to achieve it.
Reply all
Reply to author
Forward
0 new messages