Sunday, June 03, 2012

Automatic Adsense A/B Testing + Optimization

Inspired the simple idea from  Steve Hanov’s “20 lines of code that will beat A/B testing every time” (“why didn’t I think of that” moment), I adopted the concept and implement it for Adsense.

The logic:

  • 90% of the time, it will choose the Ad with the highest CTR (click through rate)
  • 10% of the time, it will explore random Ad (based on a pre-defined sets), to determine any of these lower CTR Ad will have a chance of achieving higher CTR
  • The CTR data shall be refreshed once a day (I use the average CTR for the past 7 days)

Get the CTR data for Adsense

  • Use the Adsense Management API, particularly Reports: generate
  • Use the API explorer to test out the parameters and see the results
  • Check out the client libraries and sample code
  • To enable OAuth of offline access (e.g. Cronjob), we need to authenticate/login through web
    • $client->setAccessType('offline'); 
    • $client->setApprovalPrompt('force'); 
    • Store token in a persistent storage for offline/cronjob usage.
  • Store the average CTR for the past 7 days for each ad unit into database.

With the CTR data, the implementation seems pretty straightforward.

How it works
Let's say your are trying to see if A, B or C perform better; it will probably show the ads equally on Day 1, then it'll automatically choose the ad with highest CTR on Day 2, while keeping a 10% random ad to see if other ads eventually gains higher CTR.

No comments: