The tracking pipeline
How clicks are tracked
When a visitor arrives on your site through an affiliate link (e.g.,https://yoursite.com?ref=abc123), the tracking script:
-
Detects the referral parameter. The script reads the
refparameter from the URL (or any custom aliases you configure). - Records the click server-side. The script sends a request to AgentRef’s click endpoint with the referral code, page URL, UTM data, and ad-click IDs.
- Sets first-party cookies. On successful click recording, the script stores attribution data in cookies on your domain.
-
Cleans up the URL. The
refparameter is removed from the browser address bar so it doesn’t leak into bookmarks or shared links.
Cookie details
The tracking script sets the following first-party cookies on the merchant’s domain:| Cookie | Purpose | Example value |
|---|---|---|
agentref_cid | Click token for conversion matching | clk_a1b2c3d4e5 |
agentref_src | Traffic source identifier | script_direct |
agentref_pid | Program ID | 550e8400-e29b-... |
agentref_vid | Anonymous visitor ID | v_k8m2n4p6... |
agentref_ts | Timestamp of cookie creation | 1711234567890 |
- First-party only. Cookies are set on your domain (e.g.,
.yoursite.com), not a third-party domain. This means they work reliably across browsers, including Safari’s ITP restrictions. - Configurable duration. Default is 30 days. You can change this per program in your program settings.
- Root domain scoping. Cookies are scoped to your root domain, so they persist across subdomains (e.g.,
www.yoursite.comandapp.yoursite.com). - Secure attributes. On HTTPS sites, cookies include the
Secureflag. All cookies useSameSite=Lax.
Attribution logic
AgentRef uses last-click attribution – the industry-standard model for affiliate programs. When a payment comes in, AgentRef resolves the affiliate using this priority chain:| Priority | Method | How it works |
|---|---|---|
| 1 | Coupon code | If the customer used a coupon linked to an affiliate, that affiliate gets credit regardless of click history. |
| 2 | Click token | The agentref_cid from session metadata or client_reference_id is matched to the original click record. |
Coupon-based attribution always takes priority over click-based attribution. This means an affiliate with a coupon code gets credit even if the visitor originally arrived through a different affiliate’s link.
How conversions are created
Once a Stripe payment event fires, AgentRef processes it through the webhook pipeline:Webhook received
Stripe sends
checkout.session.completed (for new purchases) or invoice.paid (for subscription renewals) to AgentRef’s Connect webhook endpoint.Metadata extracted
AgentRef reads
agentref_cid, agentref_pid, and agentref_source from Stripe metadata for custom checkout flows. For hosted Stripe surfaces (Payment Links, Buy Buttons, Pricing Tables), it uses client_reference_id as the click-token anchor.Affiliate resolved
Using the attribution priority chain above, AgentRef identifies which affiliate (if any) drove the sale.
Conversion recorded
A conversion record is created with status
pending. The commission amount is calculated based on your program’s rate settings.Integration points
| Component | What it does | Required? |
|---|---|---|
| Tracking script | Captures clicks and sets cookies on your domain | Yes |
| Stripe Connect | Sends payment events to AgentRef via webhooks | Yes |
| Checkout metadata | Passes attribution cookies into Stripe sessions | Depends on checkout method |
| Consent mode | Respects GDPR consent before setting cookies | Optional |
| Server-side tracking | API-based click recording without the JS snippet | Optional |
| Debug mode | Inspect tracking state and troubleshoot issues | Optional |
What’s next
JavaScript Snippet
Install the tracking script on your site.
Stripe Checkout
Connect tracking to your Stripe checkout flow.