Quick install
Add this script tag to every page where you want to track affiliate visits. Place it in your<head> or before the closing </body> tag:
YOUR_PROGRAM_ID with your program’s ID from the dashboard or API.
That’s it. For most setups, this single script tag handles everything.
Framework examples
What the script does
When loaded, the tracking script performs these steps automatically:-
Reads URL parameters. Checks for
ref,via, or any custom tracking parameter aliases you’ve configured. If found, this is an affiliate referral. -
Sets first-party cookies. Stores attribution data on your domain:
agentref_cid– a click identifier used for conversion matchingagentref_src– the traffic source (e.g.,link,coupon)agentref_pid– the active program ID
- Records the click. Sends a click event to AgentRef’s tracking endpoint. This appears in your analytics immediately.
-
Exposes
window.AgentRef. Provides a client-side API for reading referral metadata during checkout.
The script uses only first-party cookies on your domain. It does not use third-party cookies, fingerprinting, or local storage.
Passing metadata to Stripe
The tracking script sets cookies, but conversions are matched through Stripe metadata. How metadata reaches Stripe depends on your checkout integration:Stripe Payment Links and Buy Buttons
No additional server code needed. The tracking script automatically instruments Stripe-hosted surfaces with the click token viaclient_reference_id.
Server-created Checkout Sessions
For Checkout Sessions you create on your backend, read the metadata from the tracking script on the client side and send it to your server:Direct charges (Payment Intents)
If you create Payment Intents directly instead of using Checkout Sessions:Verify your installation
After installing the script, verify that tracking is working correctly.Browser check
- Open your website in a browser.
- Open DevTools > Network tab.
- Look for a request to
agentref.co/api/tracking/script.js– it should return200. - Visit your site through a test referral link (create one in the dashboard).
- Check DevTools > Application > Cookies for
agentref_cidandagentref_pid.
API check
Use the tracking status endpoint to verify your setup programmatically:| Field | Description |
|---|---|
stripeConnected | Whether Stripe is connected to this program. |
trackingScriptVerified | Whether the tracking script has been detected on your domain. |
websiteConfigured | Whether a landing page URL is set. |
clicksLast7Days | Click counts broken down by type (redirect, direct). |
conversionsLast30Days | Conversion counts broken down by attribution method. |
Troubleshooting
| Problem | Solution |
|---|---|
| Script returns 404 | Double-check your program ID in the pid parameter. |
| Cookies not being set | Make sure the script is loading on the same domain where users check out. Cross-domain cookies will not work. |
window.AgentRef is undefined | The script has not loaded yet. Make sure you access it after the script loads (e.g., on a button click, not immediately on page load). |
| Conversions not appearing | Verify that agentref_cid is present in your Stripe session metadata. Check Stripe’s event logs to confirm the metadata is attached. |
| Ad blockers blocking the script | The script is served from agentref.co. Some aggressive ad blockers may block it. Consider using a custom tracking domain for better reliability. |
What’s next
How Tracking Works
Deep dive into the tracking architecture, cookie mechanics, and attribution logic.
Invite Affiliates
Start recruiting affiliates to your program.