Setting Up the Datadog RUM Browser SDK - What to Decide at Initialization
The Datadog RUM Browser SDK is loaded through npm or a CDN and initialized by passing an application ID and a client token. Among the init values, decide first on the sampling rate and the privacy default, which are hard to change later, and then check in order the settings that connect to APM, screen transitions in an SPA, and the CSP permissions.
What to Create in the UI Before Writing init
First, create a RUM application in the Datadog UI. From Add an Application under Digital Experience, choose the JS type and give it a name, and an applicationId and a clientToken are issued (as of October 2026; source: Browser Monitoring Client-Side Setup). The client token is a different thing from the API key that the Agent uses. Embedding an API key in the browser exposes it to users, so the client token is what you use for sending. The token belongs to the organization and stays valid even if the account of the person who created it is disabled (source: API and Application Keys). The method in which the web server injects the SDK does not support detailed configuration, so if you want to decide the init values yourself, instrument it manually (source: Browser Monitoring Setup; for an overview of the methods, see the RUM explanation).
Choose the Loading Method by Whether You Can Accept Missing Events Before Initialization
Manual instrumentation has three loading methods: npm, CDN async, and CDN sync. As the RUM explanation describes, the first two do not block page rendering but in exchange can miss events that happen before initialization. CDN sync loads before other scripts and so captures everything, but it can affect the page's loading performance (as of October 2026; source: Browser Monitoring Client-Side Setup).
| Loading method | Effect on page rendering | Events before initialization | Where to write it |
|---|---|---|---|
| npm | None (bundled together with the app's JavaScript) | Can be missed | @datadog/browser-rum in package.json |
| CDN async | None | Can be missed | The head of every page you monitor |
| CDN sync | Can be affected | All captured | Inside the head, before other scripts |
The criterion for choosing is whether you have screens where you want to investigate errors that fire right after loading. An app where you want to track a blank white screen right after startup is suited to CDN sync, while a site with a strict rendering speed target is suited to async or npm. The URL of the CDN script contains the Datadog site and the major version of the SDK, so do not assemble it by hand; copy the value listed in the official documentation as is. Initialization with npm looks like this.
import { datadogRum } from '@datadog/browser-rum';
datadogRum.init({
applicationId: '<APP_ID>',
clientToken: '<CLIENT_TOKEN>',
site: '<DATADOG_SITE>',
service: 'my-web-application',
});With CDN async, you pass the same values to init inside window.DD_RUM.onReady.
Decide the init Values in Order of How Hard They Are to Change Later
Because the configuration lives in the code, changing a value requires a re-release of the frontend. What is more, for some values, changing them does not bring past data back. The order to decide in starts with what cannot be undone. First comes sessionSampleRate: sessions that are sampled out collect nothing, page views included, and raising the rate later does not fill the gap (as of October 2026; source: Advanced Configuration). How the two-tier rates apply is explained in the RUM session explanation.
| Order to decide | Value | Default | What happens if you do not decide |
|---|---|---|---|
| 1 | sessionSampleRate | 100 | All sessions are collected. What is left out cannot be retrieved later |
| 2 | sessionReplaySampleRate | 0 | There are no sessions with recordings |
| 3 | defaultPrivacyLevel | mask | Recording starts with all on-screen text, inputs, images, and links masked |
| 4 | trackUserInteractions / trackResources / trackLongTasks | All true | Interactions, resources, and long tasks are collected |
| 5 | service / env / version | service is the applicationId | The service name remains the ID and does not connect to APM |
The recording rate is a percentage of the tracked sessions, and if it stays at the default of 0, Session Replay records not a single session. Decide the privacy default before you start recording. The default for service is the application ID, and the settings that connect to APM do not work unless you set service explicitly. If you change the name later, the before and after appear side by side as separate services, so give it a name from the start following the same rules as the backend. How to align the three values is explained in the unified service tagging explanation.
When It Does Not Connect to APM, Suspect allowedTracingUrls and CORS
To connect browser requests to APM traces, list the origins of your own APIs in allowedTracingUrls. The SDK adds tracing headers only to requests that match this list, so if it is left empty, nothing is connected. Matching is evaluated against the entire URL: a string matches as a prefix, and a regular expression is a target if it matches anywhere in the URL, so the official documentation cautions that you should anchor regular expressions to the start with ^ (as of October 2026; source: Connect RUM and Traces). By default, both the Datadog-format headers such as x-datadog-trace-id and x-datadog-parent-id and the W3C Trace Context traceparent and tracestate are added. You can change which ones are sent with propagatorTypes.
- 1. Set service explicitly in init. With the default applicationId, it does not connect
- 2. List in allowedTracingUrls the origins of your own APIs that the browser calls
- 3. On the receiving server, add headers beginning with x-datadog- plus traceparent and tracestate to Access-Control-Allow-Headers, and accept the OPTIONS preflight
- 4. The receiving service is instrumented with APM and has a supported language library installed
- 5. In the Network tab of the browser's developer tools, check whether the headers were attached to the target requests
Step 3 is the one that is easy to miss. Tracing headers are not headers that CORS allows unconditionally, so when the API is on a different origin, the browser asks with OPTIONS before sending, and if the server does not return permission, the request itself fails. If the API seems to go down the moment you add RUM, check the CORS response first. traceSampleRate (default 100) is a value that thins out only the backend traces and has no effect on the number of RUM sessions.
In an SPA, Add Screen Boundaries and User Information Yourself
The SDK automatically creates a view every time a new page opens and every time the URL changes in an SPA, and its name is the URL with path segments containing numbers treated as IDs and masked. /dashboard/1234 becomes /dashboard/? (as of October 2026; source: Advanced Configuration). In apps where the URL structure does not match the unit of a screen, set trackViewsManually to true in init and call startView where the screen switches. As in startView({ name: 'checkout', service: 'purchase', version: '1.2.3' }), you can also assign the responsible service to each view.
| What you want to do | What to use | Points to watch |
|---|---|---|
| Decide screen names yourself | trackViewsManually and startView | Call it at every point where the screen switches |
| Record whose session it is | setUser | From v6.4.0 onward, id is required. name and email are optional |
| Fix the contents before sending | beforeSend | Can rewrite and discard events |
| Collect only after obtaining consent | trackingConsent and setTrackingConsent | The default is granted. Nothing is collected while it is not-granted |
The values you pass to setUser are attached to every event collected after the change. Some of the default dashboards use usr.id as a condition, so attaching even just the ID lets you count the affected users. Before including personal information such as email addresses, prepare processing in beforeSend that masks values in URLs and error messages. The thinking on how to handle consent is in the personal information section of the RUM explanation.
Three Permissions to Add on Sites That Enforce CSP
On sites that restrict load sources and send destinations with Content Security Policy (CSP), even after you add the SDK, the browser blocks the sending and the data does not arrive. The permissions to add depend on how you use it. The send destination is the domain corresponding to the site in init, and if you change the Datadog site, the domain to allow changes too (as of October 2026; source: Content Security Policy).
| Directive | Value to add | When it is needed |
|---|---|---|
| connect-src | The Browser SDK send destination domain corresponding to site | Always |
| worker-src | blob: | When using Session Replay or compressIntakeRequests |
| script-src | https://www.datadoghq-browser-agent.com | When loading via CDN async or sync |
If you do not want to allow blob:, from v4.47.0 onward you can serve the Worker's JavaScript yourself and specify it with workerUrl in init. The conditions are that it is placed on the same origin as the web app and that the Worker's major version matches the SDK's. When you want to route the send destination through your own domain, there is also a setting where you write the URL of your own proxy in proxy in init (source: RumInitConfiguration). If the CSP permissions are enough, starting with a setup that has no proxy keeps the number of things you have to manage from growing.
Confirm the Data Arrived Before Settling on sessionSampleRate
Even after you publish a page with init in it, until Datadog receives data, the application is shown as pending on the Applications page (as of October 2026; source: Browser Monitoring Client-Side Setup). Once the pending status clears and sessions appear in the RUM Explorer, check the following three points next.
- 1. View names - Are they split into the units you intended as SPA screens
- 2. service / env / version - Are they the same values as in the backend APM
- 3. Requests to your own APIs - Do they carry the tracing headers, and can you move from the RUM UI to the traces
If it stays pending, first check in the browser's developer tools whether requests to the send destination are being blocked by CSP. Once verification is done, settle sessionSampleRate on the value for your own site, write it in init, and ship it in the next release. One way to proceed is to start at the default of 100, track the number of sessions that arrive for one week using the steps in how to check usage, and then lower it; in that order, you will not regret sessions you left out after the fact.