Facebook Pixel
Join our Facebook Community

How to Split Test (A/B Test) Your AdSense Ads

Posted By Darren Rowse 16th of May 2008 Adsense 0 Comments

A couple of days ago I talked readers through some different approaches to AdSense Ad Design and how it can make a significant impact upon the earnings of your AdSense ads. At the end of the post I mentioned that one great way to work out which ad design is best for your blog is to run a split testing campaign.

Today I want to talk readers through how to do this – it’s not as complicated as you might think!

What is Split Testing?

Also sometimes called A/B testing, split testing means that you run two different versions of an AdSense ad unit on your blog so that you can see which one performs best. You serve one version of the ad to one visitor, and then another version to the next visitor.

If you do this over a large number of visitors you’ll get a bit enough sample to be able to draw some conclusions about which ad design works best in that particular ad position.

How to Run a Split Test on Your AdSense Ads

Split testing sounds complicated but it is relatively simple to set up. In short, all it really involves is setting up a couple of channels within your AdSense account so that you can track the results and then inserting a little extra code around the AdSense code in your blog’s templates. Here’s how:

1. set up two different custom channels in your AdSense account. They might be called something like ‘test A’ and ‘test B’.

2. generate two different ad units in the back end of your AdSense account. Make them identical sized formats but give them two different color palettes. Copy the codes AdSense gives you and put them into a text document – you’ll need them in a minute.

3. take the following code insert the two ad units codes that you just generated into it were it indicates:

