Product analytics
Track events, identity, groups, super-properties, and revenue — plus zero-instrumentation autocapture of clicks, submits, pageviews, and form interactions.
Product analytics is on by default. You get autocaptured behavior for free, and a small API for the events only you can name.
Track events#
ScaleBun.track('add_to_cart', { sku: 'A-1', price: 49.99, currency: 'USD' });ScaleBun.trackScreen('/checkout');Identify users and groups#
ScaleBun.identify('user_42', { plan: 'pro', email: 'a@b.co' });ScaleBun.group('company', 'acme', { seats: 42 }); // B2B account/workspaceScaleBun.alias('user_42'); // link to a prior idScaleBun.reset(); // logout: fresh anonymous ididentify() carries the current anonymous id, so prior activity is linked
deterministically rather than by heuristic. reset() mints a new anonymous id
and clears the user, super-properties and groups — call it on sign-out or the
next person's events are attributed to the last one.
setUser({ id, … }) is sugar over identify() for hosts that already hold a
user object.
Super-properties#
Register properties once and they attach to every subsequent event. They are persisted, and call-site properties win on conflict:
ScaleBun.register({ plan_tier: 'enterprise' });ScaleBun.unregister('plan_tier');Revenue and subscriptions#
ScaleBun.trackPurchase({ revenue: 49.99, currency: 'usd', transactionId: 'txn_9' });transactionId is the idempotency key — the server deduplicates on it, so a
retried receipt cannot double-count revenue. Use a stable value derived from the
purchase, never a fresh random one per attempt.
For recurring revenue, record lifecycle changes so MRR, ARR, churn and trials are derived from an event-sourced ledger rather than approximated from purchases:
ScaleBun.trackSubscription({ /* trial | started | renewed | plan_changed | canceled … */ });Install attribution#
ScaleBun.attribution.getInstallationId(); // stable id, seeded from the device idScaleBun.attribution.setClickId('abc123'); // for hosts running their own redirectA ?scalebun_click_id= parameter is captured automatically at init(), so the
manual setter is only needed when you own the redirect.
Autocapture#
With autocapture on (the default), the SDK captures common interactions
without any instrumentation — clicks, form submits, pageviews, element
impressions, rageclicks, and deadclicks — using delegated DOM listeners.
Opt an element (and its subtree) out with a data attribute:
<div data-scalebun-no-capture> <!-- nothing in here is autocaptured --></div>Form analytics#
Autocapture also emits $form_* events — $form_start, an enriched $submit,
$form_abandon, and $form_error — so you can see which field is costing you a
conversion. Only metadata is captured; field values are never collected.
Two lanes, one call#
track() writes to both the analytics lane (which feeds events, funnels and
retention) and the session lane (which puts the event on the session
timeline next to errors, network calls and replay frames). It also feeds Engage's
custom_event triggers.
Every event is stamped with the analytics identity and, when replay is running, the current replay coordinate — so one event carries product context and a pointer to the exact frame. That is what makes "show me the session behind this funnel drop-off" a link rather than a search.
Governance and cost#
await ScaleBun.init({ clientKey, apiBaseUrl, analytics: { plan: { /* typed tracking plan */ }, sampleRate: 1, cookieDomain: '.example.com', },});| Option | Notes |
|---|---|
plan | Client-side tracking plan — see Event naming. |
sampleRate | Per-user and deterministic, so a kept user is kept in full and funnels stay intact. Identity and revenue events are never thinned. |
cookieDomain | Share the anonymous id across sub-domains, so app., www. and shop. are one profile instead of three. |
Next#
Feature flags & experiments — target and test by cohort.
Session replay — see the session behind an event.