Add Amazon Affiliate Code to Links

If you’re a blogger and not using Amazon affiliate links, you are missing out on a great extra source of income. Unlike ads, they do not affect your readers and allow them to find the items you are reviewing/recommending.

When writing a post, there is always a chance you could forget to add your affiliate code to the end of the URL. Below is a javascript snippet that can be added to most websites and will automatically add your affiliate code to any Amazon URL. Make sure you include jquery on your site and change the affilateTag variable.

$(document).ready(function() {
  var affilateTag = 'timlelcom-20'; //Replace with your affilate code
  $('a[href*="amazon.com"]').each(function() {
    if (!this.href.includes('tag=' + affilateTag)) {
      var tag = this.href.includes('?') ? '&tag=': '?tag=';
      this.href = this.href + tag + affilateTag;
    }
  });
});

Thanks for reading. Make sure you follow me on Twitter to stay up to date on the progress of my side projects T.LYWeather Extension, and Link Shortener Extension. If you are interested in the tech I use daily, check out my uses page.  

Leave a Reply

Your email address will not be published. Required fields are marked *