Monetizing a blog: Rotate Adsense ads with 5 lines of php

So, to test the often stated advantage of text ads versus image ads I did set up two skyscrapers (160×600) and use the following code to randomly (should be 50/50 in the long run) show them.

In the sidebar.php of the WordPress Appearance Editor I added this code where formally my normal AdSense code took place:

<?php
$random = rand(0,1);
if ( $random == 0 ) { ?>
//AdSenseCode goes here
<?php } else { ?>
//AdSenseCode goes here
<?php }  ?>
$random = rand (0,1);
a variable named $random becomes a random integer between (including) zero and one
if ( $random == 0 ) {
checks if the variable is equal to zero and delivers ad code 1
} else {
delivers ad code 2 if the statement above was not true

I hope there is some useful information in that for all you profit miximizers. I’ll check out the numbers for at least on month. That should be enough time to first of all show the distribution of text ad and image ad (in number of views) and their success (in number of clicks). Needing numbers for this experiment is no encouragement for you to click, I know you are all self empowered and just curious.

To verify that it works I added the random number which you can find right below the ad. If there is no ad and instead just white space means that there is no image ad available at the moment.

I be tellin’ ya all t’ stories. Yoho!

EDIT: The results are in that post.

More articles in banner rotation with php:

This entry was posted in blog, monetization, PHP and tagged , , , , . Bookmark the permalink.
Be Sociable, Share!

One Response to Monetizing a blog: Rotate Adsense ads with 5 lines of php

  1. Pingback: Monetizing a blog: Rotate Adsense ads with 5 lines of php – Part II « LÞ kegogrog blog

Leave a Reply

Your email address will not be published.