Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 1 of 6 · Concept · 25 min · revision 3

Field Data: Web Vitals, Client Errors and Real-User Monitoring

Measure what real visitors experience with Core Web Vitals and error beacons, read the thresholds and percentiles that decide a good experience, and send it all to an endpoint you control.

Contentsand lesson path

What you will learn

  • Measure Core Web Vitals (LCP, INP, CLS) in the lab and in the field, state the 75th-percentile thresholds for a good experience, and attribute a poor score to its cause.
  • Monitor a deployed frontend by reporting Web Vitals and uncaught client errors from real sessions with source maps, release tags and privacy-respecting sampling, and use the reports to locate a regression.

Prerequisites: How Browsers Render Pages

01. Why it matters

Everything you can measure on your own machine — a Lighthouse run, a Performance panel recording — describes one device, one network and one page load. It says nothing about the visitor on a three-year-old phone on a train, whose tap lands while a 300 KB script is still parsing. Field data is the record of what real visitors actually experienced; lab data is what one controlled run produced. You need both, for different jobs: field data tells you whether something is slow, lab data shows you why.

This lesson builds the field side: the three Core Web Vitals and their thresholds, the client-side script that reports them, the error channel that reports what broke, and the handful of decisions — sampling, release tags, privacy — that keep the channel useful at scale. The later lessons in this skill dig into LCP, INP and bundle size; here you set up the ruler everyone else measures with.

02. Lab data, field data and the 75th percentile

The Core Web Vitals are three metrics chosen because each maps to something a visitor feels:

  • Largest Contentful Paint (LCP) — when the biggest thing in the viewport finished rendering. Slow LCP feels like a page that refuses to arrive.
  • Interaction to Next Paint (INP) — for the worst interactions across a visit, the delay from tap or key to the next painted frame. High INP feels like a page that ignores you.
  • Cumulative Layout Shift (CLS) — how much visible content moved unexpectedly. High CLS feels like a page that moves the floor under your finger.

A page is judged good at the 75th percentile (p75) of its real visits when LCP is at most 2.5 seconds, INP at most 200 milliseconds and CLS at most 0.1. The 75th percentile matters: speed teams report the p75 so that one fast outlier cannot mask a bad experience for a quarter of visitors. Values between good and the "poor" boundaries (LCP 4.0 s, INP 500 ms, CLS 0.25) count as needs improvement.

Lab tools have a blind spot you must design around: a Lighthouse navigation run performs no interactions, so it can never produce an INP — it offers Total Blocking Time as a lab proxy (only a Lighthouse timespan recording, during which you interact, reports INP). Field data is also the only source that reflects real devices and networks. The Chrome UX Report (CrUX) publishes exactly that, gathered from opted-in Chrome users, but a page must be publicly discoverable (not noindex) and have enough traffic before its statistics appear; a new page starts with no field data at all until enough visits accumulate.

The same page, two kinds of truth
Lab run (your laptop, throttled)   Field data (every real visit)
one device, one network            the whole distribution
no interactions, so no INP         every tap and key counted
runs before and after a change     shows a regression after release
names the cause (trace, tasks)     names the victim (page, element)

03. Reporting vitals from the browser

Browsers expose every ingredient through the Performance API: paint and navigation entries, LCP candidates, layout shifts, and — for interactions — the Event Timing entries that INP is built on. Assembling correct metric logic yourself is subtle (INP takes the worst interaction across the visit; LCP can be superseded by a bigger element at any time), so most teams use the small web-vitals library, which wraps the observers and also ships an attribution build that explains why a metric scored as it did.

The beacon below was bundled and served on a small demo storefront. It reports each metric with the web-vitals attribution fields — for LCP the four sub-parts you will use in the next lesson, for INP the input delay, processing time and presentation delay from the INP lesson — and a release tag, then hands the JSON to navigator.sendBeacon, which queues a POST that survives the page closing:

JavaScript · rum.js
import { onLCP, onCLS, onINP, onTTFB } from 'web-vitals/attribution';

