npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

affiliate

v5.0.0

Published

A platform agnostic tool to quickly add affiliate links onto your website

Downloads

188

Readme

Affiliate

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

Installation

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.

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="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.

Basic Setup

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();

Documentation

Affiliate is simple and quick to set up, even for more complex usage. Read the docs at: affiliate.js.org.

Blogs and Related Sites

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>

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.

WHERE amazon.com, www.amazon.com SET tag = MY-AMAZON-TAG AND WHERE example.com, shop.example.com SET ref = MY-OTHER-TAG

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. 

License

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