<script type=”text/javascript”>
    var random_number = Math.random();
    if (random_number < .5){
        //your first ad unit code goes here
    } else {
        //your second ad unit code goes here
<script type=”text/javascript”     src=”http://pagead2.googlesyndication.com/pagead/show_ads.js”></script>

ie – you need to replace the bolded lines with your two different AdSense codes.

4. Insert everything into your blog’s template in the appropriate spot for the ad to make it position where you want it to show.

With the above code you should now see the two different color palettes rotating on your blog. It will show one 50% of the time and the other the other 50% of impressions.

You can then log into your AdSense reports area after the script has been rotating for a while to see which one is performing best. Give it a day or two to run before you make too many changes as it can take a little while to get the ad having shown enough times to draw any solid conclusions.

Variations on the Test

You can do the same split test to work out what Ad Unit Size is converting best. The process is identical but instead of having your two ad units with different colors make the only variation their sizes (ie keep the colors the same).

You could also test any other element that you have control over. For example the different corner options, image ads vs text ads etc.

Lastly – you don’t have to make the split test a 50/50 one. You could specify for one ad unit to show up 95% of the time and the other only 5%. This means only a small number of your readers see the new ad unit (good if you’re testing something bold). To do this simply vary the “.5” to another number. For example .9 would show one ad 90% of the time.

Final Tips

  • Backup your templates before experimenting. If you mess it up somehow you can then quickly revert to your original setup.
  • Make one of the ads you rotate one that you’ve been testing for a while so as to give a good baseline result to compare to.
  • Don’t experiment with multiple changes at once. For example if you test ad size and colors at once you won’t be able to identify the specific element that cases the changes in ad performance.
  • Once you’ve worked out which of your two ad units performs best keep testing with other options. Take your best performing one and test that against other designs to see if you can find one to better it. Once you do use that one as your baseline!
About Darren Rowse
Darren Rowse is the founder and editor of ProBlogger Blog Tips and Digital Photography School. Learn more about him here and connect with him on Twitter, Facebook and LinkedIn.
  1. Wow great tip , But I guess to test this successfully you need to have considerable amount of traffic.

  2. Darren,

    Great idea as always. It’s not every day we see you being a coder.

    Thanks for the tip. When I get to the point were I have a big enough user base to test this out, I will be sure to give it a try.

  3. This is awesome! I was looking for a way to do this on one of my sites, so that I didn’t have to change the ads and then wait a few days for the results, and then change them again and wait for more results. This way I can have it going on simultaneously with no additional effort or time delay.

    Great post!

  4. I find it surprising that some bloggers find this neat feature a bit daunting task when it’s so easy to implement it.

    Even if it requires a little extra effort when done right, it will yield valuable results that would surely improve AdSense earnings.

  5. Why not call your adsense ads through a PHP include: that way you just have to change the included PHP file anytime you want to add another ad into your rotation instead of updating all your templates and rebuilding your whole site.

  6. Nice, simple explanation, definitely think I’ll give it a go on one of my sites. It’s something that’s been niggling me for a while and you’ve given me the incentive to try.

    Something so simple could show immediate, quantifiable dividends. Thanks!

  7. If you want to see an example of split testing with PHP you can see my post on my blog.

    I did a comparison of the 250×250 ads and the 300×250 ad blocks. I posted my results. There was a HUGE difference between the two.

  8. I like your blog! You have help me to increase the users to my blog. Thank you very much and compliments! :)

  9. A great idea would be that if you a blog or web site that has like a slideshow of photos, you could use 4 types of Ads and with every page impression the Ad would change and this would catch the readers eye because the colors would be changing.

  10. This is worth looking at before checking out the rotating ads option that you mentioned the other day.

    Find the best option(s) and then use that with the rotation of the ads

  11. Great post Darren. I’ve been wanting to do this on my site for some time but haven’t gotten around to do it. Now that I have step by step instructions I have no excuse to give it a go.

    @ ShinyPlastic – That seems like a good idea. How would you go about doing that?

  12. As usual I’m off to implement. The post seems to have so many ideas popping out of my brain, I’ll have to read it again. I’ll be back with my results some time. Thanks alot.

  13. Great information, Darren! I didn’t even know that you could do that. I will have to try to give it a shot at some point. Maybe test text ads against image ads..

  14. Great way of doing this! I’ve been looking for a mechanism to set this up and am glad you took the time to share this script with us. Also, the series is great as I’ve about given up on AdSense and am now willing to give them another, more formal, trial.

    I’ve screwed something up in that only the } else { is being displayed instead of the ads. Is it an issue with extra spaces between the “{” and the AdSense code?

  15. I like the idea of testing ads and site wide ad formats, this has certainly been a good post.

    Cheers now!

  16. Darren: Where do you place adsense ads on this site? I don’t see any.

  17. As suggested, a PHP include is useful for this type of stuff.

    For those not afraid to get their hands a little dirty …

    adding code like this:

    if (date(“w”)%2

    will split test your Adsense code by DAY.

    Not sure if this code will show up in the comments correctly, the important part is the “if” statement – (date(“w”)%2 < 1) – which says to show “Google Adsense #1 goes here” if today is an even numbered day, 0 (for Sunday) through 6 (for Saturday); otherwise show “Google Adsense #2 goes here”.

    You can get even fancier and split by whatever time frame you want – year, month, week, hour, minute, second, etc – or a combination.


  18. I’m getting the same problem… would someone be willing to post an example (with pub ID blocked)… Thanks!

  19. Great Post! I’ve been trying to figure out how to do this for weeks. I’m going to do this to practically every unit on my site. Now I can find out which are the best units for every ad placing on my blog incredibly fast.

    After knowing this can you imagine putting and AdSense unit up for a week, then manually changing it. Then doing the same process over for every page, post, and every other place one might place an ad in? Omg you’ve saved me a hundred headaches. Thanks Darren, really good info.

  20. If you have the “Who Sees Ads” WordPress Plugin (and you should, it’s easily the most useful plugin I have), it’s easy to set up an A/B comparison (or just randomize ads) with the “ROTATE AD” feature. You can even combine this with some of Who Sees Ads other features, so that for example you could keep an ad static if it’s someone coming from a search engine. but rotate it if it’s a regular visitor.


  21. Great post Darren. I will try to do it on my website! Keep it coming

  22. Thank you Darren…Love the adsense series you are writing. I haven’t yet implemented all the changes you mentioned…I will be doing that next week…This series is a valuable ‘ad sense book’.

  23. Awesome idea, this is definitely something that I will try in the next few weeks!

  24. Norm – I don’t use AdSense on this blog. I do use it on my other ones though.

    Check out this video on why it doesn’t work at ProBlogger.

  25. Interesting concept and will definitely give it a go as soon as I fix the feedburner issues I have with my new blog.

    Fighting with Cpanel etc. Newbie here.

  26. Wow that’s great advice, I’ve manually tested a few different setups so this will definitely help a lot.

  27. That is possibly the most useful thing I’ve read in a very long time. Thanks Darren!

  28. Darren,

    First of all, thanks so much for doing this. I’d love to see you put up more posts on coding.

    Also, thanks for focusing on Javascript, which can be used by Typepad bloggers like me, rather than PHP.

    BTW, I can’t see any ‘bolded” lines in the code in FireFox.

    Finally, I’m looking for a way to rotate Amazon ads. I tried dropping them in using this approach, but it didn’t work. Anyone have any ideas?

  29. Very Good post Darren. I will use this to test what of my ads is better for me. When I get some clicks :(

  30. Excellent! Can’t say much more than that, very practical and useful. Will put into effect immediately.

  31. Good point made with the article. Is there a way to target specific ads? Honestly, I have an information site about Trojan Condoms but I get ads that are half for virus trojan removal… I use Adware and am new to this. Any suggestions?

  32. Fantastic tip, thanks Darren!

  33. I’m afraid. Is it against adsense TOS?

  34. Great tips here! Thanks for them :-)

  35. @ HAK & Alex:

    I had the same problem with the } else { showing and the ad not rotating, but I figured it out this morning.

    If you leave out the on your ads, and just put in what’s between (and including) the “” then no closing , it works fine.

    var random_number = Math.random();
    if (random_number < .5){
    //your first ad unit code goes here
    } else {
    //your second ad unit code goes here

    Good luck, and thanks for sharing Darren!!

  36. Aaron,

    Most of the HTML you put in your comment was removed. I’m having problems getting the AdSense code to rotate too.

  37. It did get kinda mangled didn’t it? I should have noticed when I posted. I’ve pasted it all in a text file for you, and put it up at one of my sites. Hopefully, that’s OK. http://www.digital-tv-converter.info/ad.txt

  38. This is really great. I’m going to test my site to see which color format works best. I’m sure that I will find out if it’s better for my ads to stand out a little or blend in completely…

  39. Darren, does this javascript work for blogger?

    I get the following message while editing my template source.

    Your template could not be parsed as it is not well-formed. Please make sure all XML elements are closed properly.
    XML error message: Open quote is expected for attribute “{1}” associated with an element type “type”.


A Practical Podcast… to Help You Build a Better Blog

The ProBlogger Podcast

A Practical Podcast…