const endpoint = '/collect';
const base = { path: location.pathname, release: '[email protected]' };

function send(name, metric) {
  const a = metric.attribution ?? {};
  const event = { ...base, metric: name,
    value: Math.round(metric.value * 1000) / 1000, rating: metric.rating };
  if (name === 'LCP') {
    event.target = a.target ?? null;            // a CSS selector string
    event.url = (a.url ?? '').split('/').pop() || null;
    event.subParts = a.timeToFirstByte !== undefined ? {
      timeToFirstByte: Math.round(a.timeToFirstByte),
      resourceLoadDelay: Math.round(a.resourceLoadDelay),
      resourceLoadDuration: Math.round(a.resourceLoadDuration),
      elementRenderDelay: Math.round(a.elementRenderDelay),
    } : null;
  }
  if (name === 'INP') {
    event.target = a.interactionTarget ?? null;
    event.interactionType = a.interactionType ?? null;
    event.subParts = a.inputDelay !== undefined ? {
      inputDelay: Math.round(a.inputDelay),
      processingDuration: Math.round(a.processingDuration),
      presentationDelay: Math.round(a.presentationDelay),
    } : null;
  }
  navigator.sendBeacon(endpoint, new Blob([JSON.stringify(event)],
    { type: 'application/json' }));
}

// Default options: each metric is reported with its final value, not on
// every change. See the note below before adding reportAllChanges.
onTTFB((m) => send('TTFB', m));
onLCP((m) => send('LCP', m));
onCLS((m) => send('CLS', m));
onINP((m) => send('INP', m));
Illustrative output — LCP, INP and CLS beacons from one throttled visit (TTFB omitted)
{"path":"/storefront/","release":"[email protected]","metric":"LCP",
 "value":4376,"rating":"poor","target":"html>body>img.hero","url":"hero.png",
 "subParts":{"timeToFirstByte":672,"resourceLoadDelay":892,
             "resourceLoadDuration":2737,"elementRenderDelay":76}}
{"path":"/storefront/","release":"[email protected]","metric":"INP",
 "value":432,"rating":"needs-improvement","target":"#add-to-cart",
 "interactionType":"pointer","subParts":{"inputDelay":1,
 "processingDuration":425,"presentationDelay":7}}
{"path":"/storefront/","release":"[email protected]","metric":"CLS",
 "value":0.111,"rating":"needs-improvement"}

With the default options the library reports each metric when its value is final: TTFB once the page has loaded, LCP once the visitor first interacts or the page is hidden, and CLS and INP when the page is hidden (CLS can be reported again if the visitor returns and the page is hidden a second time). A typical visit therefore sends one beacon per metric. The reportAllChanges: true option instead calls back on every change, such as each new LCP candidate or each worse interaction. The web-vitals README recommends it for debugging, not production: one visit then sends many beacons per metric, so the collector must keep only the latest value for each metric.id (send the id with the event), or traffic multiplies and the p75 is skewed.

The beacons above come from one visit to the slow storefront of the lab lesson, with web-vitals 6.2.3 bundled by esbuild, in headless Chromium 156 under the lab's throttling (the hero given class="hero" and the button id="add-to-cart"). Treat the numbers as illustrative: your timings will differ on any other run. The payload already tells a story: the LCP image was requested late (892 ms of load delay) and then took 2.7 s to download, the layout shifted (0.111), and the click spent 425 ms processing — concrete leads, each handed to the lesson that fixes it. The targets are CSS selectors the library builds from the element. The rating field comes from the library and uses the thresholds above, so the beacon is self-describing.

04. Client errors: the other field signal

Speed is not the only thing you cannot see from your desk. When JavaScript throws in a real browser, your server logs nothing; only the visitor saw it. A RUM channel therefore reports errors alongside metrics, from two window events: error for uncaught exceptions (installed in the capture phase so it also catches non-bubbling resource load failures on <img> or <script>) and unhandledrejection for promises that nobody caught.

