Documentation

MacroSession records visits to your web app as replays you can watch, tracks page views and the events you name, and flags the sessions where people hit rage clicks or JavaScript errors — all from one script.

Quickstart

  1. Create an account. You get a project with a public key (ms_…).
  2. Under Install, copy the two tags into the <head> of every page of your app. The page has the exact steps for Next.js, Vite, Google Tag Manager, WordPress, Shopify and Webflow, and a prompt that has your coding agent (Claude Code, Cursor, Copilot) do it all, identify() included.
  3. Visit your app. The Install page turns green as soon as your visit arrives, and the visit is in Sessions.
<script>
  !function(w){var m=w.MacroSession=w.MacroSession||{q:[]};["identify","track","page","reset","optOut","optIn"].forEach(function(f){m[f]=m[f]||function(){m.q.push([f,[].slice.call(arguments)])}})}(window);
</script>
<script async src="https://macrosession.com/s.js" data-ms-key="ms_YOUR_PUBLIC_KEY"></script>

The first tag is a tiny stub: it defines window.MacroSession straight away and queues any calls made before the script arrives, so an identify() during your app's boot is never lost. The second loads the script asynchronously — it never blocks your page. Single-page apps need nothing extra: route changes are picked up from the History API.

What is captured

  • The replay — the page's structure and every change to it, mouse movement, scrolling and clicks, recorded with the open-source rrweb recorder. It is rebuilt in the player, not filmed, so it is small to send and sharp at any size.
  • Page views — every load and every route change, URL without the #fragment.
  • Clicks — a short CSS selector and the visible label of what was clicked (never text from inputs), and where inside that element the click landed, for heatmaps.
  • Scroll depth — how far down each page view got, sent once when the page view ends.
  • Rage clicks — three or more clicks in the same spot within 0.7 seconds.
  • JavaScript errors — uncaught errors and unhandled promise rejections, message only.
  • Session details — browser, OS and device class, screen size, language, referrer and UTM parameters.

A session is one browser tab. It survives reloads and ends after 30 minutes without activity. The script batches everything and sends it every five seconds, compressed, and once more when the page is hidden.

Identifying users

Call identify() once you know who is signed in. Their sessions then carry a name, and every session of theirs — on any device — is linked.

MacroSession.identify("user_123", { email: "ana@acme.com", plan: "pro" });

Use the id your own database gives the user, not their email: emails change, and a changed id splits one person into two. A whole number works as is (identify(42)); a string may use letters, digits and _ . : @ + -, up to 128 characters, so a UUID is fine. An id outside those rules is ignored with a warning in the browser console, and the visit is still recorded, anonymously. Traits are flat: strings, numbers, booleans or null, up to 25 of them. Call MacroSession.reset() on sign-out so the next person on the same browser starts a fresh session.

Tracking events

MacroSession.track("Order Completed", { total: 42, currency: "USD" });

Names are 1–64 characters of letters, digits, spaces and _ . : / -. Properties follow the same rules as traits. Each event appears on the Events page — with who did it and a link that opens their replay at that moment — and in the session's timeline. The shape matches Segment's track call, so existing tracking plans carry over.

Heatmaps

Heatmaps shows, for each page, where visitors click and how far down they scroll, split by desktop, tablet and mobile (by the width of the visitor's window) over the last 7 or 30 days. The numbers come from every visit, including sessions that were not recorded; the picture they are drawn on is a recent recorded visit of the same page, rebuilt from its replay.

A click is kept as a position inside the element that was clicked, not as a point on the page, so it lands on the same button when the layout differs between visits. Clicks on elements the chosen recording doesn't show (a menu that was closed, content that has since changed) are counted and listed under Most clicked, but not drawn. Heatmaps are kept per path: query strings are ignored, so /pricing?plan=pro counts as /pricing.

Privacy controls

Every form input is masked in the browser, before anything is sent: the replay shows asterisks, and click labels never include what was typed. Beyond that:

  • class="ms-block" — the element is never recorded; it plays back as an empty box of the same size.
  • class="ms-mask" — the element is recorded, but its text becomes asterisks.
  • class="ms-ignore" — interactions with the element are not captured.
  • Settings → Recording & privacy — mask all text project-wide, add a CSS selector that is never recorded, record only a percentage of sessions, or turn replays off and keep analytics.

Sensitive query parameters (anything named like token, password, secret, code, key, auth,session or email) are redacted from every stored URL. For consent banners, MacroSession.optOut() stops all recording and sending in that browser until optIn().

JavaScript API

MacroSession.identify(userId, traits?)   // name the person in this browser
MacroSession.track(name, properties?)    // a custom event
MacroSession.page()                      // a page view (automatic; for unusual routers)
MacroSession.reset()                     // on sign-out: new anonymous id and session
MacroSession.optOut()                    // record and send nothing in this browser
MacroSession.optIn()                     // undo optOut()

Server API

Authenticate with your project's secret key (mss_…, created under Settings → Keys). It is shown once and stored only as a hash. Never put it in a browser.

Use it for what happens away from the browser, against the same user id you pass to identify(), so it lands on that person's history next to their sessions: a payment clears, an import finishes, a webhook fires. It is also how to see what someone does through your REST API or what their AI agent does through your MCP server, which the browser script never sees. Send the actions that matter rather than every request: the limit is 600 events a minute per project.

Track an event

POST https://macrosession.com/api/v1/events
Authorization: Bearer mss_...
Content-Type: application/json

{ "userId": "user_123", "event": "Invoice Paid", "properties": { "amount": 49 } }
  • userId (required): the id you pass to identify(), a whole number or up to 128 letters, digits and _ . : @ + -.
  • event (required): 1 to 64 characters, starting with a letter or digit, then letters, digits, spaces and _ . : / -. Same rules as track().
  • properties (optional): up to 25 flat values, each a string, number, boolean or null.
  • timestamp (optional): ISO 8601. Backdates the event by up to a day; a time more than a day old, or more than five minutes ahead, is recorded as now.

A success returns 200 with { "ok": true }. Server events have no session, so they have no replay.

From Node or Python

// Node 18+
await fetch("https://macrosession.com/api/v1/events", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.MACROSESSION_SECRET_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ userId: user.id, event: "Invoice Paid", properties: { amount: 49 } }),
});
# Python
import os, requests

