Skip to main content
After integrating the SDK, configure views, context, sampling, and tracing as needed. Merge the initialization examples below into your existing flashcatRum.init() configuration.

Override default RUM view names

RUM automatically creates views on page visits and SPA URL changes, normalizing path segments containing numbers to ?. For example, /dashboard/1234 and /dashboard/9a both use /dashboard/?. Enable manual tracking to define route boundaries yourself; use setViewName() if you only need to rename a view.

Configure manual view tracking

1

Enable Manual Tracking

Set trackViewsManually to true during initialization:
rum-init.js
2

Call startView Method

Call the startView method on each new page or route change:

React Router integration

RumTracker.jsx

Set view name

Use the setViewName method to update the current view’s name without starting a new view:

Control initial view Web Vitals Collection

trackWebVitals defaults to true, collecting FCP, LCP, FID, and loading time on the initial load view. These values can be inflated for prerendered pages, background tabs, or pages loaded early by a host. Set the option to false for those cases. Resources, long tasks, actions, errors, and later view events are unaffected.
rum-init.js

Enrich and control RUM data

Use beforeSend(event, context) to add context, change supported fields, or return false to discard an event before upload. The callback is synchronous and does not wait for Promises.

Context types

The second argument, context, exposes the browser objects that triggered the event:

Context size limits

Custom fields (including res and req) share the context budget. Character counts differ from UTF-8 byte counts. Do not treat 256 KiB as response-body space or rely on compression to expand collection.
Whether a request or response body can be written to event.context depends on the request type and body shape. Both only work in the synchronous beforeSend:

Add response headers to resource events

Both Fetch and XHR response headers can be read synchronously in beforeSend and written to event.context. Use the tab for your request type.
Read all headers from context.response.headers, or a single header with headers.get(name):
After reporting, open the resource event in the Explorer to see context.responseHeaders in its details:
Resource details in the Explorer, with a context field containing responseHeaders data

Resource details in the Explorer

Attach an API response body to resource context

Read a response in beforeSend and write the fields you need to event.context.res. res is a custom field; the SDK does not automatically collect response bodies. XHR and Fetch differ; use the tab for your request type.
When the request completes, an XHR JSON or JSON text response reads synchronously from xhr.response. Filter requests by API path:
XHR Blob responses require asynchronous reading and are outside this example’s scope.
After an XHR report, context.res appears in the resource details in the Explorer:
Resource details in JSON view, with a red box around the context field containing response data in res

Resource details in the Explorer

Attach an API request body to resource context

A request body is what the frontend sends, unrelated to the response. How it can be read depends on the request type; use the tab for your case. The SDK does not automatically collect request bodies.
Only when a request is sent as fetch(url, { body }) with a string body is the body kept on context.requestInit.body, the second beforeSend argument, where it can be parsed synchronously and written to event.context (for example as req). The SDK passes the original call arguments through for users to extract from.
Convert URLSearchParams first with Object.fromEntries(body.entries()). Bodies sent as fetch(new Request(...)), a Blob, a file, or a stream cannot be read synchronously.After reporting, open the resource event in the Explorer to see context.req in its details:
Resource details in the Explorer, with a context field containing req data extracted from a Fetch request body

Resource details in the Explorer

Modify RUM event content

For example, mask email addresses from view URLs:

Modifiable attributes

Discard RUM events

Return false in beforeSend to discard specific RUM events:
View events cannot be discarded.

User sessions

Set user identifiers to associate the same user’s sessions and errors in RUM.

User attributes

All fields are optional; set at least one:

User session API

After user session information changes, subsequent RUM events will contain the updated information. After logout (calling clearUser), the last view still retains user information, but subsequent views and session-level data will not.

Sampling

Set the session sampling percentage with sessionSampleRate, which defaults to 100. This example collects 90% of sessions:
By default, sessions missed by ordinary sampling do not collect page views or related telemetry. Enabling on-error capture below allows buffered data to be uploaded when an error occurs.

On-error session capture

Requires Web SDK 0.3.0 or later. Both options default to false and capture only sessions or replays missed by the corresponding sample rate. Selected sessions keep their normal collection behavior. For example, keep 20% of ordinary sessions and capture error sessions and their replays from the remainder:
  • Candidate data is buffered in memory until the first qualifying error triggers upload. History reaches back at most one minute, is not guaranteed to cover a full minute, and cannot precede SDK initialization or recording.
  • Only RUM error events trigger capture, such as JavaScript errors or addError(). Errors discarded by beforeSend, rate-limited errors, and SDK errors do not trigger it. Failed requests and HTTP 5xx resource events do not trigger it either.
  • If a sessionOnError candidate never reports an error, its events and replay are not uploaded or billed. With only sessionReplayOnError, error-free candidate replays are not uploaded or billed; normally sampled RUM sessions still are.
  • A session counts once, even after repeated errors. On-error sessions count at their actual number, without extrapolation by 1 / sessionSampleRate.
At sessionSampleRate: 100, sessionOnError has no additional effect; at sessionReplaySampleRate: 100, sessionReplayOnError has no additional effect. If sessionSampleRate is 0 and sessionOnError is off, enabling only sessionReplayOnError cannot collect any sessions. To keep only error sessions and their replays, set both sample rates to 0 and enable both on-error options.

Known limitations

You can also change both options through remote configuration.

Remote configuration

Requires Web SDK 0.4.0 or later. Set remoteConfigurationEnabled: true (default false) to override initialization values with published sampling, replay, privacy, and custom settings. Changes apply to the next new session. See Application management for supported settings and publishing steps.
To collect data only after consent, initialize trackingConsent as "not-granted", then call setTrackingConsent("granted") when the user agrees:
Consent state is not synchronized or persisted across tabs. You need to provide the user’s decision during initialization or through setTrackingConsent.

View context

You can add or modify context for the current view and its child events using these APIs:

Error context

When catching errors, you can attach local context to error objects through the dd_context property:

Global context

Global context is attached to all RUM events:

Context lifecycle

By default, global context and user information do not survive a full page refresh or share across tabs. Set storeContextsAcrossPages: true to save them in localStorage:
  • Not recommended to store personally identifiable information in context, as localStorage data persists beyond user session lifetime
  • Incompatible with trackSessionAcrossSubdomains option
  • localStorage capacity is limited to 5 MiB

Micro-frontend support

Set service and version from event call stacks in beforeSend to distinguish micro-frontends:
The following events cannot be attributed to specific sources: auto-collected action events, non-XHR/Fetch resource events, view events, CORS and CSP violation events.

Integrate RUM with distributed tracing

Configure allowedTracingUrls to inject tracing headers into matching API requests and correlate browser requests with backend traces.

Usage

Use the allowedTracingUrls parameter to configure API service domains for your application:
CDN integrations use the same initialization options. See the SDK integration guide for loading examples. allowedTracingUrls matches full URLs and accepts the following types:

Tracing protocol

The SDK adds traceparent and tracestate headers to matching requests. For field meanings and an example, see Distributed tracing.

Verification

In the browser Network panel, check that matching requests include the traceparent and tracestate tracing headers.
Distributed Tracing Verification
If your HTTP requests involve cross-origin issues, ensure requests can pass cross-origin checks. Make sure the corresponding server has cross-origin configuration and supports preflight requests.

SDK Integration Guide

Learn how to quickly integrate the RUM SDK

Data Collection

Learn about data types and attributes collected by the SDK

Troubleshooting

Solve common issues and debugging tips
For source and releases, see the Flashduty SDK GitHub repository.