FirstMRRHelp Center
Developers

JavaScript snippet reference

Every window.firstmrr call: measure, declare a conversion, read the origin, test a variant.

2 min read

Installation

Add this line once, in the <head> of every page, with your public key:

html
<script async src="https://firstmrr.app/app/t.js" data-key="pk_0123456789abcdef01234567"></script>

The script sends a pageview on load and on every client-side navigation (pushState, replaceState, back). Always keep ?. before the calls: nothing breaks if the script fails to load or is blocked.

track(event, options)

javascript
// Account created
window.firstmrr?.track("signup")
// First time the user does the main action of your product
window.firstmrr?.track("activation")
// Free trial started
window.firstmrr?.track("trial")
// Payment confirmed: amount in major units, the order or subscription id counts it once
window.firstmrr?.track("payment", { amount: 19.99, currency: "EUR", id: "in_1PqXyZ" })
// Subscription cancelled
window.firstmrr?.track("cancel", { id: "sub_1PqXyZ" })
// Answer to "Where did you hear about us?"
window.firstmrr?.track("source", { answer: "tiktok", account: "@oscar.wft" })
// Any other step: lower-case letters, digits and _
window.firstmrr?.track("invite_sent")
FieldTypeRequiredDescription
amountnumberOptionalpayment: the amount in major units (19.99), under 100,000.
currencystringOptionalpayment: 3-letter ISO code; EUR by default.
idstringOptionalOrder, subscription or user id: a conversion with an id is counted once, for good. Without one, it is counted once per tab and page.
answerstringOptionalsource: among tiktok, instagram, youtube, x, threads, facebook, linkedin, snapchat, pinterest, google, app_store, friend, press, other; any other value becomes other.
accountstringOptionalsource: the account the person named, 60 characters at most.

source()

Returns the tab's first origin, or null: { method, at, platform?, ref? }, with method among link, utm, in_app, referrer. Only keys that have a value are present. Save it on the user at signup, then copy it onto their payment.

javascript
const origin = window.firstmrr?.source()
// { method: "link", ref: "tiktok-oscar-3f9a", at: "2026-10-12T14:00:00Z" }

visitorId()

Returns the tab's random id (kept in sessionStorage, cleared when the tab closes), or null if the person opted out. Send it to your server with the signup or the payment, then pass it as visitor_id to the server API: the server event joins that visitor.

javascript
await fetch("/api/checkout", {
  method: "POST",
  body: JSON.stringify({ plan: "pro", fm_visitor: window.firstmrr?.visitorId() ?? null }),
})

variant(test, variant)

Declares the A/B variant shown to the visitor, before showing it. The first time in the tab, the script sends the ab:exposure event; then every event carries the assignments (4 tests at most). See A/B tests.

javascript
window.firstmrr?.variant("pricing_page", "b")

optOut() / optIn()

optOut() stops measurement in this browser (kept in localStorage) and clears the tab's origin, variants and id; optIn() turns it back on. The script also honours Global Privacy Control and Do Not Track. Put a link calling optOut() in your privacy policy.

No identify, by design

There is no identify call and no field for an e-mail, a name or an account id: FirstMRR measures visits and conversions, not people. A visitor is a hash that changes every day. To tie a payment to a video, the origin written on the payment is what counts, not the customer's identity.