A minified production bundle produces a minified stack, which is where source maps come in: they translate positions in the generated file back to the original sources. The demo below throws from a tiny widget, minified with esbuild, and reads the stack in Node with and without --enable-source-maps (error trackers symbolicate stacks the same way, using maps you upload to them at build time rather than serving publicly). In a folder with "type": "module" in package.json and npm install -D [email protected], create two files:

JavaScript · src/widget.js
export function initWidget(options) {
  const url = options.endpoint.host;
  return `https://${url}/widget`;
}
JavaScript · run-minified.mjs
// Calls the minified widget with a bad options object and prints the top of the stack.
import { initWidget } from './www/widget.min.js';

try {
  initWidget({});
} catch (error) {
  console.log(error.stack.split('\n').slice(0, 2).join('\n'));
}
Terminal · minify with a source map, then read the stack both ways
npx esbuild src/widget.js --minify --sourcemap --outfile=www/widget.min.js
node run-minified.mjs
node --enable-source-maps run-minified.mjs
Expected output — the same throw, without and with the map (paths shortened)
TypeError: Cannot read properties of undefined (reading 'host')
    at initWidget (file:///…/www/widget.min.js:1:59)

TypeError: Cannot read properties of undefined (reading 'host')
    at initWidget (/…/src/widget.js:2:32)

Note what did not change: the error message. Maps restore names, files and line numbers, which is what makes a minified stack triageable. Tag every beacon with the release (the release field above), because the stack for main.8c1f.js is only meaningful together with the map for that exact bundle — upload maps per release, and keep old ones until their traffic has aged out.

05. Sampling, consent and staying proportionate

A beacon per visit is fine for a small site; at millions of daily visits it is cost without extra signal, because percentiles stabilise long before you have counted everyone. Sample: keep every beacon on a small share of sessions — or all of them, but coarsened — and you will still see a release regression in the p75 within hours. Decide the sampling rate in one place, and let the rate survive the redesign of the page.

The second discipline is payload design. A metric value, a page template, a device class and a release tag answer nearly every performance question; the full URL with its query string can carry emails, tokens and search terms you have no business collecting, and session replay captures everything at once. Collect the coarse context you need, scrub or omit the rest, and honour whatever consent regime applies to your audience — "it is only performance data" does not exempt a payload that can identify a person.

06. Check your understanding

Practice check · 3 questions

Reading field data

Three situations from a real monitoring channel.

Q1. A template reports LCP at the 40th percentile of 1.9 s and at the 75th percentile of 2.9 s. How does the page count for LCP?
Q2. Your team ships a new landing page. The Chrome UX Report shows no field data for it. What is the most likely reason?
Q3. Your error beacon catches thrown exceptions via an `error` listener, but rejected promises never arrive. What is missing?
Practice only: not graded, not saved, not evidence.

07. Apply it

Wire the channel into a page you own (or the storefront from the lab lesson once you have built it):

  1. Install web-vitals, bundle the beacon above behind your consent check, and log the payloads server-side to a file before building a dashboard.
  2. Visit the page on a throttled connection in the browser, interact, and check that LCP, INP and CLS beacons arrive with plausible values and a release tag.
  3. Add the unhandledrejection listener and prove it works by throwing inside a rejected promise.
  4. Choose a sampling rate and a payload allowlist in writing — one line each — before the first production deploy.

The measure-then-decide habit matters more than the dashboard: every later lesson in this skill starts from a field number like the ones above.

08. Review prompt

Without looking back: state the three Core Web Vitals and the p75 value each needs to count as good. Why can a Lighthouse navigation run never report INP? What do the four LCP sub-parts and the three INP sub-parts each tell you? Which two window events feed a client error channel, and what does a source map add to a minified stack? Finally, name two things a performance beacon should not contain.

References

Your progress

Reading state

Sign in to save that you finished reading this lesson.

Sign in to mark reading complete

Prove this skill

10 questions · about 8 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check