How to: Dynamically insert an affiliate ID into a banner

I often get questions in the mail or through the contact form that might be relevant to more than just one person. That’s why I have decided to start answering these questions on this blog. I’ve created a new Q&A category, I hope to be able to add more posts shortly.

Lorand Minyo from Romania sent me this question:

I have a campaign running on multiple sites with different publishers, with two banners in rotation. These publishers run the invocation code on their sites and I use OpenX to count views and clicks. However, I’d like to give each of the publishers the ability to have a different link for the same banner – for example publisher 1 using banner X and have the link, publisher 2 using the same banner X and have the link and so on. This would be particularly useful, since I want to count views and clicks in OpenX and record transactions in my billing system. So my question is: Can you have different links for the same banner or different links for different zones?

Lorand, this is possible, and it is not even all that hard to implement. I suggest we use two techniques that are not very well known: site variables in zone invocation code and magic macros in banners. I will explain below.

Adding publisher details to OpenX invocation code

When OpenX generates the invocation code for a zone, one line of that code contains the ID of the zone in question:

document.write (“?zoneid=1”);

What many people don’t know is that you can add extra parameters to the line of where OpenX placed the zone ID. Here is an example that could be used for the scenario that Lorand described:

document.write (“?zoneid=1&pubid=X”);

Just send each publisher instructions to replace the capital X with the number that you want them to use, so that you can uniquely identify them. Any time OpenX is processing an ad request for this zone, it ‘knows’ the extra bit of information, in this case the value of the variable named “pubid”.

Dynamically altering a banner or link

Now that we have the publisher’s ID in OpenX during ad processing, we need a way to insert this ID into the banner. There is a little known feature in OpenX called “Magic Macros” that can do just this.

Let’s assume you have a banner in OpenX (it might be an image banner with a destination URL specified, but it could just as well be an HTML banner). The link would like something like this:

What Magic Macros can do is simple, let me give you the example and you’ll see right away:{pubid}

Whenever a banner with this magic macro is delivered through a zone that’s called with the special version of the invocation code described above, OpenX will automatically replace the magic macro with the value of the pubid variable. So if the zone is called like this:

document.write (“?zoneid=1&pubid=abc”);

The banner will be delivered with this link:

Share this on:
  • Twitter
  • Facebook
  • LinkedIn
  • email
About Erik Geurts - OpenX Source Specialist

Find out more about me on my profile page on Google+