I’ve been a member of Amazon’s Associate program for a number of years and have posted affiliate links to books discussed on this very blog. The program means that by putting my affiliate ID into any links to Amazon products, I receive a small referral fee.
I’ve always linked to Amazon.co.uk as that’s my local Amazon store, but of course that’s not necessarily true for my visitors – or yours…
To solve this problem, I’ve written some JavaScript and a little bit of PHP which will convert any Amazon links on your page into affiliated links to your visitor’s local Amazon store. So US visitors will get a .com link, whilst UK visitors will get a .co.uk link to the same product.
Download
- amazon-localiser.zip 4 kb
Setup
Edit amazon-localiser.js to insert your regional Associate IDs into the array at the top, for example:
var arrAffiliates = {
'co.uk' : 'petewill-19',
'com' : 'petewill-20',
'de' : 'petewill05-21',
'fr' : 'petewill-21',
'ca' : 'petewill00-20',
'jp' : '',
'it' : petewill04-21',
'cn' : petewill-23',
'es' : petewill0d4-21'
};
If you do not have an ID for each country, you can just leave them blank, as above for .jp.
In most cases, you will also need to set the path to amazon-localiser.php, for example:
var strUrlAjax = '/inc/amazon-localiser.php';
Upload and Embed
As well as linking to amazon-localiser.js you need to link to the Google JS API file (5 kb) or the script will not work. Insert the following code just before your </body> tag:
<script type="text/javascript" src="http://www.google.com/jsapi"></script> <script type="text/javascript" src="amazon-localiser.js"></script>
Upload your modified amazon-localiser.js file, and make sure the above link points to the right location.
Usage
That’s it – job done! You can now just link to any product on any Amazon site with a normal, unaffiliated link and your users will get one affiliated for their country. Initially, the script looks for a product with the same product ID as the one in your link, but if it can’t find one on the user’s local store, it will link to a search results page searching for the name of your product. This means that it will still be found even if international versions have different product IDs, and if it’s not stocked at all, your user will be shown similar alternatives.
Example
The script is running on this page, so hopefully this example should be affiliated specially for you!
Updates
Follow me on Twitter to be sure you hear about new updates.
Donations
If you find this plugin helpful and it’s increasing your sales. please consider donating just $1 or more to say thanks for the many, many hours I’ve spent on it. I’d really appreciate it!
Disclosure
If you do not insert your own affiliate IDs the script will use mine. Hopefully this will help fund my book addiction!
Wow this looks like a great script!
just one question – where exactly do we put amazon.js and the Google JS API file? In our websites header or footer?
Thanks!
Hi Tricia, it’ll work fine wherever you put it, but for performance issues, I’d recommend you put it at the bottom of your page, just before the </body> tag.
Hi Pete
So I could put both of them in say in my blogs footer? Just want to be sure that I’ll be doing it right.
Thanks!
Yes, that would be fine.
thanks for this
[...] If you want to achieve the same result on a non-Wordpress site, you can simply install the pure JavaScript version. [...]
Do you have to signup for each amazon TLD separately ?
Yes, each store as a separate affiliate program which you need to sign up to. They will each give you a unique affiliate ID which you store in the plugin settings.
Thanks for the script. Perfect for my drupal website!
Great script and very useful, I’ll be trying it on my WordPress and hopefully it’ll save me a lot of time of manual links entry .
[...] des mêmes avantages que sur WordPress sur d’autres plateformes de blog, vous pouvez installer la version Java sur votre [...]
Hi Pete, script looks great but I have one question:
You stated that I can insert an unaffiliated link to the post.
But, if I put an affiliated link, will this script works and change the link anyway?
I want to install your script to my blogs which already has Amazon contents and don’t feel like going through all the troubles of changing all those inserted links.
Thanks.
Yes that’ll work fine.
Does this work with any format of amazon affiliate link?
Not only in this format
http://www.amazon.de/exec/obidos/ASIN/0321344758/petewill05-21
like a link generated from the afiliate linkbuilder
http://www.amazon.de/Dont-Make-Me-Think-Usability/dp/0321344758/?_encoding=UTF8&site-redirect=de&tag=petewill05-21&linkCode=ur2&camp=1638&creative=6742
or other formats?
Hi Holger,
Yes those will work fine.
Pete
Thanks Pete. Will try it out
Great tip this. I’m going to try to follow the example above. I feel I may run into trouble as I often favour Amazon’s “short url” so will report back if I get any questions with it.
Hi and thanks for this script. It looks like it’s exactly what I need but I would like to know if anyone here has yet been successful at using it on a Drupal site. I haven’t but i might be doing something wrong. Is there a plan to port this to Drupal 7 as a module ?
That would be great…
Hi, I’ve no experience with Drupal, so I had no plans to migrate the module. That said, it shouldn’t be too hard to get across, so if anyone has any experience of Drupal modules and wants to help out, then I should be able to get it working.