PHP Code, SEO Optimization

Displaying and Tracking Multiple (Random) Adsense Formats

I guess this post isn't really about Search Engine Optimization, more about Adsense optimization. But I don't have a category for Adsense, and I'm not going to create one (yet) for just one post. So there is a lot of advice out there on Adsense format best practices. One of the most important tips to achieving the highest Adsense revenue is to test different ad formats. You have options to doing this. You could try one ad format for a month, then test another, and so on. But that takes a lot of time! It would take a year just to test all of the different formats! Well, I have come up with a way to test as many ad formats as you want concurrently, through random ad format displaying.

The first thing you need to do is create a channel for each Adsense ad format that you want to test. To make it easy on yourself, include the ad size in the channel name (e.g. "site 1 – 120×240"). Then copy and paste the PHP code below, and just modify the switch case below to include the formats and channel IDs that you want. That way you can track which format generated the most revenue, and stick with that one. Or, you can keep randomly switching sizes/colors, to prevent ad blindness.

By the way, you also extend this code to test color combinations, but right now I don't have enough visitors to warrant the work involved in creating 4 times the channels in adsense. Instead, I just used the 'chameleon codes'; using a array of colors for each color option, and the combinations are chosen randomly.


<div id="contentAd">
<?php
srand(time());
$random = (rand(0,3));
$width  = "300";
$height = "250";
$format = "300x250_as";
$chanel = "7439306004";

switch ($random) 
{
  case 0:
	$width  = "300";
	$height = "250";
	$format = "300x250_as";
	$chanel = ""##########";";
	break;
  case 1:
	$width  = "120";
	$height = "240";
	$format = "120x240_as";
	$chanel = ""##########";";
	break;
  case 2:
	$width  = "180";
	$height = "150";
	$format = "180x150_as";
	$chanel = ""##########";";
	break;
  case 3:
	$width  = "250";
	$height = "250";
	$format = "250x250_as";
	$chanel = "##########";
	break;
}
?>

And here's the JavaScript code to display the random Adsense ad with the format chosen:


<script type="text/javascript"><!--
google_ad_client = "pub-################";
google_ad_width = <?php echo $width; ?>;
google_ad_height = <?php echo $height; ?>;
google_ad_format = "<?php echo $format; ?>";
google_ad_type = "text_image";
google_ad_channel = "<?php echo $chanel; ?>";
google_color_border = &#91;"FFFFFF", "CCCCCC", "FF0000"&#93;;
google_color_bg = "FFFFFF";
google_color_link = &#91;"333333", "996088"&#93;;
google_color_url = &#91;"0066CC", "CC3300"&#93;;
google_color_text = &#91;"666666","000000", "CC6633"&#93;;
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>

This code is in operation on this very page that you're reading. Just hit refresh a few times, and you'll see different ads at the top!

Share

1 Comments

  1. nice idea. will give it a try. thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Anti-spam image