[How to] Mask your affiliate links from end users

thedorf

Elite Member
Joined
Oct 1, 2008
Messages
2,558
Reaction score
1,819
Just a quick how to for you all. Many users will hover over a link, look at the bottom of the browser, and see if it is an affiliate link. If it is most who do this will open a new window and manually type in the website address without the affiliate code attached.

The following will mask the affiliate link, but, it only masks the link on your website. Once the link is clicked the affiliate code is added to the link and visible in the address bar on the website the end-user is forwarded to - but most will not notice this and in any case your cookie has already been set.

THIS IS NOT COOKIE STUFFING.

Read: "On the World Wide Web, cookie stuffing (also cookie dropping) is an affiliate marketing technique in which, as a result of visiting a website, a user receives a third-party cookie from a website unrelated to that visited by the user, usually without the user being aware of it." Source: https://en.wikipedia.org/wiki/Cookie_stuffing

Using my technique the cookie is being set by the website the cookie is valid for, a small but major difference.

You can see this in action on my website but the website is only one day old and is still ugly as hell: http://www.100prowebsitetips.com

A non-affiliate link to the company I am promoting is: http://www.a2hosting.com

Here is the HTML:

Code:
<a href=''http://www.a2hosting.com" rel="nofollow" id="a2">http://www.a2hosting.com</a>

Here is the Javascript that does the magic:

Code:
function loadlink(url, callback){
var link = document.getElementById( 'a2' );
link.addEventListener( 'click', function() {
link.setAttribute("href",url);
callback();
});
}

loadlink("http://www.a2hosting.com?aid=YourAffiliateId", function(){
setTimeout(function() { document.getElementById( 'a2' ).setAttribute("href","http://www.a2hosting.com"); }, 1000);
});

The callback function resets the link on my webpage to be the link without the affiliate code - but if clicked it will again forward with the affiliate id attached.

Cheers,

Phillip aka thedorf

P.S. Always notify your affiliate manager if you do this to be on the safe side - I've yet to find an affiliate manager that had a problem with this.

P.S.S. Mods if there is a problem with this post just delete it - whatever.
 
Last edited:
Hey Phillip, would you mind explaining why the timeout is necessary there? (Unfortunately, I'm not very good with JavaScript)

Gonna try this one out tomorrow, pretty smart approach!
 
The timeout is necessary because the callback function will change the link back to the original href before the forward to the new website occurs and we will not get the affiliate code with the link.

We have to let the click take effect, the forward occur, and then change the link back to it's original state without the affiliate code attached so it still shows on our website to be a non-affiliate link. If we did not do this another mouse-over on the link (on our website) would show the changed href with the affiliate code attached.
 
Looking at the WordPress Pretty Link website it's hard to tell if they are using 301 redirects (I don't recommend this as you are misleading the end-user where they are going) or just shortening the url. A shortened url will usually be assumed to be an affiliate link by most savvy internet users. Besides, not everyone is on WordPress.

My method does not mislead the end-user where they are going, all I am doing is adding a variable along with the URL. The end-user goes exactly where the link states they are going. Also, I do not violate any FTC rules doing this that I am aware of. I am not paid to do this and I only promote products I have purchased and tried myself.

Plus, my method costs nothing. I reply on the affiliate program for reporting clicks from my website so I get reporting as well.

But hey, you do what you want to do...
 
This is absolutely brilliant piece of code :)

Thanks alot :)
 
I am gonna put this to use for another affiliate thing I have in mind!
 
Back
Top