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
2.4K members online now
2.4K members online now
Improve your Google Ads performance and boost your ROI, CTR, and Quality Score
Guide Me
star_border
Reply

Script: Bid adjustment according to Conversion rates

[ Edited ]
Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hey guys,


I'm looking for some kind of script that will change keywords bids according to its conversion rate.


in other words...

I'm looking for a script that will apply this formula for all the keywords in my account -> Bid = Targeted CPA * conversion rate.

any kind of help will be appreciated.

Cheers,
Gil s.

1 Expert replyverified_user

Re: Script: Bid adjustment according to Conversion rates

[ Edited ]
Top Contributor
# 2
Top Contributor

Hi @Gil U something like this should do it.  It's pretty simple, no frills, but should work.  Please Preview the script before setting it to run on a schedule, preferably daily, around 1am.  Make sure to edit the script to use your own figures at the top for TCPA, max & min CPC and how many days you want to look back to check stats.

// set bids to match CPA target
// Jon Gritton 2016

// user vars
var TCPA = 20.0;     // enter your target TCPA
var LOOKBACK = 30;    // how many days do you want to look back for stats?
var MIN_CPC = 1.0;    // lowest permitted CPC value
var MAX_CPC = 10.0;   // maximum CPC value

function main() {
  processKeywords(getDates(LOOKBACK));
}

function processKeywords(lookback) {
  // get the active Keywords
  var keyIter = AdWordsApp.keywords()
    .withCondition("CampaignStatus = ENABLED")
    .withCondition("AdGroupStatus = ENABLED")
    .withCondition("Status = ENABLED")
    .orderBy("Cost DESC")
    .forDateRange("LAST_14_DAYS")
    .get();
  
  while(keyIter.hasNext()) {
    var thisKeyword = keyIter.next();
    var thisStats = thisKeyword.getStatsFor(lookback.then,lookback.now);
    var thisConv = thisStats.getConversions();
    if(thisConv > 0) {
      var thisConvRate = thisStats.getConversionRate();
      var currCPC = thisKeyword.bidding().getCpc();
    
      // calc new CPC
      var newCPC = TCPA * thisConvRate;
    
      newCPC = (newCPC < MIN_CPC)? MIN_CPC : newCPC;
      newCPC = (newCPC > MAX_CPC)? MAX_CPC : newCPC;
    
      thisKeyword.bidding().setCpc(newCPC);
      Logger.log("Keyword: " + thisKeyword.getText() + ", Conversion Rate: " + thisConvRate + ", Current CPC: " + currCPC + ", New CPC: " + newCPC);
    }
  }
}

function getDates(duration) {
  var d = new Date(Utilities.formatDate(new Date(), AdWordsApp.currentAccount().getTimeZone(), "MMM dd,yyyy HH:mm:ss"));
  var now = Utilities.formatDate(new Date(),AdWordsApp.currentAccount().getTimeZone(), 'yyyyMMdd');
  d.setDate(d.getDate()-duration);
  var then = Utilities.formatDate(d,AdWordsApp.currentAccount().getTimeZone(), 'yyyyMMdd');
  return {now:now,then:then};
}

Jon

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