Skip to content


Google Adsense – How to randomize theme

A few conversations about changing and ad placement to help prevent banner blindness has led to me to create this simple script to automatically randomize a Google AdSense block. This is a extremely easy script that uses a array of values, randomizes the index and puts the values into the AdSense block. This could be modified to include random ad formats as well as optionally including Video units, etc.

I’ve rolled this out on one of my sites to see what ad format color scheme might be the best. I’m tracking results by providing a channel to see what gets good clicks and what themes do not.

<?php
$pubID                                  = ‘pub-0000000000000001′;
$width                                  = 120;
$height                                 = 240;
$adFormat                               = ‘120×240_as’;
$adType                                 = ‘text’;
$adArray                                = array();
$adArray[0][‘bc’]               = ‘FCFCFC’;
$adArray[0][‘bg’]               = ‘286EA0′;
$adArray[0][‘link’]             = ‘286EA0′;
$adArray[0][‘text’]             = ‘E6E6E6′;
$adArray[0][‘url’]              = ‘FFFFCC’;
$adArray[0][‘channel’]  = ‘blue’;
$adArray[0][‘misc’]             = ‘rc:6′;

$adArray[1][‘bc’]               = ‘FFFF66′;
$adArray[1][‘bg’]               = ‘FFCC66′;
$adArray[1][‘link’]             = ‘FFFFFF’;
$adArray[1][‘text’]             = ‘000000′;
$adArray[1][‘url’]              = ‘FFFFFF’;
$adArray[1][‘channel’]  = ‘yellow’;
$adArray[1][‘misc’]             = ‘rc:10′;

$adArray[2][‘bc’]               = ‘FFFF66′;
$adArray[2][‘bg’]               = ‘CC0000′;
$adArray[2][‘link’]             = ‘FFFFFF’;
$adArray[2][‘text’]             = ‘000000′;
$adArray[2][‘url’]              = ‘FFFFCC’;
$adArray[2][‘channel’]  = ‘red’;
$adArray[2][‘misc’]             = ;
$index                                  = rand(0, sizeof($adArray)1);?>
<script type="text/javascript"><!–
        google_ad_client = "<?=$pubID?>";
        google_ad_width = <?=$width?>;
        google_ad_height = <?=$height?>;
        google_ad_format = "<?=$adFormat?>";
        google_ad_type = "<?=$adType?>";
        google_ad_channel = "";
        google_color_border = "<?=$adArray[$index]['bc']?>";
        google_color_bg = "<?=$adArray[$index]['bg']?>";
        google_color_link = "<?=$adArray[$index]['link']?>";
        google_color_text = "<?=$adArray[$index]['text']?>";
        google_color_url = "<?=$adArray[$index]['url']?>";
        <?if(strlen(trim($adArray[$index][‘misc’])) > 0){?>
        google_ui_features = "<?=$adArray[$index]['misc']?>";
        <?}?>
//–>
</script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<?unset($adArray);?>
 



Related posts:

  1. Monetizing your site with Google Video Units (AdSense)
  2. Google AdSense with affiliate store front (Good || Bad)?
  3. Commission Junction, Banners or Google AdSense?
  4. Shoemoney’s Google Adsense Check
  5. WidgetBucks and Google

Posted in Affiliate Marketing, Programming.

Tagged with , , , .


2 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Suzanne of New Affiliate Discoveries says

    Wow, great idea and nice clean script.

    Dugg the post!

  2. admin says

    Thanks! I need to do some additional testing, no real interesting results as of yet, but that’s because I’m testing on a low traffic site. Planning on testing with a site with a bit more traffic.



Some HTML is OK

or, reply to this post via trackback.

Powered by WP Hashcash