# RUM plus Session Replay wiring

## Setup

1. In the Datadog app: Digital Experience, add application, JavaScript type. Copy the `clientToken` and `applicationId`.
2. Install the browser SDK (npm into your frontend bundle is the recommended path).
3. Init early in the page lifecycle:
   - `applicationId` and `clientToken` from step 1.
   - `site` matching your org region (same trap as everything else).
   - `service` and `env` matching your backend unified tagging so frontend and backend sessions join.
   - `sessionSampleRate`: 100 while validating, then lower for production volume.
   - Session Replay: enable it and set its sample rate separately; replay is the expensive one, sample it harder than sessions.
   - Privacy: default text masking is on for a reason. Decide what unmasking you actually need before turning it off.

## Pre-flight (do these before calling it done)

- **CSP**: add the SDK script and intake domains to your Content Security Policy, or the SDK silently never loads.
- **Ad blockers**: test in a clean browser profile. Blockers nuke the SDK and your testing will false-negative.
- **Consent gates**: if the SDK loads after consent, undocumented users produce no sessions. That is a product decision, make it deliberately.

## Verify

Devtools Network shows intake requests on load and interactions. Sessions appear in the explorer within a minute. Click a session, play the replay, and confirm backend traces link from the frontend spans. If the link is missing, the service/env tags disagree between frontend and backend.