Skip to the content.


Affiliate is a platform agnostic link affiliator. Simplify affiliating links with automatic affiliation in the browser. Affiliate works with libraries that mutate the DOM after the page loads, including React.

🌟 Star me on Github Download via NPM Use via CDN Bundle small when minified Bundle small when minified and gunzipped


Use NPM or Yarn

$ npm install --save affiliate
$ yarn add affiliate

Or use a CDN (check out the codeless setup)

<script src=""></script>

What It Can Do

Affiliate can modify query tags (e.g. setting ?tag=my-tag, which is the most common method for affiliate tags), modify URL paths, and modify host names.

<a href="">Original</a>
<a href="">New Query Tags</a>
<a href=""
  >Modified URL Path</a
<a href="">Modified Host Name</a>

Affiliate has easy plugins, including one for Amazon, which simplify adding affiliate links even more.


import Affiliate from 'affiliate'; // window.Affiliate is automatically accessible if using a CDN

const aff = Affiliate.create({
  log: true, // enable logging
  tags: [
      hosts: ['', ''], // a list of applicable hosts
      query: {
        ref: 'my-tag', // will output a url with ?ref=my-tag
      replace: [
          from: 'ref-tag', // will replace ref-tag in all urls with my tag
          to: 'my-tag',
          from: /ref-regex/g, // regular expressions are supported
          to: 'my-tag',
      modify: function (url) {
        // a function that directly modifies the URL
        url.set('pathname', url.pathname + '-tag');
        url.set('hostname', url.hostname + '');
        return url;


After passing the configuration to Affiliate, it will search the DOM and automatically and change links. Then whenever the DOM is modified, it will search through the modifications and change those links for no-hassle affiliation.


A boolean of whether or not to enable verbose logging.


An array of the hosts to match.


An object to update the query of the url.


An array of objects with a from key that is a regex or string and a to key that is the value that will replace the from key.


This exposes a URL instance. This can be used to update individual parts of the URL, such as the hostname or hash. It expects the URL instance or a URL string to be returned.

Affiliate API

import Affiliate from 'affiliate';

let newInstance = Affiliate.create(config); // creates a new Affiliate instance
let instances = Affiliate.instances; // an array of all instances
Affiliate.detachAll(); // stops all instances from making automatic changes
Affiliate.revert(); // detaches all instances and reverts all urls

newInstance.attach(); // begins listening to DOM events
newInstance.detach(); // stops listening to DOM events


import Affiliate from 'affiliate'; // window.Affiliate if using a CDN

const aff = Affiliate.create({
  log: false,
  tags: [
      hosts: ['', ''],
      query: {
        ref: 'my-amazon-tag-20',

You should try the
<a href="">Chocolate Passport</a>.

Will become…

You should try the
<a href="">
  Chocolate Passport

A simplified codeless solution might better suit some sites that use content module systems, such as WordPress, SquareSpace, etc.

Insert this code within the HTML <head>...</head> tag. The contents of the data-auto-affiliate attribute will tell Affiliate what to do.

  data-auto-affiliate="WHERE, SET tag = MY-AMAZON-TAG"

data-auto-affiliate Syntax

The syntax for data-auto-affiliate is capital WHERE, a comma separated list of domains, capital SET, and then comma separated list of URL queries in the format key=value. Multiple website groups can be separated by a capital AND.



Plugins make some more complex affiliation tasks super simple. Check out a list here, and learn to make your own.

Left with Questions?

If for any reason you feel that this documentation is unclear or incomplete, add an issue detailing what needs to be improved.

Star This Project

Like this project? Let me know by putting a star on it. 😉🌟


MIT (C) Russell Steadman. Learn more in the LICENSE file.