Install
Tracking script
What t.js does, the JavaScript API, consent mode and calls before the script loads.
<script src="https://referralmeter.com/t.js" data-key="pk_…" async></script>One tag, under 5 KB, no dependencies. It never throws into your page and never blocks rendering.
What it does
- Reads the referral from the landing URL:
?via=,?ref=,?fpr=or?aff=carry an affiliate code;?sf_cid=carries a click id from a Referralmeter go-link (https://referralmeter.com/go/<program>/<code>). - Records the click and keeps the referral in a first-party cookie,
sf_ref, on your site's own domain (plus localStorage) for your program's attribution window (60 days unless you change it). First-click or last-click follows your program setting. - Notices visitors sent by AI assistants (ChatGPT, Perplexity, Claude, Gemini, Copilot) so you can see which customers came from them.
- Adds
client_reference_idto Stripe Payment Links, the Stripe pricing table and Buy Buttons, and fills any<input name="referralmeter_ref">in your forms.
JavaScript API
| Call | Returns | Use it for |
|---|---|---|
referralmeter.ref() | click id or affiliate code, or null | Pass to checkout as metadata.referralmeter_ref |
referralmeter.code() | the affiliate's code, or null | Showing "referred by …" or a discount |
referralmeter.signup(email, { uid }) | Promise<{ ok }> | Right after signup. Does nothing when the visitor has no referral |
referralmeter.ready(cb?) | Promise | Run code once the referral is known |
referralmeter.consent() | — | Start tracking after the visitor accepts (consent mode) |
Consent mode
Add data-consent="required" to the tag. Until you call referralmeter.consent(), the script reads nothing, writes nothing and makes no request.
<script src="https://referralmeter.com/t.js" data-key="pk_…" data-consent="required" async></script>Calling it before it has loaded
The tag is async, so your code may run first. Optional chaining (window.referralmeter?.signup(…)) is enough in most apps. If signup can happen in the first second of a visit, paste this stub above the tag. Calls to signup(), ready() and consent() made before load are queued and replayed; ref() and code() return null until the script has loaded.
<script>!function(w){var s=w.referralmeter=w.referralmeter||{q:[]};["signup","ready","consent"].forEach(function(m){s[m]=s[m]||function(){var a=arguments;return new Promise(function(r){s.q.push([m,a,r])})}});s.ref=s.ref||function(){return null};s.code=s.code||function(){return null}}(window)</script>Where the tag goes
| Stack | Place it in |
|---|---|
| Next.js | app/layout.tsx (or pages/_document.tsx), inside <head> |
| React SPA / Vite | index.html, inside <head> |
| Remix / React Router | app/root.tsx, inside <head> |
| Astro | your base layout, with is:inline |
| SvelteKit | src/app.html |
| Plain HTML | every page a visitor can land on |
Ad blockers
A blocked script can't record the click. Everything after it is server-side: the referral rides through your billing provider's checkout metadata and comes back on its signed webhook. If you want signups recorded even when the script is blocked, also report them from your server with POST /api/v1/referrals.