What this method tracks
Once it’s set up, Referly follows a referred customer from the first click all the way through renewals and refunds.What it can’t track
Be honest with yourself about these before you launch — every one of them shows up as an unattributed sale, not as an error.- A checkout you create without the identifier. If the value is missing when the session is created, there’s nothing to attribute. Sessions created by hand in the Stripe Dashboard fall into this group.
- A buyer who switches devices. Someone who clicks the link on their phone and pays on their laptop can’t be connected — the referral is remembered in the browser that clicked.
- A buyer whose browser blocked the script, or who cleared their cookies and site data between clicking and buying.
- A purchase after the cookie window closed. Your program’s cookie duration decides how long a click stays valid. See tracking methods.
- Payments taken outside Stripe. Bank transfers or invoices you settle elsewhere never reach Referly. Add those with add a sale.
- Live payments while you’re connected in test mode, and test payments while you’re connected in live mode. Referly deliberately ignores the mismatched ones.
Before you start
A Stripe account you can log into as an administrator
Access to your site's code
Your Referly program set up
Step 1: Install the tracking script
The tracking script is what records clicks and remembers which affiliate sent each visitor. Nothing else works without it. Open Integrations from the left sidebar, find the Stripe Session API card, and select it. The guide that opens has your script already filled in with your program’s ID. Copy that snippet and paste it into thehead section of every page on your site — including your pricing page and your checkout page. It looks like this:
Check that clicks are being recorded
Visit your own site with a referral link — for exampleyour-domain.com?ref=TESTCODE, using the code of a real affiliate in your program. Then open Analytics in the left sidebar and confirm the click shows up. If it doesn’t, the script isn’t loading, and there’s no point continuing until it does. See installing the snippet for help.
Step 2: Connect your Stripe account
Connecting Stripe is what lets Referly hear about payments. You don’t create API keys and you don’t set up a webhook endpoint by hand — you authorize Referly’s app from inside Stripe, and everything is wired up for you.Open the connect dialog
Choose live or test
Authorize Referly in Stripe
Confirm the connection
Step 3: Read the referral identifier in your frontend
Once the script from Step 1 is on the page, it makes the referral identifier available to the rest of your frontend code aswindow.affiliateId.
There’s a timing detail that matters. When someone lands with a referral link, the script first sets window.affiliateId to the affiliate’s code, then swaps it for a numeric click ID as soon as it has registered the click with Referly. Both values work for attribution, but only the numeric click ID connects the sale to the exact click, which is what makes your click-to-sale reporting accurate.
So read the value at the moment the customer starts checkout, not when the page first loads. If you need to know the instant it’s ready, listen for the affiliate_id_ready event:
window.affiliateId is empty for visitors who didn’t arrive through a referral link. That’s normal — send null and Referly records the sale without an affiliate.Step 4: Attach the identifier to the Checkout Session
In your backend, put the value you just received onto the Checkout Session. Referly reads it from any of these three places, so pick whichever suits your code:Using client_reference_id
Using metadata instead
Recommended for subscriptions
For a subscription, also copy the identifier onto the subscription itself. Referly reads it when the subscription is created, which means the referral is recorded even in the rare cases where the Checkout Session event doesn’t reach it first.How free trials behave
If your plan starts with a free trial, the subscription is created but no money moves. Referly records the referral straight away, with the plan name and an Active status, and no reward yet. When the trial ends and the first payment succeeds, the sale and the commission are created then. This is usually what you want: affiliates see the trial as progress, and only get paid when it converts. If you’d rather hold rewards even longer, use the holding period.Track sign-ups before payment
By default the referral appears when checkout completes. If you want it to appear the moment someone signs up — before they’ve paid anything — create the Stripe Customer yourself at sign-up and put the identifier in the customer’s metadata:What wins when both are present
Sometimes more than one signal points at an affiliate. Referly resolves it in this order:- An affiliate’s promo code used at checkout. If the Stripe promotion code on the order belongs to one of your affiliates, that affiliate gets the sale, even if the click came from someone else. See coupons and promo codes.
- The identifier you passed on the session. The click ID or affiliate code from Steps 3 and 4.
- The customer’s email matching an existing referral. This is what makes renewals work: a renewal payment carries no click ID, so Referly matches the email to the referral created at the first purchase and pays the same affiliate again.
Step 5: Test the whole flow
Test before you send a single affiliate link out. Do it with your Stripe connection showing the yellow Test Mode badge.Switch Stripe to a sandbox
Visit your site through a referral link
your-domain.com?ref=THEIRCODE. Use a private window so you start clean.Check the identifier is there
window.affiliateId. You should get a value back. If it’s empty, go back to Step 1 — the script isn’t running.Buy something with a test card
4242 4242 4242 4242, any future expiry date, and any three-digit security code. The full list is in Stripe’s testing guide.Confirm it in Stripe
Confirm it in Referly
Go live
When your test passes:- On the Integrations page, open the Stripe panel and select Disconnect.
- Select Connect Stripe Account and authorize your live Stripe account.
- Confirm the badge is now green and reads Connected.
- Deploy your app with your live Stripe keys.
Troubleshooting
The sale is in Referly but no affiliate is attached
The sale is in Referly but no affiliate is attached
window.affiliateId before the script had set it, or the value wasn’t passed through to your backend. Log the value at the moment you create the session and check what you’re getting.Nothing appears in Referly at all
Nothing appears in Referly at all
The referral appeared but there's no reward
The referral appeared but there's no reward
The wrong affiliate got the sale
The wrong affiliate got the sale
Renewals aren't paying commission
Renewals aren't paying commission
The sale showed up late
The sale showed up late