<script> tag that handles click recording, cookie management, and Stripe surface instrumentation automatically. Add it once to your site and it works on every page.
Installation
- Plain HTML
- Next.js
- React SPA
Add the snippet to your Replace
<head> on every page, or in a shared layout template:YOUR_PROGRAM_ID with the UUID from your program’s Tracking settings page.The script is served with a 5-minute CDN cache (
Cache-Control: public, max-age=300). It is safe to load on every page – the script skips tracking if no referral parameter is present and the visitor has no existing attribution cookies.Script attributes
?agentref_debug=1 to any URL on your site.
URL parameters
Referral parameter (via)
Generated AgentRef links use the via URL parameter by default:
via, ref, r, and a. You can configure additional aliases (for example aff or partner) in your program’s tracking settings. The script checks the default parameters first, then your configured aliases, and uses the first one that has a value.
UTM parameters
All standard UTM parameters are captured and stored alongside the click record:Ad-click IDs
The script captures ad platform click IDs automatically when present:Sub-IDs
Sub-IDs let affiliates pass custom tracking data through their links for their own attribution needs. Five slots are available:Cookies
The script sets the following first-party cookies on your domain:
Cookie characteristics:
- First-party only. Cookies are set on your domain, not
agentref.co. They are not affected by third-party cookie blocking. - Root domain scoping. Cookies are scoped to
.yoursite.comso they persist across subdomains (www,app,checkout). SameSite=Lax. Compatible with standard browser security policies.Secureflag is added automatically on HTTPS sites.
DOM API (window.AgentRef)
After the script loads, window.AgentRef is available with the following methods:
AgentRef.ready(callback)
Run code after tracking has initialized. Use this when you need attribution data at checkout time:
AgentRef.getCheckoutMetadata()
Returns an object to embed in your Stripe checkout session metadata. Returns {} if no active attribution is found.
AgentRef.getState()
Returns the current runtime state of the tracker:
AgentRef.refresh()
Re-run the tracking initialization. Useful after granting cookie consent:
AgentRef.setConsent(status)
Set the user’s consent status. Pass 'granted' to enable tracking or 'denied' to clear cookies and disable tracking. See Consent & GDPR for full details.