How to Dynamically insert an affiliate ID into a banner

using Revive Adserver

This article explains how to add custom values to zone invocation code, and then to use those values using custom magic macros in banners.

This article answers a question we’ve seen frequently. We’ve taken a typical example of this question and generalized it as follows:

I have a campaign running on multiple sites with different publishers. These publishers run the invocation code on their sites and I use Revive Adserver 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 abc showing the banner with the link as myurl.com?affid=abc, and publisher def displaying the same banner and with the link as myurl.com?affid=def and so on.

This is possible, and it is not even all that hard to implement!

To address this requirement, we use two techniques that are not very well known: site variables in zone invocation code and magic macros in banners. Please continue reading to find out how.

Adding custom values to Revive Adserver invocation code

When Revive Adserver generates the invocation code for a zone, the first line of that code contains the ID of the zone in question, along with a few other things.

<ins data-revive-zoneid="X" data-revive-id="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"></ins>
<script async src="//the-ad-server-url/asyncjs.php"></script>

We’ve formatted the zone ID in bold for the purpose of illustration, in reality there is no such thing as bold in computer code.

What many people don’t know is that you can add extra parameters to the first line.

Here is an example that could be used for the scenario described in the question above:

<ins data-revive-zoneid="X" data-revive-pubid="Y" data-revive-id="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"></ins>
<script async src="//the-ad-server-url/asyncjs.php"></script>

Just send each publisher a version of the code whereby you replace the capital Y with the number that you’ve assigned to them, so that you can uniquely identify them.

Any time Revive Adserver 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 Revive Adserver during ad processing, we need a way to insert this ID into the banner. There is a little known feature in Revive Adserver called “Magic Macros” that can do just this.

Let’s assume you have a banner in Revive Adserver (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:

https://www.myurl.com

What Magic Macros can do is simple, here is an example so you’ll see right away:

https://www.myurl.com?affid={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, Revive Adserver will automatically replace the magic macro with the value of the pubid variable.

So if the zone is called like this:

<ins data-revive-zoneid="X" data-revive-pubid="abc" data-revive-id="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"></ins>
<script async src="//the-ad-server-url/asyncjs.php"></script>

the banner will be delivered with this link:

https://www.myurl.com?affid=abc