When to track server-side
Reach for server-side reporting when the conversion doesn’t happen in the browser that clicked the affiliate link, or when you can’t trust a browser to report it at all:- Server-rendered or off-site checkouts. The purchase completes on a payment page you don’t control, or the confirmation page never loads a script.
- Mobile and native apps. There’s no browser to run the tracking snippet at the point of purchase.
- Subscriptions and renewals. The first payment happens in a browser, but every renewal after that is billed by your system with nobody watching.
- Ad blockers and privacy settings. A share of visitors will never execute a client-side conversion call. A server call always lands.
- Payment providers without a Referly integration. You already receive a webhook from your provider — forward it to Referly.
- Conversions your team creates. Sales closed by a salesperson, invoices raised manually, or upgrades applied from your own admin panel.
- Backfills and migrations. Recording historical sales that happened before you installed tracking.
How the flow works
Server-side reporting is a three-step chain. Break any link and the sale arrives with nobody to credit.1. Capture the click identifier in the browser
The tracking snippet reads the affiliate parameter from the URL, records a click, and stores the result in the visitor’s browser. It exposes two globals once it’s finished:
Both are also persisted under
PROGRAM_ID_affiliate_referral and PROGRAM_ID_affiliate_ref in cookies, with a localStorage fallback, for the length of your cookie window.
The snippet works asynchronously, so read the globals after the tracker signals that it’s ready rather than on page load:
2. Store it against your user
When someone signs up, send the click ID to your backend along with the rest of the sign-up form and save it on your user, customer, or subscription record. This is the step teams skip, and it’s the one that matters — a renewal billed eight months later has no browser and no cookie to fall back on. The only reason you can still credit the affiliate is that you wrote the click ID down. Store it as an opaque string. Don’t parse it or assume anything about its format.3. Report the conversion from your server
When the payment succeeds, POST the sale to the Referly API with the stored identifier:Identifiers Referly accepts
A sale has to name the affiliate somehow. Send one of these:
A few things worth knowing:
- The click ID is the most precise option. It ties the sale to one specific visit, which keeps the click, referral, and sale connected in your reports.
- Matching on
emailonly works if a referral with that email already exists in your program. If it doesn’t, the sale has nothing to attach to. - If none of the identifiers resolve to an affiliate, the request does not create a commission. Attribution is never guessed.
totalEarned is always required, as are the customer’s email and name — either sent directly or already present on the referral you matched.
Authentication
Every server-side call carries an API key as a Bearer token:403.
Generate an API key
Create a key and authorise your requests.
How this fits with the platform integrations
Referly’s payment integrations are themselves server-side — the difference is that Referly runs them for you.Don’t send the same sale twice
Networks time out, webhooks retry, and queues replay. Referly deduplicates on the external identifiers you supply —externalId for your own sale or transaction reference, externalInvoiceId for the invoice or charge from your payment provider. A retry carrying an identifier Referly has already seen for that affiliate is recognised and does not create a second commission.
Send them on every request. Without an external identifier, Referly has nothing to compare against and a retried call becomes a duplicate sale.
Idempotency
Retry safely without creating duplicate sales.
Related
Report a sale
Every field on the sales endpoint, with examples.
Capture endpoints
The public endpoints the tracking script calls.
Install the snippet
Where the click ID you’ll store comes from.
Webhooks
Receive events back from Referly when a sale is recorded.