Install + identify
The SDK does three things: track page loads (which capture ?ref= and refresh the cookie),
identify users when they sign up or log in, and emit revenue events.
Install
npm install @openpartner/sdkimport { OpenPartner } from '@openpartner/sdk';
export const op = new OpenPartner({ siteId: 'site_xxx', // optional: override the router URL for self-hosted deploys routerUrl: 'https://r.yourdomain.com',});The SDK ships ESM (dist/browser.js) and CJS (dist/browser.cjs) bundles. Both work with
any modern bundler — Vite, webpack, esbuild, Next.js, Remix, Nuxt, etc.
Track
Call once on every page load. It reads ?ref= from the URL, drops or refreshes the
first-party cookie, and is safe to call multiple times.
op.track();Identify
Call when a user signs up or logs in. This is what stitches an authenticated user to the click that brought them in — enabling cross-device attribution and ITP-resilience on Safari.
op.identify(user.id, { email: user.email, // any traits you want to expose to the partner dashboard});You can call identify() multiple times — the same user always maps to the same Identity row,
and additional traits are merged.
Anonymous tracking
If you don’t want to expose userIds, you can identify with a hash:
op.identify(sha256(user.email + SITE_SALT));The attribution chain still works because the same hash is reproducible across sessions.