# Configure the JavaScript tag

All settings on this page are managed from the **Frontend** tab in your application's settings. Changes take effect immediately. No redeployment required!

## What should we collect?

Toggle individual collection features on or off:

| Feature | Description |
|---|---|
| **Collect frontend errors** | Unhandled exceptions and promise rejections. |
| **Record web vitals** | Core Web Vitals (LCP, FID, CLS) and other performance metrics. |
| **Collect console.logs** | `console.log`, `console.warn`, and `console.error` output. |
| **Record JS heap memory** | JavaScript heap memory usage (Chrome only). |
| **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. See [Session replays](#session-replays) below. |
| **Auto-capture identified user events** | Interactions for users identified with `betterstack('user', ...)`. See [Identify users](https://betterstack.com/docs/errors/js-tag/install/#identify-users). |
| **Collect browser fingerprint** | Browser fingerprint for cross-session user identification. |

All features are enabled by default.

## Sampling

Three independent sampling rates control how much data the JS tag collects:

| Setting | What it controls | Default |
|---|---|---|
| Sampling of errors | Percentage of frontend errors captured | 100% |
| Sampling of session replays | Percentage of sessions with replay recording | 100% |
| Sampling of web events | Percentage of sessions that track analytics and autocapture events | 100% |

Sampling is **per-session**, not per-event. When a new session starts, a random roll determines whether that session will track web events, session replays, and errors. All events within a sampled-in session are captured; all events in a sampled-out session are dropped.

Error sampling is applied independently: a session can capture errors but not web events, or vice versa.

## Data retention

Web events retention controls how long captured events are stored before automatic removal. Configurable in the Frontend tab.

## Session replays

Session replays record DOM changes during a user's session, letting you visually replay exactly what they saw and did.

- **Enable:** Toggle **Record session replays** in the collection settings.
- **Sampling:** Configurable under **Sampling of session replays**. Default is 100%. Decided per-session: if selected, the entire session is recorded.
- **Error context:** Replays are linked to captured errors. When reviewing an error, you can watch the replay to see what led to it.

## Exclude HTML elements

Exclude specific elements from both session replay recording and autocapture. Useful for sensitive content like password fields or personal data.

Enter CSS selectors under **Exclude HTML elements**:

```
[label Exclude elements from data collection]
input[type=password]
.sensitive-data
#credit-card-form
```

Matching elements are:

- **Blocked in replays**: replaced with a placeholder in the recorded DOM.
- **Excluded from autocapture**: clicks and form interactions on these elements are not tracked.

## Custom configuration

JavaScript code entered here runs when the tag loads. This is equivalent to calling `betterstack('config', ...)` in your application code (see [Installation — Custom configuration](https://betterstack.com/docs/errors/js-tag/install/#custom-configuration)), but managed remotely.

Example, the placeholder shown in the UI:

```javascript
[label Customize configuration]
betterstack('config', {
  environment: 'production',
});
```

Use this to set `environment`, `release`, or pass advanced error tracking options without modifying your deployed code.

## Sessions

A session groups all user activity within a continuous browsing window.

**Session timeout in minutes:** Sessions expire after a configurable period of inactivity. Default is **30**. After the timeout elapses with no interaction, the next user action starts a new session.

Session data is stored in the browser's `localStorage` under the `_bs` key: session ID, anonymous user ID, last activity timestamp, and sampling decisions.

At session start, the JS tag captures attribution data automatically:

- UTM parameters (`utm_source`, `utm_medium`, `utm_campaign`, `utm_term`, `utm_content`)
- Referrer URL
- Ad click IDs (`gclid`, `fbclid`, `msclkid`, `ttclid`, `li_fat_id`, `twclid`)
- Current page URL

This data is sent with the `session-start` event and available for querying.

## Batching

Events are batched in memory before sending to reduce network requests.

**Send events at most every N seconds:** Default is **1**. Events are flushed at this interval.

Events are also flushed immediately when the page becomes hidden (tab switch, minimize) or on `pagehide`, ensuring no data is lost when the user navigates away. Events are sent as newline-delimited JSON (`application/x-ndjson`).

## Next steps

- [Installation](https://betterstack.com/docs/errors/js-tag/install/): snippet, init options, identifying users, tracking custom events.
- [Getting started](https://betterstack.com/docs/errors/js-tag/start/): overview and prerequisites.
- [Events reference](https://betterstack.com/docs/errors/js-tag/events/): full schema of all captured events.
