Before you start
- In AgentRef, set the program website to the same root domain your Next.js app serves.
- Copy the exact script snippet from
Settings -> Integration. - If you split traffic between
www.example.comandapp.example.com, install the script on both surfaces if either one can receive affiliate traffic or start checkout.
Recommended installation
- App Router
- Pages Router
Use
next/script in app/layout.tsx so the script loads once for the whole application.Checkout compatibility in Next.js
| Checkout pattern | Recommendation |
|---|---|
| Stripe Payment Links, Buy Buttons, or Pricing Tables rendered in your app | Supported directly. Keep the AgentRef script on the same page. |
| Server-created Checkout Sessions in API routes, server actions, or route handlers | Supported, but you must bridge window.AgentRef.getCheckoutMetadata() into Stripe metadata. Use the Stripe guide. |
| Checkout starts on a different root domain | First-party cookies will not carry across roots. Move the flow onto one root or build a server-side handoff intentionally. |
Consent, CSP, and multi-domain notes
- If you use a cookie banner, call
window.AgentRef.setConsent('granted')after the visitor accepts tracking. See Consent and GDPR. - If you use a Content Security Policy, allow
https://www.agentref.coinscript-srcandconnect-src. - If your marketing site and app live on sibling subdomains, install AgentRef on both when both can begin the journey.
Verify the installation
Troubleshooting
window.AgentRefis undefined: the script has not loaded yet. Trigger checkout only after the page is interactive.- Cookies exist on
wwwbut not in your app subdomain: install the script on both subdomains and make sure the program website points at the shared root. - Clicks are recorded but conversions are missing: your Next.js checkout path probably creates Stripe sessions server-side and still needs the Stripe metadata bridge.
Related docs
Stripe Checkout
Custom Checkout Session metadata bridge for Next.js backends.
JavaScript Snippet
Full cookie, parameter, and API behavior.
Consent and GDPR
Gate tracking until the visitor grants consent.