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

@afflyin/sdk

v0.0.1

Published

Official Afflyin SDK — load the affiliate tracking pixel in the browser and post conversions from your server.

Readme

@afflyin/sdk

Official SDK for Afflyin affiliate tracking. Two thin pieces:

  • Browser — a loader that injects Afflyin's hosted tracking pixel (the pixel is served from Afflyin's CDN, never bundled, so attribution fixes ship centrally without you re-deploying).
  • Server — a typed client for posting conversions from your backend.

Works in any JS app; the examples below use Next.js.

npm install @afflyin/sdk

Browser: load the pixel

The pixel auto-captures ?ref= from the landing URL and stores a first-party attribution cookie. Load it once, app-wide.

// app/layout.tsx
'use client';
import { useEffect } from 'react';
import { loadAfflyin } from '@afflyin/sdk';

export function AfflyinPixel() {
  useEffect(() => {
    loadAfflyin({ apiKey: process.env.NEXT_PUBLIC_AFFLYIN_API_KEY! });
  }, []);
  return null;
}

At checkout, read the tracking id (or referral code) and persist it on the order so you can attribute the conversion server-side:

import { getTrackingId, getReferralCode } from '@afflyin/sdk';

const trackingId = getTrackingId() ?? getReferralCode();
// save `trackingId` with the order you create

Tip: if you only persist one thing, persist the referral code. Afflyin attributes from the bare ?ref= code even when cookies and click beacons were blocked — so sending it back at conversion makes attribution survive almost anything.

Server: post the conversion

Call this from a route handler, server action, or payment webhook — at the moment your business rule says the order converted. It's idempotent on orderId, so retries are safe.

// app/api/afflyin/route.ts
import { createAfflyinClient } from '@afflyin/sdk/server';

const afflyin = createAfflyinClient({
  apiKey: process.env.AFFLYIN_API_KEY!, // server-only secret
});

export async function POST(req: Request) {
  const order = await req.json();

  const result = await afflyin.trackConversion({
    trackingId: order.afflyinRef, // the tracking id / ref code you persisted
    orderId: order.id,
    orderValue: order.total,
    currency: order.currency,
    customerEmail: order.email,
  });

  return Response.json({ attributed: result.success });
}

Signed postbacks (optional)

If your program enabled require_signed_postbacks, pass the signing secret and every conversion is HMAC-signed automatically:

const afflyin = createAfflyinClient({
  apiKey: process.env.AFFLYIN_API_KEY!,
  signingSecret: process.env.AFFLYIN_SIGNING_SECRET!,
});

The /server entry targets the Node runtime (uses node:crypto for signing). In Next.js, ensure the route is not on the Edge runtime when signing.

API

| Export | Where | Purpose | | --- | --- | --- | | loadAfflyin(opts) | browser | Inject the hosted pixel (idempotent, SSR-safe). | | getTrackingId() | browser | Read the _aff_trk / afflyin_tracking_id cookie. | | getReferralCode() | browser | Read the captured referral code. | | getReferralCodeFromUrl(search?) | browser | Parse ?ref=/?r=/… from a query string. | | createAfflyinClient(opts) | server | trackConversion() + trackClick(). |

License

MIT