Skip to main content
The tracking script is a single <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

Add the snippet to your <head> on every page, or in a shared layout template:
Replace 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

You can also trigger debug mode without touching the script tag by adding ?agentref_debug=1 to any URL on your site.

URL parameters

Referral parameter (via)

Generated AgentRef links use the via URL parameter by default:
Inbound attribution always accepts 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:
Sub-IDs are stored with the click record and appear in conversion data returned to the affiliate via the API.

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.com so they persist across subdomains (www, app, checkout).
  • SameSite=Lax. Compatible with standard browser security policies. Secure flag 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.

AgentRef.getDebugInfo()

Returns a diagnostic snapshot. See Debug Mode for details.