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.
$ npm i -S affiliate
$ yarn add affiliate
Or use a CDN
<!-- Replace <VERSION> with your intended version, e.g. 1.2.1 -->
<script src="https://cdn.jsdelivr.net/npm/affiliate@<VERSION>/dist/affiliate.js"></script>
Affiliate can modify the following link into any of the others.
<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.
const Affiliate = require('affiliate');
const aff = Affiliate({
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 blogging-style sites.
Insert this code into the page <head>
. The contents of the data-aff
attribute will tell Affiliate what to do.
<!-- Replace 1.2 with your intended version -->
<script data-aff="amazon.com, www.amazon.com : tag = MY-AMAZON-TAG" src="https://cdn.jsdelivr.net/npm/[email protected]/dist/affiliate.js" async id="aff-js"></script>
The syntax for data-aff is a comma separated list of domains, a colon, and then comma separated list of url queries in the format key=value
. Multiple website groups can be separated by an exclamation mark.
amazon.com, www.amazon.com : tag = MY-AMAZON-TAG ! example.com, shop.example.com : ref = MY-OTHER-TAG
Affiliate is tested using Jasmine. The test of the minified packages is available here and the webpack package here.
Cross-browser Testing Platform and Open Source <3 Provided by Sauce Labs!
If you like it then you gotta put a star on it. 😉🌟
MIT (C) Russell Steadman. Learn more in the LICENSE file.
Like this project? Buy me a cup of coffee. ☕ Here are more of my projects.