nathan's blog

kickass stuff from and for the interwebs
« Back to blog
May 25
Views

Short Amazon Affiliate Links, Round Two

The other day I noticed that Amazon owns the "amzn.com" domain and they use it to generate short links to products. Unfortunately, the only way I've found to directly create the short links is to use a very tiny 'share on Twitter' button on the product page:

Amazon_twitter_share

This button opens a new browser window and pre-fills the status update field with the short link. But what if you want to paste a short link into an email or Twitter client? Let's solve that problem by creating a JavaScript bookmarklet that returns a shortened URL, and optionally appends your Amazon affiliate code.

I've explored this area before by using Mac OS X's Automator and Ruby. This time, let's create a cross-platform solution.

Stoyan Stefanov created a bookmarklet solution that grabs the ASIN from most Amazon product pages and returns a URL without all the cruft. I like the simplicity of Stoyan's solution, as it uses JavaScript to grab the ASIN by its element ID, instead of using a complicated regex. We'll use his code as a starting point, and tweak it to support the new short domain.

The short link format is simple, it's just "http://amzn.com/" + the ASIN.

If you want to generate URLs with an affiliate ID, use this code:

otherwise use this:

Edit your Affiliate ID (if applicable), then paste the code into the very handy Bookmarklet Crunchinator. Drag the output link to your bookmarks bar, and you're done!

Now, when you visit an Amazon product page, you can click your bookmarklet and a shortened URL is returned. This seems to work on most products, though I've run into a few (like Kindle books) that don't seem to work.

Enjoy!