Skip to content
Tutorials Center
My learning

Topics

Lesson 29 of 37 ยท Synthetics and Security

Real User Monitoring

Add Datadog Real User Monitoring to a web app: sessions, views, actions, Core Web Vitals (LCP, INP, CLS), privacy settings and linking frontend to backend traces.

Synthetic tests are a robot using your site. Real User Monitoring (RUM) measures real people: how fast pages load on their devices, which clicks fail, which browsers throw errors. Together they cover both "does it work?" and "how does it feel?".

RUM needs a browser SDK loaded into a real site, which this tutorial cannot run. The setup snippets are read-only, and the calculations are demonstrated with labelled stand-ins.

The RUM data model

RUM events form a hierarchy:

  • Session: one visit, up to the inactivity timeout (default 15 minutes) or 4 hours maximum.
  • View: one page or screen (in a single-page app, a route).
  • Action: a click, tap or scroll, plus custom actions you record.
  • Resource: one network request or asset load (images, scripts, fetch/XHR).
  • Error: a JavaScript exception, failed request or console error.
  • Long task: main-thread work longer than 50 ms that blocks the page.

Add the Browser SDK

Create an application in Digital Experience > RUM Applications > New Application. You receive an applicationId and a clientToken. The client token is public by design (it is shipped to browsers) and only allows sending data. Never use an API key in frontend code.

JavaScript
import { datadogRum } from "@datadog/browser-rum";

datadogRum.init({
  applicationId: "<APPLICATION_ID>",
  clientToken: "<CLIENT_TOKEN>",
  site: "datadoghq.com",
  service: "web-frontend",
  env: "prod",
  version: "2.14.0",
  sessionSampleRate: 100,
  sessionReplaySampleRate: 20,
  trackUserInteractions: true,
  trackResources: true,
  trackLongTasks: true,
  defaultPrivacyLevel: "mask-user-input",
  allowedTracingUrls: ["https://api.example.com"],
});

Notes:

  • sessionSampleRate controls cost. 100 means every session; lower it on high traffic.
  • sessionReplaySampleRate records a replay of a share of sessions, a video-like reconstruction of the DOM.
  • defaultPrivacyLevel masks text the user types or sees. Check your legal requirements before enabling replay, and add data-dd-privacy="hidden" to sensitive parts of the page.
  • allowedTracingUrls makes the SDK add trace headers to calls to your API, so a frontend request links to its backend trace.

Core Web Vitals

Datadog reports Google's Core Web Vitals, which reflect user-perceived performance:

Metric Question it answers "Good" threshold (75th percentile)
LCP (Largest Contentful Paint) When did the main content appear? 2.5 s or less
INP (Interaction to Next Paint) How quickly does the page react to input? 200 ms or less
CLS (Cumulative Layout Shift) Does the layout jump around? 0.1 or less

Thresholds are Google's public guidance and may be revised; the RUM page shows current rating bands. Vitals are judged at the 75th percentile across page views, not the average.

Stand-in: rate vitals from samples

JS Stand-in: p75 and Core Web Vitals rating

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Finding problems with RUM

  • Performance tab: page load by view, slowest resources, long tasks.
  • Errors: grouped by message and stack, with source maps uploaded (datadog-ci sourcemaps upload) so minified stacks show real file names.
  • Frustration signals: rage clicks (many quick clicks), dead clicks (click with no reaction) and error clicks highlight confusing UI.
  • Session replay: watch what happened before an error.
  • Funnels and retention analytics: where users drop out of checkout.
  • Segment by tag: @browser.name, @geo.country, version, @usr.plan (user attributes you set with datadogRum.setUser).

Frontend to backend: because of the tracing headers, the View side panel can show the APM trace for a slow fetch call, so you see whether the slowness is the network, the backend or the rendering.

Stand-in: detect rage clicks

JS Stand-in: rage click detector

Press Run (or Ctrl + Enter) to see the console output here.

No output.

A real detector is more sophisticated, but this is the core: several clicks on one element in a short window.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which key belongs in browser code for RUM?

    The client token is designed to be public and can only send RUM data.
  2. 2. Core Web Vitals are rated at which statistic?

    Google evaluates vitals at the 75th percentile of page views.
  3. 3. What does INP measure?

    Interaction to Next Paint measures responsiveness after a user interaction.
  4. 4. Why upload source maps to Datadog?

    Source maps translate minified positions back to original files and lines.

Summary

  • RUM records sessions, views, actions, resources, errors and long tasks from real browsers.
  • Initialise the SDK with a public client token, tag service, env and version, and control cost with sampling.
  • Watch LCP, INP and CLS at the 75th percentile.
  • Source maps, frustration signals, replay and trace links turn data into fixes.
  • Mind privacy: mask input and hide sensitive elements.

Next: Security Monitoring