AdSense experts have always told beginners to experiment with AdSense ads – to determine which format will perform best for their website or blog. Beginners commonly experience a very low CTR on their sites with moderate traffic. CTR, expanded as Click-through rate, is the number of clicks on ads on a website divided by the number of ad-impressions, expressed in percentage. You can perform A/B testing with Google AdSense ads to figure out the most effective ad-format with highest CTR for you.
Lets take a deeper look into A/B Testing with AdSense ads:

Say, you want to test two different formats (which differ in appearance and/or dimensions) and you are not sure which will interact better with the visitors on your website, hence gaining the CTR; you should test those two AdSense ad units using A/B Testing for a certain period of time, track their performance and finalize the best ad format for that position on your website. The idea of A/B Testing is to randomize ads on every page load, this will help us to record the performance of both ads.
How to perform A/B Testing with AdSense ads to increase CTR?
We take an example of a commonly practiced AdSense ad-placement: 336×280 ad below the post Headline. Now, you want to experiment that unit for two different colors, say blue and red, to get the best performing arrangement out of it.
- Create a 336×280 ad unit with blue-colored links (suppose this is Ad ‘A’), and assign a custom channel, say ‘blue’ to it (custom channels will help us to track the results later).
- Similarly, create another 336×280 ad unit with red-colored links (say this Ad ‘B’), assign a custom channel, say ‘red’ to it.
- Use your ad in any one of the two scripts depending on your choice:
JavaScript:
I covered the JavaScript method previously in: How to display random ads on your website?
<script type="text/javascript">
var random_number = Math.random();
if (random_number < .5){
// Ad 'A' code goes here
} else {
// Ad 'B' code goes here
}
</script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>PHP:
<?php
$random_number = rand(0, 1); ?>
<script type="text/javascript">
<?php
if($random_number < .5){ ?>
Ad 'A' code goes here
<?php } else { ?>
Ad 'A' code goes here
<?php } ?>
</script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
Place the code below post headline or wherever you want.
Correct Usage
Since modifying AdSense ads is a bit tricky process, you should use below samples to do the modifications for A/B Testing implementation. [You will need the only part after script tags (from <!-- to //-->) after generating code from AdSense].
JavaScript:
<script type="text/javascript">
var random_number = Math.random();
if (random_number < .5){
<!--
google_ad_client = "pub-xxxxxxxxxxx";
google_ad_slot = "xxxxx";
google_ad_width = 336;
google_ad_height = 280;
//-->
} else {
<!--
google_ad_client = "pub-yyyyyyyyyyyy";
google_ad_slot = "yyyyyy";
google_ad_width = 336;
google_ad_height = 280;
//-->
}
</script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
PHP:
<?php
$random_number = rand(0, 1); ?>
<script type="text/javascript">
<?php
if($random_number < .5){ ?>
<!--
google_ad_client = "pub-xxxxxxxxxxx";
google_ad_slot = "xxxxx";
google_ad_width = 336;
google_ad_height = 280;
//-->
<?php } else { ?>
<!--
google_ad_client = "pub-yyyyyyyyyyyy";
google_ad_slot = "yyyyyy";
google_ad_width = 336;
google_ad_height = 280;
//-->
<?php } ?>
</script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
People often don’t use the JavaScript method, as modifying the AdSense ad code is against Google TOS, but it is actually suggested by Adsense team itself [read more on AdSense Official blog], so you can use the JavaScript method without worries any more. People who consider loading a single ad slot at one time processed at server side, should go with the PHP snippet.
Track the results
After a certain period of time, say after 2-3 weeks (or after a full month), compare the custom channel reports in Adsense and analyze which one has the better CTR. You can finalize the related high-performing format or start a new experiment again, to get a more better results!
Also see how to improve AdSense CTR by making ads relevant.
Nice Tips. I will test the same on my blog and will bring back results.
Thanks Harry.
Fantastic! Been searching for this script for a long time! Excited to try this out. Thanks so much for this post, Rahul. Many more like this.
I think what the majority of posts these days are saying points to the same direction; average out your time looking at other aspects which affect your ranking like brand authority, social, content, rather than concentrate on the ‘traditional’ ranking factors.
Hey Rohith.
This post is not about the ranking factors or traffic building strategies. This post simply features the A/B testing of ads to know which position works well on a particular site.