{"id":5767,"date":"2020-06-10T04:27:04","date_gmt":"2020-06-09T20:27:04","guid":{"rendered":"http:\/\/www.verylvke.com\/en\/?p=5767"},"modified":"2020-06-14T18:43:24","modified_gmt":"2020-06-14T10:43:24","slug":"customise-and-improve-awins-convert-a-link-script","status":"publish","type":"post","link":"https:\/\/www.verylvke.com\/en\/2020\/06\/10\/customise-and-improve-awins-convert-a-link-script\/","title":{"rendered":"Customise and Improve Awin&#8217;s Convert-a-link Script"},"content":{"rendered":"\n<p>If you are a user of <a href=\"http:\/\/www.awin1.com\/awclick.php?gid=807&amp;mid=3&amp;awinaffid=572701&amp;linkid=2137873&amp;clickref=\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"Awin\uff08\u5728\u65b0\u7a97\u53e3\u6253\u5f00\uff09\">Awin<\/a>, you probably have heard of or been using their <a rel=\"noreferrer noopener\" aria-label=\"\uff08\u5728\u65b0\u7a97\u53e3\u6253\u5f00\uff09\" href=\"https:\/\/wiki.awin.com\/index.php\/Convert-a-link\" target=\"_blank\">Convert-a-link<\/a> feature. This is a handy feature &#8211; it converts all links to Awin affiliated advertisers on your site to Awin links automatically, so you don&#8217;t have to manually convert them one by one.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>However, after trying out this feature I found two very annoying &#8220;bugs&#8221;. First, unlike Commission Junction, this tool from Awin tries to convert ALL links, regardless whether you have joined the respective advertiser&#8217;s program or not.<\/p>\n\n\n\n<p>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 <a rel=\"noreferrer noopener\" aria-label=\"Viglink\uff08\u5728\u65b0\u7a97\u53e3\u6253\u5f00\uff09\" href=\"http:\/\/viglink.com\/?vgref=134170\" target=\"_blank\">Viglink<\/a> to monetise as many links as possible. As Convert-a-link has already affiliated all your links, Viglink won&#8217;t reaffiliate them again so you are losing out on advertisers who don&#8217;t work with you directly, but with Viglink.<\/p>\n\n\n\n<p>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?!<\/p>\n\n\n\n<p>Good news is, after reading their code, I found an easy workaround to fix both issues. Here is the solution.<\/p>\n\n\n\n<p>1. Enable Convert-a-link on your dashboard, and open the URL in your Publisher MasterTag. The URL will be something like  <br>https:\/\/www.dwin2.com\/pub.123456.min.js. <\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><a href=\"https:\/\/www.verylvke.com\/wp-content\/uploads\/2019\/03\/awin-code.jpg\" target=\"_blank\" rel=\"noreferrer noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.verylvke.com\/wp-content\/uploads\/2019\/03\/awin-code.jpg\" alt=\"\" class=\"wp-image-19675\" width=\"500\" height=\"350\"\/><\/a><\/figure><\/div>\n\n\n\n<p>3. You may want to reformat the code (using e.g. <a rel=\"noreferrer noopener\" aria-label=\"this site\uff08\u5728\u65b0\u7a97\u53e3\u6253\u5f00\uff09\" href=\"https:\/\/www.freeformatter.com\/javascript-beautifier.html\" target=\"_blank\">this site<\/a>) and paste it into the editor of your choice for convenience.<\/p>\n\n\n\n<p>4. Now look for the line starting with <samp style=\"background:hsl(220, 80%, 90%)\">var domains = <\/samp>. 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.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><a href=\"https:\/\/www.verylvke.com\/wp-content\/uploads\/2019\/03\/awin-domains-1.jpg\" target=\"_blank\" rel=\"noreferrer noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.verylvke.com\/wp-content\/uploads\/2019\/03\/awin-domains-1.jpg\" alt=\"\" class=\"wp-image-19676\" width=\"525\" height=\"506\"\/><\/a><\/figure><\/div>\n\n\n\n<p>For example, if you have only joined Hilton&#8217;s program, search for hilton, keep the three relevant entries and remove everything else.  Now this script won&#8217;t convert any links other than Hilton&#8217;s. No trailing comma in the last line and remember the closing bracket.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><a href=\"https:\/\/www.verylvke.com\/wp-content\/uploads\/2019\/03\/awin-domains-2.jpg\" target=\"_blank\" rel=\"noreferrer noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.verylvke.com\/wp-content\/uploads\/2019\/03\/awin-domains-2.jpg\" alt=\"\" class=\"wp-image-19677\" width=\"525\" height=\"83\"\/><\/a><\/figure><\/div>\n\n\n\n<p>5. Now go further down to locate the line starting with <samp style=\"background:hsl(220, 80%, 90%)\">this.attachClickEvents = <\/samp>. The is the culprit that disables right-click and opens the URL on both left and right clicks. <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><a href=\"https:\/\/www.verylvke.com\/wp-content\/uploads\/2019\/03\/awin-events-1.jpg\" target=\"_blank\" rel=\"noreferrer noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.verylvke.com\/wp-content\/uploads\/2019\/03\/awin-events-1.jpg\" alt=\"\" class=\"wp-image-19678\" width=\"525\" height=\"149\"\/><\/a><\/figure><\/div>\n\n\n\n<p>Remove the following two lines:<\/p>\n\n\n\n<p><samp style=\"background:hsl(220, 80%, 90%)\">links[i].oncontextmenu = this.stopDefaultActionForIe8;<br>\nlinks[i].addEventListener(&#8216;contextmenu&#8217;, this.stopDefaultAction);<\/samp><\/p>\n\n\n\n<p>And replace the two <samp style=\"background:hsl(220, 80%, 90%)\">mouseup<\/samp> occurrences with <samp style=\"background:hsl(220, 80%, 90%)\">click<\/samp>. The final snippet would look like this:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><a href=\"https:\/\/www.verylvke.com\/wp-content\/uploads\/2019\/03\/awin-events-2.jpg\" target=\"_blank\" rel=\"noreferrer noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.verylvke.com\/wp-content\/uploads\/2019\/03\/awin-events-2.jpg\" alt=\"\" class=\"wp-image-19679\" width=\"525\" height=\"127\"\/><\/a><\/figure><\/div>\n\n\n\n<p>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 <a href=\"https:\/\/en-gb.wordpress.org\/plugins\/ad-inserter\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"Ad Inserter\uff08\u5728\u65b0\u7a97\u53e3\u6253\u5f00\uff09\">Ad Inserter<\/a>, rather than doing it yourself.<\/p>\n\n\n\n<p>If you are using Ad Inserter, create a new ad, write down <samp style=\"background:hsl(220, 80%, 90%)\">&lt;script&gt;  &lt;\/script&gt;<\/samp>, then paste the code you have just created between them. Save it.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><a href=\"https:\/\/www.verylvke.com\/wp-content\/uploads\/2019\/03\/awin-ad-inserter-1.jpg\" target=\"_blank\" rel=\"noreferrer noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.verylvke.com\/wp-content\/uploads\/2019\/03\/awin-ad-inserter-1.jpg\" alt=\"\" class=\"wp-image-19680\" width=\"525\" height=\"149\"\/><\/a><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><a href=\"https:\/\/www.verylvke.com\/wp-content\/uploads\/2019\/03\/awin-ad-inserter-2.jpg\" target=\"_blank\" rel=\"noreferrer noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.verylvke.com\/wp-content\/uploads\/2019\/03\/awin-ad-inserter-2.jpg\" alt=\"\" class=\"wp-image-19681\" width=\"525\" height=\"291\"\/><\/a><\/figure><\/div>\n\n\n\n<p>Alternatively (probably better), for those who know what I&#8217;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.<\/p>\n\n\n\n<p>It should all work now. If you were using the Publisher MasterTag before don&#8217;t forget to disable it first. No more right-click hijack or conflict with other programs. Enjoy!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &#8211; it converts&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[],"tags":[],"class_list":["post-5767","post","type-post","status-publish","format-standard","hentry"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.verylvke.com\/en\/wp-json\/wp\/v2\/posts\/5767","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.verylvke.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.verylvke.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.verylvke.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.verylvke.com\/en\/wp-json\/wp\/v2\/comments?post=5767"}],"version-history":[{"count":1,"href":"https:\/\/www.verylvke.com\/en\/wp-json\/wp\/v2\/posts\/5767\/revisions"}],"predecessor-version":[{"id":5783,"href":"https:\/\/www.verylvke.com\/en\/wp-json\/wp\/v2\/posts\/5767\/revisions\/5783"}],"wp:attachment":[{"href":"https:\/\/www.verylvke.com\/en\/wp-json\/wp\/v2\/media?parent=5767"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.verylvke.com\/en\/wp-json\/wp\/v2\/categories?post=5767"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.verylvke.com\/en\/wp-json\/wp\/v2\/tags?post=5767"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}