How to Rotate Kontera and Infolinks With Simple JavaScript and HTML

Kontera and Infolinks are two in-text advertising systems that deliver relevant ads based on the text of the webpage. Many website owners use Kontera and Infolinks in addition to other forms of advertising. Unlike traditional block advertisements, in-text links do not require any space on the sidebar. Thus, Infolinks and Kontera can help bloggers and website owners earn revenue without sacrificing page space.

There are several ways to rotate the ad code so that Infolinks are displayed part of the time, and Kontera ads are displayed the other part of the time. Some Wordpress plugins can rotate ad scripts randomly where each script has an equal chance of being displayed. However, by writing your own javascript code, you can customize the rotation so that one ad displays more frequently than the other. You can even make Infolinks appear on certain days of the week and Kontera on others. This tutorial will explain how to rotate Infolinks and Kontera ads based on different parameters. These instructions actually work with any ad code; we use Kontera and Infolinks as examples.

Rotating Ad Code With Unequal Weight/Frequency

First, login to your Kontera and Infolinks accounts to find your ad code. Next, open a blank plain text document. Copy and paste the text below into your document:

Replace the xxxxx's with your ID numbers, particular color codes, and other customizations. This script displays your Kontera code 30% of the time and your Infolinks code the other 70% of the time. You can make it 50/50 simply by replacing the 0.30 with 0.50. Save the file as "rotad.js" and upload it to your directory. You can place it in whatever folder you normally place javascripts.

Next, edit the html code of the pages where you want the in-text ads displayed. Look for the closing body tag, </body>. Right before this tag, paste the following line of code:

<script type="text/javascript" src="../..../rotad.js"></script>

Replace the ../..../ with the particular directory path that leads to the javascript file. And now you will have Infolinks and Kontera rotating on your page with a set frequency.

Rotating Ad Code Based on Day of the Week

In javascript, you can make ads display on certain days only. For example, suppose you want to display infolinks on Sundays, Mondays, and Wednesdays, and display Kontera on Tuesdays, Thursdays, Fridays, and Saturdays. Write these lines of code in your javascript file:
The command getDay fetches the current day of the week. Sunday = 0, Monday = 1,...and Saturday = 6. You can even combine day and frequency restrictions. For example, suppose on Sundays, Mondays, and Wednesdays you want Infolinks displayed 80% of the time and Kontera 20%. On Tuesdays, Thursdays, Fridays, and Saturdays you want Infolinks displayed 35% of the time and Kontera 65% of the time. Your code would look like this:
When copying and pasting the code, remove any line breaks that occur within the document.write() command, otherwise the script will not run properly. By rotating your Kontera and Infolinks ad codes, you can see which ad network performs better and optimize your revenue.


© Had2Know 2010