Getting started
Quickstart
End to end: create a key, install the tracker, and report a sale. About ten minutes.
1. Create an API key
In the agency console, open your program's Settings and create an API key. Give it both read and write scope — reporting conversions needs write.
2. Find your program id
Every data endpoint is nested under a program id. Your key already knows which program it belongs to; ask it:
curl https://app.smoothprofit.app/api/v1/me \
-H "Authorization: Bearer sp_live_your_key"Cache program.id from the response. It never changes for that key.
3. Install the tracker
Add one script tag to your storefront, before </body>. It reads ?ref= off the landing URL, records the click, and stores the attribution in a first-party cookie for 60 days.
<script
src="https://app.smoothprofit.app/tracker/smoothprofit.js"
data-program="peakcare"
data-api-base="https://app.smoothprofit.app"
data-cookie-domain=".peakcare.health"
async
></script>Set data-cookie-domain to your registrable domain with a leading dot if checkout lives on a subdomain — without it the cookie is host-only and attribution is lost on the hop to checkout.
4. Report the sale
When an order is paid, read the sp_ref cookie server-side and post the conversion. Reading it on the server rather than passing it through your checkout UI means attribution works no matter which flow started the order.
const attribution = JSON.parse(cookies().get("sp_ref")?.value ?? "{}");
await fetch("https://app.smoothprofit.app/api/v1/conversions", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${process.env.SMOOTHPROFIT_API_KEY}`,
},
body: JSON.stringify({
orderId: order.id,
orderAmountCents: order.totalCents,
clickId: attribution.clickId,
referralCode: attribution.referralCode,
customerEmail: order.customerEmail,
externalProductId: order.productId,
}),
});5. Confirm it landed
curl "https://app.smoothprofit.app/api/v1/programs/$PROGRAM_ID/dashboard-summary" \
-H "Authorization: Bearer sp_live_your_key"sales.total should have gone up by one, and the affiliate's commission appears as pending until its holding period elapses and the agency approves it.
POST /v1/conversions/clawback so the commission is reversed rather than paid out on a sale that no longer exists.