bettermetrics is installed with a single script tag and configured with nothing. This page covers the install, custom events, journeys and funnels, the two identity modes, the data model, the endpoints and the plans.

<script defer src="https://your-app/bm.js?k=bm_pub_YOUR_KEY"></script>
The key is the project's public write key, generated when you create the project. It is write-only: it can send events and can never read them, so it is safe in a client bundle. The script is 2.5 kB gzipped and loads deferred.
| Type | When | Carries |
|---|---|---|
| pageview | Automatic, on load and on every client-side route change | path |
| error | Automatic, on uncaught errors and unhandled rejections | message |
| vital | Automatic: LCP on paint, CLS when the page is hidden | name + value in ms |
| custom | When you call bm(name, props) | name + JSON properties |
bm('signup', { plan: 'pro' })
bm('checkout_started')window.bm is defined as soon as the script runs. Properties are stored as JSON, capped at 24 keys per event. Names are free-form and show up in the dashboard grouped by name.
Name them after outcomes rather than clicks. Funnel suggestions are built around custom events, so signup produces a useful proposal where button_3_clicked does not.
Every session is kept as an ordered timeline, which is what lets the Journeys screen answer questions a counter cannot: which sequences of pages people actually follow, what share of them stop at each step, and what someone was doing in the seconds before an error.
A session is a 30-minute window per visitor. Opening one shows its whole timeline: every pageview, custom event, error and vital, with the time elapsed since the session started, plus the country, browser and referrer it came from.
The insight band at the top of that screen is on every plan. It names the page that ends the most sessions, the bounce rate and the share of sessions that hit an error, in plain sentences.
Nobody configures a funnel on a product they have just installed, so bettermetrics proposes them first. It looks for the sequences in your own sessions that end in a custom event, and builds a funnel from the entry page those people came in on.
Pin a suggestion and it becomes editable: each step is either a page view at an exact path, or a custom event by name, and steps can be added, removed or reordered.
Steps are matched in order but not necessarily back to back. Someone who detours through the documentation between the pricing page and signing up has still converted, and each step counts a session once, never a click twice.
Only the step definitions are stored. Every figure is recomputed from the sessions at read time, so editing a step re-reads the whole history rather than losing the part that came before the edit.
The tracker listens for error and unhandledrejection and records the message with the path it happened on. The Errors screen groups by message and breaks each one down by page, browser and country, with the first and last time it was seen and a handful of sessions to open.
Errors are ranked by how many people they hit, not how many times they fired. An exception inside a render loop fires a thousand times for one person and would otherwise outrank the one breaking checkout for everyone.
The visitor id is sha256(salt, project, day, ip, user agent), truncated to 32 hex characters. It rotates at midnight UTC, nothing is written to the visitor's device, and the raw ip is never stored. No cookie, no local storage, no consent banner.
The day is left out of the hash, so the id is stable across sessions and long funnels hold up. That is tracking under ePrivacy and the GDPR, so the tracker shows its own consent banner and computes nothing identifying until the visitor accepts. A refusal is remembered and never asked again on that device. Switching a project back to cookieless makes the banner disappear on its own.
Every event is one row in the events table. Each night a rollup folds the previous day into two shapes: daily_stats for the counters and the leaderboards, and sessions, one row per session holding its ordered timeline. That second table is what journeys, funnels and error context read, and it is why the dashboard stays fast once the event table is large.
| Column | Meaning |
|---|---|
| ts | When the event arrived (server time) |
| type | pageview | error | vital | fetch | custom |
| name | Custom event name, error message or vital name |
| visitor_id | Salted hash, see identity modes below |
| session_id | Derived from the visitor and a 30-minute window |
| path | Pathname only; query string and hash are stripped |
| referrer | Hostname only; self-referrals are dropped |
| country / device / browser / os | Coarse, from the CDN header and the user agent |
| value | Numeric payload: vital reading, duration, amount |
| props | JSONB, up to 24 keys per event |
A session timeline is capped at 200 steps. The pageview and error counters are taken before the cap, so a truncated timeline never produces a wrong total.
daily_stats and sessions. Bearer token, meant for a nightly cron. Idempotent: re-running it for a past day is how you backfill.We host bettermetrics for you. The free plan has no end date and asks for no card. What the paid plans add is the part that costs real storage: whole sessions, long retention and more sites.
| Plan | Sites | Events / month | History |
|---|---|---|---|
| Free | 1 | 10,000 | 30d |
| Pro | 5 | 200k | 1y |
| Business | unlimited | 2M | 3y |
Past the monthly quota, events stop being recorded until the first of the month. The endpoint keeps answering 204 and the tracker stays silent, so nothing about it is visible to your visitors. The dashboard warns you from 80% of the quota.
Full plan comparison ›bettermetrics is MIT licensed and the repository holds the whole thing: the tracker, the ingest endpoint, the schema, the rollup, the journeys and the funnels. Nothing is reserved for the hosted version and nothing phones home.
db/schema.sql, then db/rollup_function.sql, against a fresh PostgreSQL database.MOTHERBASE_SERVICE_KEY, INGEST_SALT and CRON_SECRET, then deploy the Next.js app.NEXT_PUBLIC_BM_SELF_HOSTED=true so no plan limit or upgrade prompt is applied.POST /api/rollup once a night with the bearer token.On your own copy there is no quota, no retention limit and no locked screen. Retention becomes whatever your disk and your delete schedule say.
Coming from Google Analytics? See the side-by-side comparison and the migration steps.