Browse documentation

Browser referral capture — API/SDK advanced

Capture link references and manual codes for the API/SDK advanced path without exposing credentials or coupling attribution to analytics.

Updated August 3, 2026

Browser referral capture is only for API/SDK advanced integrations. The browser entry point of @affihq/sdk stores only an opaque reference and capture dates. It makes no authenticated request and includes no server cryptography.

In Stripe automatic mode, native /r/ records the click and redirects directly to the selected Payment Link; no SDK browser capture is required.

import { readReferralFromUrl, storeReferral } from '@affihq/sdk/browser'

const reference = readReferralFromUrl(window.location.href)

if (reference) {
  storeReferral(reference, {
    enabled: attributionStorageAllowed,
    maxAgeDays: 90,
  })
}

Set enabled from your application’s attribution-storage policy. Affiliate attribution may have a different purpose from analytics; apply the consent and storage rules for the customer’s jurisdiction before storing the reference.

Resolve a manual code

import { chooseReferral, loadReferral } from '@affihq/sdk/browser'

const referral = chooseReferral({
  manualCode: form.partnerCode,
  storedReference: loadReferral()?.reference,
})

A manually entered code wins over a stored link at this point. Neither can replace an attribution your server has already locked.

Storage behavior

The default cookie is SameSite=Lax, becomes Secure on HTTPS and expires after the configured attribution window. Supply a custom ReferralStorage implementation if your application needs another storage mechanism.

Do not store affiliate rates, customer emails, discounts or API responses in this cookie.