ReferralMath offers two ways to track affiliate referrals: a drop-in JavaScript tag and a server-to-server REST API. Both are production-ready. The right choice depends on your stack, your accuracy requirements, and how much control you need.
The JavaScript tag is a single script you add to your site. It handles everything client-side.
<script src="https://tag.referralmath.com/tag.js"
data-program="your-program" async></script>
- Reads the referral code from the URL query parameter (e.g.,
?ref=abc)
- Sets a first-party cookie to persist attribution across sessions
- Tracks impressions when the page loads
- Tracks clicks when the referral link is first visited
- Fires conversion events via a JavaScript call when a purchase or signup happens
- Zero backend work — just paste the script tag
- Works with any stack — static sites, WordPress, Shopify, SPAs
- Automatic cookie management — handles attribution window for you
- Live in minutes — no deployment needed beyond adding the tag
- Ad blockers can prevent the script from loading
- Client-side only — if your conversion happens server-side (e.g., webhook from Stripe), you can't fire it from the browser
- Less control over deduplication and validation
The REST API lets you report conversions directly from your backend.
curl -X POST https://api.referralmath.com/t/conversion \
-H "X-API-Key: your_key" \
-d '{"type":"payment","referral_code":"abc","amount":49.99}'
- Server-to-server communication — no browser involved
- You control when conversions are reported — after payment confirmation, after trial conversion, etc.
- Automatic deduplication — the API prevents double-counting
- API key authentication — secure and tamper-proof
- Ad-blocker proof — runs entirely server-side
- Higher accuracy — you report conversions only when you've confirmed them
- Full control — validate, enrich, and filter events before sending
- Works with webhooks — integrate with Stripe, Paddle, or any payment processor
- Requires backend work — you need to write code to call the API
- You manage the referral code — your app needs to capture and store the referral code from the URL
- Cookie attribution is your responsibility — the API doesn't set cookies
| Scenario | Recommended |
|---|
| Marketing site with a signup form | JavaScript Tag |
| SaaS with server-side payment processing | REST API |
| E-commerce with client-side checkout | JavaScript Tag |
| High-value B2B deals where accuracy is critical | REST API |
| You want to launch today with zero backend changes | JavaScript Tag |
| You need to track offline or delayed conversions | REST API |
Many ReferralMath customers use both methods together:
- JavaScript tag for click tracking and cookie-based attribution
- REST API for conversion reporting from the backend
This gives you the best of both worlds: automatic click tracking with browser cookies, plus reliable server-side conversion attribution.
The tag captures the referral code and stores it in a cookie. When the user converts, your backend reads the cookie (or the referral code you stored in your database) and reports the conversion via the API.
Both methods are available on all plans. Check out the integration docs or start your free trial to try them out.