Install the Better Stack JavaScript tag to start collecting real user monitoring data: website analytics, web vitals, session replays, user events, and frontend errors. Install the snippet once. All collection features are managed remotely from the Better Stack UI, no redeploys needed.
<script> tag.</head> tag on every page you want to monitor:
The snippet loads asynchronously and won't block page rendering. You never need to update it, as the remote script is always generated with your latest configuration.
The betterstack('init', opts) call starts data collection. You can pass the following options:
| Option | Type | Default | Description |
|---|---|---|---|
environment |
string |
undefined |
Environment name, e.g. 'production' or 'staging'. |
release |
string |
undefined |
App version or release identifier. |
autoPageview |
boolean |
true |
Automatically track page views. Set to false to track navigation manually. |
debug |
boolean |
false |
Log internal activity to the browser console. Useful during development. |
All collection features are enabled out of the box. Each can be toggled individually in the Frontend tab, see Configure the JavaScript tag.
| Feature | Description |
|---|---|
| Collect frontend errors | Unhandled exceptions and promise rejections. |
| Record web vitals | Performance metrics like TTFB, FCP, and LCP. |
| Collect console.logs | console.log, console.warn, and console.error output. |
| Record JS heap memory (Chrome) | JavaScript heap memory usage. |
| Record website analytics | Page views, page leaves, and navigation events. |
| Auto-capture anonymous user events | Clicks, form submissions, and rage clicks for anonymous visitors. |
| Record session replays | DOM changes replayed visually. |
| Auto-capture identified user events | Interactions for users identified with betterstack('user', ...). |
| Collect browser fingerprint | Browser fingerprint for cross-session user identification. |
Page views are tracked automatically. To send them yourself, set autoPageview: false in init, then track a page view on each navigation with betterstack('track', ...):
Use 'page-change' for in-app navigation in single-page applications, and 'page-leave' when the visitor leaves the page.
Use betterstack('track', eventName, data) to send custom events with an arbitrary payload:
Events appear in Events and can be used in event funnels and dashboards. The full event schema is documented in JavaScript tag events.
We use cookies to authenticate users, improve the product user experience, and for personalized ads. Learn more.