Attribution & Cookies
Attribution model
Affihub uses last-click attribution — the most recent partner referral link clicked before a purchase gets credit for the conversion.
How attribution is stored
When a visitor clicks a referral link (?ref=partner-slug), the tracking script stores the attribution in localStorage:
{
"ref": "partner-slug",
"program": "prog_abc123",
"ts": 1712880000000,
"landing": "/pricing"
}Key: affihub_ref
This data persists in the visitor's browser until:
- It expires (90 days from the click)
- A new
?ref=click overwrites it - The visitor clears their browser storage
90-day window
Attribution expires after 90 days. If a visitor clicks a referral link today but doesn't purchase until 91 days later, no partner gets credit.
The script checks the ts timestamp on each page load and automatically clears expired data.
Last-click behavior
If a visitor clicks multiple partner links, the most recent one wins:
| Day | Action | Attribution |
|---|---|---|
| Day 1 | Clicks ?ref=alice |
Alice |
| Day 5 | Clicks ?ref=bob |
Bob (overwrites Alice) |
| Day 10 | Visits site without ?ref |
Bob (persists) |
| Day 15 | Purchases | Bob gets the commission |
No cookies
Affihub does not use cookies for attribution. All referral data is stored in localStorage, which:
- Is scoped to your domain (first-party only)
- Is not sent with HTTP requests
- Is not accessible by third-party scripts on other domains
- Is generally not subject to cookie consent requirements
Since no cookies are involved, ad blockers that target third-party cookies do not affect Affihub attribution.
Cross-device limitations
Because localStorage is browser-specific, attribution does not carry across devices. If a visitor clicks a referral link on their phone but purchases on their laptop, the conversion won't be attributed.
This is a fundamental limitation of client-side attribution. Server-side attribution via customer email matching is not currently supported but may be added in the future.
How attribution flows to payment
At checkout, your code reads the stored attribution:
const ref = window.AffiHub.getRef();And passes it to the payment provider:
- Stripe:
client_reference_idormetadata.affihub_ref - Paddle:
custom_data.affihub_ref
When the payment webhook arrives at Affihub, the partner slug is extracted from this field and matched to a partner in your program.
Deduplication
Each transaction is identified by a unique provider_event_id:
- Stripe: The Stripe event ID (e.g.,
evt_xxx) - Paddle: The Paddle event ID
- Custom: Your transaction ID
If the same event ID is processed twice (e.g., webhook retry), the duplicate is ignored. A single transaction can only produce one commission.
Edge cases
No referral stored
If AffiHub.getRef() returns null, no referral attribution exists. The transaction proceeds normally with no commission created.
Partner not found
If the ref value doesn't match any active partner slug in your program, the webhook is processed but no commission is created. The event is still logged for debugging.
Partner deactivated
If a partner's status is deactivated at the time a webhook is processed, no commission is created even if the referral was captured when they were active.