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.
Use NPM or Yarn
$ npm install affiliate
$ yarn add affiliate
Or use a CDN (check out the codeless setup)
<script src="https://cdn.jsdelivr.net/npm/affiliate@5/dist/web/affiliate.web.js"></script>
The precompiled version of affiliate@5
supports modern browsers (i.e. ES2016
or above) by default.
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="https://example.com/shop/product/item-id">Original</a>
<a href="https://example.com/shop/product/item-id?ref=my-tag">New Query Tags</a>
<a href="https://example.com/shop/product/item-id/ref/my-tag"
>Modified URL Path</a
>
<a href="https://my-tag.example.com/shop/product/item-id">Modified Host Name</a>
Affiliate has easy plugins, including one for Amazon, which simplify adding affiliate links even more.
Read the documentation for more advanced usage.
import Affiliate from 'affiliate';
const aff = Affiliate.create({
tags: [
{
hosts: ['example.com', 'www.example.com'],
query: {
ref: 'my-tag', // This means ?ref=my-tag
},
},
{
hosts: ['example.org', 'shop.example.org'],
query: {
tag: 'my-tag2', // This means ?tag=my-tag2
},
},
],
});
aff.attach();
Affiliate is simple and quick to set up, even for more complex usage. Read the docs at: affiliate.js.org.
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.
<script
data-auto-affiliate="WHERE amazon.com, www.amazon.com SET tag = MY-AMAZON-TAG"
src="https://cdn.jsdelivr.net/npm/affiliate@5/dist/web/affiliate.web.js"
async
id="aff-js"
></script>
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
.
WHERE amazon.com, www.amazon.com SET tag = MY-AMAZON-TAG AND WHERE example.com, shop.example.com SET ref = MY-OTHER-TAG
If for any reason you feel that this documentation is unclear or incomplete, add an issue detailing what needs to be improved.
Like this project? Let me know by putting a star on it. 😉🌟
MIT (C) Russell Steadman. Learn more in the LICENSE file.