Bidding script for top impression share

301 views
Skip to first unread message

YAN

unread,
Sep 24, 2019, 7:30:15 AM9/24/19
to Google Ads Scripts Forum
Hi, I am using a script to bid to a position. But since the average position is on a way out. I want to modify my script to use the new metrics "impr. top %" and "abs top impr. %".

Please help guys.

the script I am using looks like this.

// what position are you trying to achieve?
var TARGET_AVERAGE_POSITION = 2.5;

/**** UPDATE !!! ****/
// 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?
/**** UPDATE !!! ****/
var BID_ADJUSTMENT_COEFFICIENT = 1.05;

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

function raiseKeywordBids() {
 
// adjust this condition!
 
var keywordsToRaise = AdWordsApp.keywords()
   
.withCondition("Ctr > 0.01")
   
.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() {
 
// adjust this condition!
 
var keywordsToLower = AdWordsApp.keywords()
   
.withCondition("AveragePosition < " + (TARGET_AVERAGE_POSITION - TOLERANCE))
   
.withCondition("Status = ENABLED")
   
.orderBy("AveragePosition DESC")
   
.forDateRange("LAST_7_DAYS")
   
.get();
   
 
 
while (keywordsToLower.hasNext()) {
   
var keyword = keywordsToLower.next();
    keyword
.setMaxCpc(keyword.getMaxCpc() / BID_ADJUSTMENT_COEFFICIENT);
 
}
}

Google Ads Scripts Forum Advisor

unread,
Sep 24, 2019, 1:48:02 PM9/24/19
to adwords-scripts+apn2wqczzj3cza3o...@googlegroups.com, adwords-scripts+apn2wqczzj3cza3o...@googlegroups.co, adwords...@googlegroups.com
Hello,

Top impression percentage is not available at the moment through the withCondition method. You can get keywords with the top impression percentage metric using reports, however. For example:

  var ids = [ ]; //Empty array that you will contain filtered keyword IDs and ad group IDs for keyword selector
  
  var report = AdsApp.report(    
    "SELECT AdGroupId, Id " +
    "FROM KEYWORDS_PERFORMANCE_REPORT " +
    "WHERE Ctr > .01 " +
    "AND Status = ENABLED " +
    "AND TopImpressionPercentage > .5 " + //Sample value
    "DURING LAST_7_DAYS "    
    );
  
  var rows = report.rows();
  
  while(rows.hasNext()) {
    var row = rows.next();
    var adGroupId = row['AdGroupId'];
    var keywordId = row['Id'];
    ids.push( [adGroupId, keywordId] ); 
  }
  
  var keywordIterator = AdsApp.keywords().withIds(ids).get();

Note that the keyword selector method, withIds, requires both an ad group ID and keyword ID because keyword IDs are not unique.

Regards,
Matt
Google Ads Scripts Team

ref:_00D1U1174p._5001UHHl65:ref

YAN

unread,
Sep 25, 2019, 5:04:12 AM9/25/19
to Google Ads Scripts Forum
Hello Matt, 

Thank you for your reply. 

I will be very grateful if you could help me with the look of the whole script as you're the expert and I will benefit from your advice. The point of my script is to increase bids if TopImpressionPercentage is lower than 60% and lower bids if  AbsoluteTopImpressionPercentage is higher than 25%

Please help!

Regards
Yan

Message has been deleted

Google Ads Scripts Forum Advisor

unread,
Sep 25, 2019, 2:30:30 PM9/25/19
to adwords...@googlegroups.com, adwords-scripts+apn2wqczzj3cza3o...@googlegroups.com, adwords-scripts+apn2wqczzj3cza3o...@googlegroups.co
Hi Yan,

Please note that this channel is for developer support rather than custom script implementations. The script is pretty much the same as yours below except the portion I wrote will replace your keyword iterator:
  var keywordsToRaise = AdWordsApp.keywords()
    .withCondition("Ctr > 0.01")
    .withCondition("Status = ENABLED")
    .withCondition("AveragePosition > " + (TARGET_AVERAGE_POSITION + TOLERANCE))
    .orderBy("AveragePosition ASC")
    .forDateRange("LAST_7_DAYS")
    .get();

Note that I named the iterator 'keywordIterator', whereas your script names the iterators 'keywordsToRaise' and 'keywordsToLower'. Additionally, you need to input your top impression percentage of choice (I cannot decide this).


Regards,
Matt
Google Ads Scripts Team
 

 



ref:_00D1U1174p._5001UHHl65:ref

YAN

unread,
Sep 28, 2019, 4:16:04 PM9/28/19
to Google Ads Scripts Forum

Thank you so much, everything works as it should. I just have one last question. In one of the scripts, I want to set MaxCpc > 2, so all keywords below 2 don't change.
I was using .withCondition("MaxCpc > 2").
How could I include this in the new script?

Google Ads Scripts Forum Advisor

unread,
Sep 30, 2019, 1:11:28 PM9/30/19
to adwords-scripts+apn2wqczzj3cza3o...@googlegroups.com, adwords-scripts+apn2wqczzj3cza3o...@googlegroups.co, adwords...@googlegroups.com
Hello,

You can chain the withIds and withCondition methods on your keyword iterator. You can simply reinsert the max CPC condition back into the iterator:

  var keywordIterator = AdsApp.keywords().withCondition("MaxCpc > 2").withIds(ids).get();


Regards,
Matt
Google Ads Scripts Team

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