Ad Rotation Code

Here is some simple Ad Rotation code that allows you to rotate affiliate links or banners on your website to check which ones actually produce sales.

It can be tedious manually updating affiliate links and you can end up leaving non-performing Ads on your site for a long time.

This code allows you to simultaneously test many Ads.

< ?php
// Function to display a random selection of Ads

function banners() {
$n = 2; // The number of Ads to display

$ads = array( // The html code of each of the Ads
        ‘a’,
        ‘b’,

        ‘c’,
        ‘d’,
        ‘e’,

        ‘f’,
        ‘g’
);

shuffle($ads);

for ($i=0; $i<$n; $i++) echo $ads[$i];

}
?>
 

This code works in php pages such as Wordpress templates. Insert it into the wp-blog-header.php file or another included file.

Simply replace a,b,c etc. with the code for your banner ads or affiliate links. And, set the number to how many selections you want inserted on each page view. The code randomly chooses the selections each time.

Then insert the code: banners(); in your template where you want the banners/links to appear. This could be in your sidebar or header for example.

So you can now try many different Ads to check which ones actually produce sales on your site. If they all lead to the same offer then you will need to add a tracking tag to the html link. This is normally of the form: ?tag=id.

You could rotate, banners, images, and links to landing pages.

Currently I am testing a more sophisticated version of this script that weights the exposures of Ads based on their performance. This means that the Ads that get clicked show up more often. I will post more on this when the script is finalized.

- Mr MultiVar

Tags: ,

Leave a Reply

build a niche store