JavaScript SDK
A dependency-free script (about 2 KB gzipped) that captures referral visits in a first-party cookie.
Installation
<script async src="https://YOUR-AFFLUX-HOST/sdk/v1.js"
data-key="pk_…"
data-consent="required"
data-track-pageviews
data-cookie-domain=".example.com"></script>data-key(required): the website's publishable key.data-consent="required": wait forAffllux.consent(true)before storing anything.data-track-pageviews: send a page-view event on load.data-cookie-domain: share the cookie across subdomains.
The script loads asynchronously, never blocks rendering and catches its own errors.
API
Affllux.consent(granted)— grant or revoke consent. Revoking deletes the cookie and local history.Affllux.getClickId()— current click id ornull.Affllux.getClickIds()— up to 10 recent click ids for server-side first/last-click selection.Affllux.track(name, properties)— custom analytics event (no money).Affllux.pageview()— record a page view (call on route changes in single-page apps).Affllux.diagnostics()— key, consent state, click ids and recent errors, for debugging.
Calls made before the script loads can be queued:
<script>window.Affllux = window.Affllux || { q: [] };
window.Affllux.q.push(["consent", true]);</script>Reading the click id on your server
// Next.js Route Handler / Server Action
import { cookies } from "next/headers";
const clickId = (await cookies()).get("_aff_cid")?.value;$clickId = $_COOKIE['_aff_cid'] ?? null;