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 which will convert any Amazon product 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.js (2 kb)
- amazon.min.js compressed (1 kb)
Setup
Edit amazon.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' : ''
}
If you do not have an ID for each country, you can just leave them blank, as above for .jp.
Upload and Embed
As well as linking to amazon.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.min.js"></script>
Upload your modified amazon.js file, and make sure the above link points to the right location.
Usage
That’s it. You’re 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.
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.
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.