requests.post(
    "https://macrosession.com/api/v1/events",
    headers={"Authorization": f"Bearer {os.environ['MACROSESSION_SECRET_KEY']}"},
    json={"userId": user.id, "event": "Invoice Paid", "properties": {"amount": 49}},
    timeout=5,
)

For an MCP tool call or an API request, name the event after what was done and keep the details in properties, for example { "event": "MCP: create_article", "properties": { "client": "claude", "ok": true, "ms": 840 } }. Send it after the response, and don't let a failed send fail the request it describes.

List a user's sessions

GET https://macrosession.com/api/v1/sessions?userId=user_123&limit=20
Authorization: Bearer mss_...

{ "data": [ { "id": "…", "startedAt": "2026-10-11T12:00:00.000Z", "durationMs": 81000,
              "pages": 4, "errors": 0, "rageClicks": 1, "entryUrl": "https://app.acme.com/",
              "hasReplay": true, "url": "https://macrosession.com/app/sessions/…" } ] }

Put the url next to a support ticket: anyone signed in to your MacroSession account opens the replay in one click.

Activation by signup week

GET https://macrosession.com/api/v1/activation?event=course_published&within=7&from=2026-09-01&to=2026-10-31
Authorization: Bearer mss_...

{ "event": "course_published", "withinDays": 7, "from": "2026-09-01", "to": "2026-10-31", "truncated": false,
  "cohorts": [ { "week": "2026-09-07", "users": 120, "activated": 54, "pending": 0 } ] }

Of the identified users first seen each week (weeks start Monday, UTC), how many sent event — from the browser's track() or from your server — within within days (1–90, default 7). Users whose window is still open and who haven't done it yet are pending, not failures. from and to are inclusive dates and default to the last 12 weeks; a range can span up to a year.

Retention by signup week

GET https://macrosession.com/api/v1/retention?from=2026-09-01&to=2026-10-31
Authorization: Bearer mss_...

{ "weeks": [1, 4, 8], "from": "2026-09-01", "to": "2026-10-31", "truncated": false,
  "cohorts": [ { "week": "2026-09-07", "users": 120,
                 "returned": { "1": { "eligible": 120, "returned": 61 }, "4": { "eligible": 120, "returned": 38 },
                               "8": { "eligible": 0, "returned": 0 } } } ] }

Week 1 is days 7–13 after a user was first seen, week 4 days 28–34, week 8 days 56–62. A user counts toward a week only once it has fully passed (eligible). Both reads return counts only, never who, and allow 30 requests a minute per project.

Errors

Every endpoint answers errors as { "error": { "type", "message" } }: 401 for a missing or wrong secret key, 422 for a field that breaks the rules above (the message names it). Sending events also answers 429 past 600 a minute per project, with a Retry-After header.

Limits & retention

  • Sessions, replays, events and heatmaps are kept for 30 days, then deleted. Event-name totals are kept while the project exists.
  • For activation and retention, each identified user also has a small activity record — first seen, the weeks they were active, and the first time of each event name — kept for 400 days after their last activity. It holds ids and times, never pages, properties or recordings.
  • Up to 5,000 recorded sessions per project per day while in beta. Past that, page views and events are still counted; new sessions are not recorded until the next day (UTC).
  • A single session stops growing its replay at 40 MB of recording data; its events keep counting.
  • Set Allowed origins in Settings once you are live, so your public key only works on your own domains.