PHP Code to Split Test Adsense

I was just reading a post on Pro Blogger regarding How to Split Test (A/B Test) Your AdSense Ads and had a light bulb moment.

This year I have watched my Adsense earnings gradually improve to useful levels and got keener to create more opportunities to earn Adsense revenue. But it never occured to me to split test Ad Units to see which work best on my sites.

I need a slap on the head since I have been creating testing software and not applying what I already know to maximum effect on my own sites. I may have left $1000’s on the table? Like when I was slow to initially embrace Adsense a few years ago.

I think it was because Adsense uses Javascript and you aren’t allowed to alter the code that you generate in your member’s area, I didn’t think it was possible to split test the Ads automatically.

But of course it is, it is no different to editing your pages manually to try different Ad units to see which work best.

What I did within minutes of reading Darren’s post was to login to my Adsense account and check out my highest earning Ad channel. The channel is a tag that you apply to Ad units to track their performance.

This particular channel is applied to a wide 728×90 text unit which tends to show 4 Adword Ads side by side. So I am excluding the square Ads which may be a mistake.

It’s possible that the square Ads may generate more revenue due to higher higher bids and CTR. So it is worth testing this theory. Let’s see.

The 3 Ad sizes I am testing are: 728×90, 300×250 and 250×250

What I did was to generate new code for each of these Ad units with their own channel tag. So now I can randomly rotate between them and compare earnings to tell which format works best on my page.

Here is the code I wrote to randomly rotate these 3 Ads in the same position on my php page:

< ?php
$choice = rand(1,3); //Choose a random number between 1 and 3

switch ($choice) {
case 1:
?>

Javascript code for Ad format #1

< ?php
break;
case 2:
?>

Javascript code for Ad format #2

< ?php
break;
case 3:
?>

Javascript code for Ad format #3

< ?php
break;
}
?>

p.s. where you see < ?php you need to remove the space (a problem due to the code high-lighter).

Hopefully, the above code is self-explanatory and you can easily modify it to suit your needs. For example, you can cut and paste it to a PHP template file.

This should be fun. I look forward to reporting my results from this test.

Tags:

Leave a Reply

build a niche store