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

@linkzly/affiliate-web

v1.0.0

Published

Lightweight browser SDK for Linkzly affiliate attribution tracking (<3KB gzipped)

Readme

@linkzly/affiliate-web

Lightweight browser SDK for Linkzly affiliate attribution tracking. < 3KB gzipped.

Installation

npm install @linkzly/affiliate-web

Or via CDN (UMD):

<script src="https://cdn.linkzly.com/affiliate-web/latest/index.js"></script>

Quick Start

import { init, getClickId, attachToCheckout } from '@linkzly/affiliate-web';

// Initialize (optional — auto-initializes on first call)
init({ debug: true });

// Get click ID for your backend
const clickId = getClickId();

// Attach to checkout form
attachToCheckout('#checkout-form');

How It Works

When a user clicks an affiliate link (/a/:slug), the Linkzly tracking worker:

  1. Sets an lz_aff cookie with signed attribution data
  2. Appends lz_click_id to the destination URL

This SDK reads both sources and provides the attribution data to your frontend.

API Reference

init(config?)

Initialize the SDK singleton.

const lz = init({
  cookieName: 'lz_aff',       // default
  clickIdParam: 'lz_click_id', // default
  debug: false,                 // default
});

getAttribution()

Returns full attribution data:

const attr = getAttribution();
// {
//   clickId: '019...',
//   programId: '019...',
//   affiliateId: '019...',
//   timestamp: 1707300000,
//   hasAttribution: true,
//   source: 'both' | 'cookie' | 'url' | 'none'
// }

getClickId()

Returns just the click ID (most common use case):

const clickId = getClickId();
// Pass to your backend for S2S conversion

getCookieId()

Returns the raw lz_aff cookie value:

const cookieId = getCookieId();

attachToCheckout(form)

Injects hidden lz_click_id and lz_cookie_id fields into a form:

attachToCheckout('#checkout-form');
// or
attachToCheckout(document.getElementById('checkout-form'));

buildConversionPayload(order)

Builds a conversion payload with attribution data included:

const payload = buildConversionPayload({
  order_id: 'ORD-123',
  order_value: 99.99,
  currency: 'USD',
  customer_id: 'cust_abc',
});
// Send payload to your backend → your backend sends to Linkzly S2S API

getAttributionHeaders()

Returns attribution data as HTTP headers for fetch/XHR:

const lz = init();
fetch('/api/checkout', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    ...lz.getAttributionHeaders(),
  },
  body: JSON.stringify(orderData),
});

Integration Examples

Next.js / React

import { useEffect, useState } from 'react';
import { init, getAttribution } from '@linkzly/affiliate-web';

export function CheckoutPage() {
  const [attribution, setAttribution] = useState(null);

  useEffect(() => {
    const lz = init();
    setAttribution(lz.getAttribution());
  }, []);

  const handleCheckout = async (orderData) => {
    const lz = init();
    const payload = lz.buildConversionPayload({
      order_id: orderData.id,
      order_value: orderData.total,
      currency: 'USD',
    });

    await fetch('/api/conversions', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify(payload),
    });
  };

  return <button onClick={handleCheckout}>Complete Purchase</button>;
}

Vanilla JS

<form id="checkout-form" action="/api/checkout" method="POST">
  <input type="text" name="email" />
  <button type="submit">Pay Now</button>
</form>

<script type="module">
  import { attachToCheckout } from '@linkzly/affiliate-web';
  attachToCheckout('#checkout-form');
</script>

SPA Support

The SDK automatically persists lz_click_id from URL parameters to sessionStorage, so attribution survives client-side navigation in SPAs (React Router, Next.js, etc.).

License

MIT