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 🙏

© 2026 – Pkg Stats / Ryan Hefner

affiliatebase-tracking

v1.0.3

Published

Lightweight affiliate tracking script for AffiliateBase - cookie-based attribution, conversion tracking, and Stripe integration

Readme

affiliatebase-tracking

Lightweight, zero-dependency affiliate tracking script for AffiliateBase. Cookie-based attribution, conversion tracking, and automatic Stripe integration.

npm version License: MIT

Features

  • Cookie-based referral attribution (30-day default)
  • Multiple tracking parameters (?via=, ?ref=, ?affiliate=)
  • Automatic Stripe Buy Button / Pricing Table integration
  • Conversion tracking via email
  • Promo code attribution
  • Cross-domain link tagging
  • Automatic form integration
  • Zero dependencies, pure JavaScript (~26KB)

Quick Start

Add this snippet to your website's <head> or before </body>:

<script>
  (function (w, r) {
    w._abq = w._abq || [];
    w[r] =
      w[r] ||
      function () {
        (w[r].q = w[r].q || []).push(arguments);
      };
  })(window, "affiliatebase");
</script>
<script
  async
  src="https://cdn.jsdelivr.net/npm/affiliatebase-tracking@1/src/index.js"
  data-org-id="YOUR_ORG_ID"
></script>

Replace YOUR_ORG_ID with your organization ID from the AffiliateBase dashboard.

That's it! The script will automatically track referrals from affiliate links.

Usage

Track Conversions

When a referred visitor signs up or makes a purchase, track the conversion:

affiliatebase("convert", { email: "[email protected]" });

Check Attribution

affiliatebase("ready", () => {
  if (window.AffiliateBase.referral) {
    console.log("Referred by:", window.AffiliateBase.affiliate?.name);
  }
});

Stripe Integration

Add data-affiliatebase to your Stripe elements for automatic attribution:

<!-- Stripe Buy Button -->
<stripe-buy-button buy-button-id="buy_btn_xxx" publishable-key="pk_live_xxx" data-affiliatebase></stripe-buy-button>

<!-- Stripe Pricing Table -->
<stripe-pricing-table
  pricing-table-id="prctbl_xxx"
  publishable-key="pk_live_xxx"
  data-affiliatebase
></stripe-pricing-table>

Form Integration

Add data-affiliatebase="true" to forms to automatically include referral data:

<form data-affiliatebase="true" action="/signup" method="POST">
  <input type="email" name="email" />
  <button>Sign Up</button>
  <!-- Hidden referral input auto-injected -->
</form>

Configuration

Script Attributes

| Attribute | Required | Description | | --------------------------- | -------- | --------------------------------------- | | data-org-id | Yes | Your organization ID | | data-debug | No | Set to "true" for console logging | | data-affiliatebase-params | No | Custom URL parameters (comma-separated) |

URL Parameters

The script automatically detects these URL parameters:

  • ?via=TOKEN (primary)
  • ?ref=TOKEN
  • ?affiliate=TOKEN
  • ?a=TOKEN
  • ?referral=ID (preload existing referral)

Example affiliate link: https://yoursite.com?via=john123

API Reference

Methods

// Track conversion
affiliatebase("convert", { email: "[email protected]" });

// Force attribution to specific affiliate
affiliatebase("source", "affiliate_token");

// Execute when loaded
affiliatebase("ready", () => {
  console.log("Ready!");
});

Global Object

Access attribution data via window.AffiliateBase:

window.AffiliateBase.referral; // Referral ID (UUID) or ""
window.AffiliateBase.affiliate; // Affiliate object or false
window.AffiliateBase.campaign; // Campaign object or false
window.AffiliateBase.coupon; // Coupon object or false

Events

window.addEventListener("AffiliateBase.initialized", () => {
  console.log("Tracking initialized");
});

window.addEventListener("AffiliateBase.tracked", (e) => {
  console.log("Referral tracked:", e.detail.referral);
});

TypeScript

Type definitions are included:

import "affiliatebase-tracking";

affiliatebase("convert", { email: "[email protected]" });

if (window.AffiliateBase.referral) {
  console.log("Affiliate:", window.AffiliateBase.affiliate?.name);
}

Browser Support

  • Chrome/Edge (last 2 versions)
  • Firefox (last 2 versions)
  • Safari (last 2 versions)
  • iOS Safari (last 2 versions)

License

MIT

Links