OpenX "INSERT_RANDOM_NUMBER_HERE"

September 25, 2008

Openx Invocation Tags Requiring Random Numbers

One of least understood and most often asked questions in regards to the OpenX banner invocation code must be the “INSERT_RANDOM_NUMBER_HERE” placed within the image, java and iframe invocation codes by OpenX.

This post will attempt to clarify this and give you some simple examples as to implementing on your site

Within the invocation code for a zone using the image, iframe, or javascript tag, there’s a part called “cb=INSERT_RANDOM_NUMBER_HERE”.

What is it ? Why is it needed ?

This is a unique number required to stop browser caching of your banners and ensures each end user will receive a new ad on page load. If we took the above example and simply inserted “cb=123″, the end user being a web browser or spider would eventually see this ad as a static non changing item and cache it. The user would then begin to see the same ad each time he accessed your page as its now stored in his browser cache with the stated id of 123.

If we generate a new number each time the ad is called, the browser, sees this as new content, and as such loads the new content on each visit.

Depending on your sites cms, design or other there are several language specific ways to generate this new random number on each page load. I will give a few examples below. Feel free to copy and paste as needed. Please perform test before implementing , or use at your own risk.

How to Generate A Random Number

php example:
First as its my personal favorite language I will provide an example in php.
This is the part that generates the number. If you are using more than 1 invocation tag on your site or within your template then place this code above your first banner call.

<?php $random_number = rand(1, 999999); ?>

Now we have a random number being generated each time the page is accessed. We can now place the random number within the OpenX banner invocation code.

Where you have “cb=INSERT_RANDOM_NUMBER_HERE”, simply replace as shown below

cb=<?php echo"$random_number";?>

You now have a new unique id generated and inserted with php on each and every page load.

Java example:
Here’s an example for those with static html pages.

<script type='text/javascript'>
var randomnumber=Math.floor(Math.random()*99999999999);
document.write("<a href='http://domain.com/ck.php?n=3874N2&cb="+randomnumber);
document.write("'><img src='http://domain.com/avw.php?zoneid=1&n=3874N2&cb="+randomnumber);
document.write("'></a>");
</script>

In order to implement the above code you will first need to generate a valid Image invocation tag from within OpenX to make sure that the domain and path to OpenX are valid, and that the < img > tag has the correct zoneid. So a valid invocation tag would look similar to below.

<script type='text/javascript'><!--//<![CDATA[
   var m3_u = (location.protocol=='https:'?'https://www.openxpayments.com/openx-2/www/delivery/ajs.php':'http://www.openxpayments.com/openx-2/www/delivery/ajs.php');
   var m3_r = Math.floor(Math.random()*99999999999);
   if (!document.MAX_used) document.MAX_used = ',';
   document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
   document.write ("?zoneid=1");
   document.write ('&amp;cb=' + m3_r);
   if (document.MAX_used != ',') document.write ("&amp;exclude=" + document.MAX_used);
   document.write (document.charset ? '&amp;charset='+document.charset : (document.characterSet ? '&amp;charset='+document.characterSet : ''));
   document.write ("&amp;loc=" + escape(window.location));
   if (document.referrer) document.write ("&amp;referer=" + escape(document.referrer));
   if (document.context) document.write ("&context=" + escape(document.context));
   if (document.mmm_fo) document.write ("&amp;mmm_fo=1");
   document.write ("'><\/scr"+"ipt>");
//]]>--></script><noscript>
<script type='text/javascript'>
var randomnumber=Math.floor(Math.random()*99999999999);
document.write("<a href='http://www.openxpayments.com/openx-2/www/delivery/ck.php?n=acb4cacc&amp;cb=="+randomnumber);
document.write("'><img src='http://www.openxpayments.com/openx-2/www/delivery/avw.php?zoneid=1&amp;n=acb4cacc&cb="+randomnumber);
document.write("'></a>");
</script>

Granted with all the code that’s a hard one to understand and implement. But if you look closely you will note the only changes that were made were to the image tag.

ASP example:
Hopefully there’s not a lot of folks using asp these days. I personally find it cumbersome, and it will stall my browser on most page visits. Perhaps a good definition of ironic as I browse with ie7.

First generate the random number with ASP, remembering to place it above any banner invocation tags on your page.

<%
Dim my_num
Randomize
my_num = Int((rnd*10))+1
%>

Then within your invocation tags, where you have “cb=INSERT_RANDOM_NUMBER_HERE”, replace as shown below.

cb=<% Response.Write my_num %>

Conclusion:
Hopefully that will have you well on your way to generating a random number, for your OpenX invocation code in order to stop browser caching and ensure your ads are being shown properly.

If you feel you still need help you can leave a post on our forum, and hopefully I or another will have a chance to answer you soon. If not Our services are affordable and timely.

Share

Comments

Comments are closed.

  • RevMax Update Newsletter



     
  • Advertisement