window, works out whether the current visitor arrived from an affiliate link, and fires an event when it has finished.
Everything on this page is available in any browser context that can see window. If you render pages on a server, call these from client-side code only, or use the server-side capture endpoints instead.
Load the script
Add the snippet to thehead of every page an affiliate might send someone to, including your checkout and thank-you pages. You can copy it with your program ID already filled in from Settings then Integrations in your Referly dashboard.
If the tag is missing
data-program-id, the script falls back to a programId query parameter on the current URL. That fallback exists for embedded and hosted checkout pages you cannot edit; on your own site, always set the attribute.
See Install the snippet for platform-specific placement.
What the script exposes
Nothing is namespaced. The names are global, so treat them as reserved on any page carrying the snippet.
Wait until tracking is ready
Because the snippet loads asynchronously and resolves the referral over the network, the functions may not exist yet when your own code runs, andwindow.affiliateId may not hold the final click ID for a few hundred milliseconds after page load.
Two rules keep you safe:
1
Guard the function before calling it
Check
typeof first, so an ad blocker or a slow network never throws inside your checkout code.2
Listen for affiliate_referral_ready before reading globals
The script fires this event once it has finished, whether or not it found a referral. It always fires, so it is a safe place to hang setup code.
affiliate_id_ready instead — it carries the referral code and click ID on its detail. Both events are documented on the Events page.
createPushLapEmail
Records a referred customer: someone who signed up, joined a waitlist, or submitted a form after arriving from an affiliate link. Use it for lead and sign-up conversions where no money changes hands yet.The customer’s email address. This is how Referly matches the person to a later sale, so use the same address your billing system will use.
The customer’s name. When you leave it out, the email address is stored as the name.
Promise. It resolves to the created referral record on success, or to null when there is no referral to credit or the request fails.
A typical form handler:
null immediately and costs nothing.
createPushLapSale
Records a sale against the affiliate who referred the visitor. Call it on your confirmation or thank-you page, after payment has actually succeeded.The buyer’s email address. Used to tie this sale to any earlier sign-up from the same person.
The sale value. Send it in the smallest currency unit —
4900 for 49.00 — and stay consistent across every call.The buyer’s name.
Your own identifier for the customer. Useful for reconciling Referly records against your database later.
Promise resolving to the created sale, or null when the visitor was not referred, when email or amount is missing, or when the request fails. The page URL at the time of the call is recorded alongside the sale.
pushLapTrackAddToCart
Records an add-to-cart event. This is a funnel signal — it shows affiliates that their traffic is engaging even before it converts — and it does not create a commission.Your identifier for the product.
Your identifier for the specific variant, where the product has more than one.
A human-readable product name, shown in reporting.
How many units were added. Non-numeric values fall back to
1.Price per unit, in the same smallest-currency-unit convention you use for sales.
Three-letter currency code, such as
USD.Where the event came from. Platform integrations set their own value; leave it alone on a custom site.
Your own session identifier, if you want to group cart events from one visit.
A stable ID of your own. Send the same value if you might retry the call, so the event is not counted twice. See idempotency.
Promise resolving to the recorded event, or null. Unlike the other two functions, this one needs a resolved click ID rather than just a referral code, so calling it before affiliate_id_ready has fired may be skipped. Wait for the event if you fire it early in the page lifecycle.
getPushLapAffiliateInfo
Reads the current referral state without touching the network. Useful for debugging, and for passing attribution data into your own checkout or analytics.The referral code from the affiliate link, such as the value of
?ref=. null when the visitor was not referred.The ID of the recorded click. This is what you attach to a sale reported from your server.
Either
cookies or localStorage. The script prefers cookies and falls back to local storage when cookies are unavailable. See Cookies and storage.affiliate_referral_ready listener rather than at the top of your script, or you may read it before the click ID exists.
Behaviour to expect
- No referral, no work. When the visitor did not arrive from an affiliate link, every function returns
nullstraight away without a network request. You can call them unconditionally. - Failures are quiet. Network errors and non-2xx responses resolve to
nullrather than rejecting, so a Referly outage cannot break your checkout. The only exception is a missing email oncreatePushLapEmail. window.affiliateIdchanges value. On a fresh click it is briefly set to the referral code before being replaced with the real click ID. Anything that persists the click ID should read it afteraffiliate_id_ready.- Nothing is queued. Calls made before the script has loaded are lost, not replayed. Guard with
typeofand, where timing is tight, wait for the ready event. - Debug logging is off by default. Turn it on for your program to see the script’s decisions in the console. See Debug mode.
Related
Events
The events the script fires, when they fire, and what they carry.
Globals
The values the script puts on the window and how to read them safely.
Install the snippet
Where to place the tag on each platform.
Report sales server-side
The more reliable way to record revenue.