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 🙏

© 2025 – Pkg Stats / Ryan Hefner

affiliatebase-tracking

v1.0.1

Published

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

Downloads

180

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
  • 0️⃣ Zero dependencies, pure JavaScript (~26KB)

Installation

Via npm

npm install affiliatebase-tracking
# or
pnpm add affiliatebase-tracking
# or
yarn add affiliatebase-tracking

Via CDN

<!-- Async loader (recommended) -->
<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>

Usage

Basic Tracking

// Track conversion after signup/purchase
affiliatebase('convert', { email: '[email protected]' });

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

// Execute code when loaded
affiliatebase('ready', () => {
  console.log('Referral:', window.AffiliateBase.referral);
});

TypeScript Support

import 'affiliatebase-tracking';

// Full type safety
affiliatebase('convert', { email: '[email protected]' });

if (window.AffiliateBase.referral) {
  console.log('Referred by:', window.AffiliateBase.affiliate?.name);
}

Automatic Stripe Integration

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

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

Form Integration

<!-- Automatic -->
<form data-affiliatebase="true">
  <input type="email" name="email">
  <button>Submit</button>
  <!-- Hidden referral input auto-injected -->
</form>

<!-- Manual -->
<script>
affiliatebase('ready', () => {
  window.AffiliateBase.Forms.add(document.getElementById('signup-form'));
});
</script>

API Reference

Methods

affiliatebase('convert', data)

Track conversion event (signup, purchase, etc.)

Parameters:

  • data.email (required): Customer email
  • data.*: Additional metadata

Example:

affiliatebase('convert', {
  email: '[email protected]',
  value: 99.99,
  plan: 'pro'
});

affiliatebase('source', token)

Force attribution to specific affiliate token

Parameters:

  • token (required): Affiliate link token

Example:

affiliatebase('source', 'affiliate_abc123');

affiliatebase('ready', callback)

Execute callback when script loaded

Parameters:

  • callback (required): Function to execute

Example:

affiliatebase('ready', () => {
  console.log('Tracking initialized');
});

Global Objects

window.AffiliateBase

Main tracking object with attribution state

Properties:

  • config: Configuration (apiUrl, orgId, debug, loaded)
  • referral: Current referral ID (UUID) or empty string
  • affiliate: Affiliate object or false
  • campaign: Campaign object or false
  • coupon: Coupon object or false

Example:

if (window.AffiliateBase.referral) {
  console.log('Referred by:', window.AffiliateBase.affiliate.name);
  console.log('Campaign:', window.AffiliateBase.campaign.name);
  console.log('Commission:', window.AffiliateBase.campaign.commission_value);
}

Configuration

Script Tag Attributes

<script
  src="https://cdn.jsdelivr.net/npm/@affiliatebase/tracking@1/src/index.js"
  data-org-id="YOUR_ORG_ID"              <!-- Required -->
  data-debug="true"                      <!-- Optional: logging -->
  data-affiliatebase-params="partner"    <!-- Optional: custom params -->
></script>

URL Parameters

Automatically detected:

  • ?via=TOKEN (primary)
  • ?ref=TOKEN
  • ?affiliate=TOKEN
  • ?a=TOKEN
  • ?referral=ID (preload existing)
  • Custom parameters via data-affiliatebase-params

Example:

https://yoursite.com?via=john123
https://yoursite.com?ref=partner&promo=SALE20

Events

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

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

Advanced Usage

Cross-Domain Link Tagging

// Automatically tag links to specified domains
affiliatebase('ready', () => {
  window.AffiliateBase.CrossDomainLinks.attach('example.com,partner.com');
});

Manual Stripe Integration

affiliatebase('ready', () => {
  // Attach Stripe Buy Buttons
  window.AffiliateBase.StripeBuyButtons.attach();

  // Attach Stripe Pricing Tables
  window.AffiliateBase.StripePricingTables.attach();

  // Attach Payment Links
  window.AffiliateBase.PaymentLinks.attach();
});

Attach All Integrations

affiliatebase('ready', () => {
  // Attach everything at once
  window.AffiliateBase.attachAll('example.com,partner.com');
});

Browser Support

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

License

MIT

Links