The tracking script is a singleDocumentation Index
Fetch the complete documentation index at: https://agentref.co/docs/llms.txt
Use this file to discover all available pages before exploring further.
<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
| Attribute | Values | Description |
|---|---|---|
data-debug | "true" | Enable debug logging to the browser console on every page load |
data-program | "<program-id>" | Override the program ID embedded in the ?pid= query string |
?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:| Parameter | Example |
|---|---|
utm_source | utm_source=newsletter |
utm_medium | utm_medium=email |
utm_campaign | utm_campaign=spring_launch |
utm_term | utm_term=affiliate+software |
utm_content | utm_content=cta_button |
Ad-click IDs
The script captures ad platform click IDs automatically when present:| Parameter | Platform |
|---|---|
gclid | Google Ads |
fbclid | Meta / Facebook Ads |
msclkid | Microsoft Ads |
ttclid | TikTok Ads |
li_fat_id | LinkedIn Ads |
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 | Purpose | Duration |
|---|---|---|
agentref_cid | Click token – the key for conversion matching | Program setting (default 30 days) |
agentref_src | Traffic source (e.g., script_direct, redirect) | Program setting (default 30 days) |
agentref_pid | Program ID | Program setting (default 30 days) |
agentref_vid | Anonymous visitor ID (365-day lifetime) | 365 days |
agentref_ts | Timestamp of when attribution was set | Program setting (default 30 days) |
- 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.