Customise and Improve Awin’s Convert-a-link Script

If you are a user of Awin, you probably have heard of or been using their Convert-a-link feature. This is a handy feature – it converts all links to Awin affiliated advertisers on your site to Awin links automatically, so you don’t have to manually convert them one by one.

However, after trying out this feature I found two very annoying “bugs”. First, unlike Commission Junction, this tool from Awin tries to convert ALL links, regardless whether you have joined the respective advertiser’s program or not.

This is especially annoying for casual bloggers like me who work with only a handful of advertisers on Awin, since we also need other programs such as Viglink to monetise as many links as possible. As Convert-a-link has already affiliated all your links, Viglink won’t reaffiliate them again so you are losing out on advertisers who don’t work with you directly, but with Viglink.

The other nuisance is right-click on converted links is blocked. It acts as left-click so opens the link in a new window. What the hell?!

Good news is, after reading their code, I found an easy workaround to fix both issues. Here is the solution.

1. Enable Convert-a-link on your dashboard, and open the URL in your Publisher MasterTag. The URL will be something like

2. The (Javascript) code you are seeing is the one doing the converting job. It basically goes through all links on your site, find those affiliated with Awin, disable the default click/right-click behaviour and generate new links.

3. You may want to reformat the code (using e.g. this site) and paste it into the editor of your choice for convenience.

4. Now look for the line starting with var domains = . The following list in curly brackets are all advertisers working with Awin. What you want to do is only keep the programs that you have already joined.

For example, if you have only joined Hilton’s program, search for hilton, keep the three relevant entries and remove everything else. Now this script won’t convert any links other than Hilton’s. No trailing comma in the last line and remember the closing bracket.

5. Now go further down to locate the line starting with this.attachClickEvents = . The is the culprit that disables right-click and opens the URL on both left and right clicks.

Remove the following two lines:

links[i].oncontextmenu = this.stopDefaultActionForIe8;
links[i].addEventListener(‘contextmenu’, this.stopDefaultAction);

And replace the two mouseup occurrences with click. The final snippet would look like this:

6. Almost done! The last step is to insert this new piece of code to your website. If you are on WordPress, I strongly recommend using a plug-in such as Ad Inserter, rather than doing it yourself.

If you are using Ad Inserter, create a new ad, write down <script> </script>, then paste the code you have just created between them. Save it.

Alternatively (probably better), for those who know what I’m talking about, you could save the code as a js file on your server and load it asynchronously. You could also manually paste the code to your website template but using a plug-in makes your life much easier.

It should all work now. If you were using the Publisher MasterTag before don’t forget to disable it first. No more right-click hijack or conflict with other programs. Enjoy!


电子邮件地址不会被公开。 必填项已用*标注