Guides
Install the tracker
A first-party script that reads ?ref=, records the click, and keeps the attribution in a cookie until checkout.
The basic install
<script
src="https://app.smoothprofit.app/tracker/smoothprofit.js"
data-program="peakcare"
data-api-base="https://app.smoothprofit.app"
async
></script>Put it on every page a referral link can land on — including the home page, since affiliates share whatever URL they like.
Attributes
| data-program | Required. Your program's subdomain. |
| data-api-base | Required. Your SmoothProfit origin. |
| data-cookie-domain | Set to ".brand.com" so subdomains share the cookie. |
| data-cross-domains | Comma-separated hosts to decorate links and forms for. |
When checkout is on a subdomain
Cookies set without an explicit domain are host-only, so an attribution written on brand.com is invisible on checkout.brand.com. This is the single most common reason attribution silently stops working. Set the registrable domain with a leading dot:
data-cookie-domain=".brand.com"When checkout is a different domain entirely
No cookie can span two registrable domains. List the hosts and the script rewrites outbound links and form posts to carry sp_ref and sp_click; the tracker on the receiving domain adopts them without recording a duplicate click.
data-cross-domains="checkout.otherbrand.com,pay.example.com"<a> clicks and <form> submits are intercepted. A JavaScript-driven window.location = ... redirect bypasses it — read the sp_ref cookie and append the parameters yourself before redirecting.Reading the attribution
Client-side, once the script has loaded:
const attribution = window.smoothprofit?.getAttribution();
// { referralCode: "a8f2k1x9", clickId: "4b91..." } or nullServer-side, parse the sp_ref cookie. Prefer this: it works no matter which checkout flow runs, including ones you add later.
Verifying the install
- Visit any page with
?ref=and a real referral code. - Confirm an
sp_refcookie appears with both fields populated. - Confirm the affiliate's click count increments on
dashboard-summary. - Complete a test order and confirm the conversion attributes to that affiliate.