Lesson 2 of 14 · 24m
Field Data: Instrumenting Real Users
CrUX tells you whether you have a problem; your own RUM with the web-vitals attribution build tells you why.
The most expensive performance bug I ever chased was a single A/B variant that loaded a 2 MB personalization SDK for 15% of traffic. No lab test caught it — no lab test was ever bucketed into that variant. Field data caught it in a day, once we started recording which variant each slow session had. Real-user monitoring isn't a nice-to-have; it's the only ground truth there is.
Two sources of field data
- CrUX (Chrome UX Report): Google's public dataset from opted-in Chrome users, a 28-day rolling window, origin- or URL-level. Free, zero setup, and it's what Search reads. But it's coarse, delayed, Chrome-only, and you can't slice it by your own dimensions.
- Your own RUM: you measure in the page and beacon results home. Immediate, sliceable by route, release, device, A/B variant — and the only way to get attribution: which element, which script.
CrUX tells you whether you have a problem. Your RUM tells you why.
curl -s "https://chromeuxreport.googleapis.com/v1/records:queryRecord?key=$CRUX_API_KEY" \
-H 'Content-Type: application/json' \
-d '{"origin": "https://shop.northwindgear.com", "formFactor": "PHONE"}' \
| jq '.record.metrics.largest_contentful_paint.percentiles.p75'Instrumenting with web-vitals
Don't hand-roll PerformanceObservers for this — the edge cases (bfcache restores, prerendering, background tabs, CLS session windows) will eat you. Use Google's web-vitals library, and specifically the attribution build:
import { onLCP, onINP, onCLS, onTTFB } from "web-vitals/attribution";
function send(metric) {
const body = JSON.stringify({
name: metric.name, // "LCP" | "INP" | "CLS" | "TTFB"
value: metric.value,
rating: metric.rating, // "good" | "needs-improvement" | "poor"
id: metric.id,
nav: metric.navigationType, // "navigate" | "reload" | "back-forward" | "back-forward-cache" | "prerender" | ...
route: window.__ROUTE_TEMPLATE__, // "/product/:id", never the raw URL
release: window.__BUILD_SHA__,
attribution: metric.attribution, // trim in production; it can be large
});
// sendBeacon survives page unload; fetch keepalive is the fallback
if (!navigator.sendBeacon?.("/rum", body)) {
fetch("/rum", { method: "POST", body, keepalive: true });
}
}
onLCP(send);
onINP(send);
onCLS(send);
onTTFB(send);With attribution, LCP reports the element selector plus timeToFirstByte, resourceLoadDelay, resourceLoadDuration, and elementRenderDelay — the four sub-parts, per real session. INP reports the interaction target plus inputDelay, processingDuration, and presentationDelay. CLS reports largestShiftTarget. "INP is 480 ms" becomes "the filter checkbox on /search burns 350 ms of processing on a Xiaomi."
Send TTFB too. It's the LCP sub-part you can't compute client-side, and it's the canary for CDN and origin regressions. While you're at it, capture navigationType — back-forward/back-forward-cache and prerender loads have near-zero LCP by construction, and including them unmarked in your averages flatters the numbers.
The receiving end
The /rum endpoint is a dumb POST sink: parse the JSON, tag it with route, release, and device class, store the raw value. Aggregation happens at query time — keep the raw events so you can re-segment later without re-collecting. Two practical limits. sendBeacon payloads are capped at 64 KB, and a full attribution object can exceed that on a bad page — strip it to the element selector and the sub-part numbers before you stringify. And beacons fire on visibilitychange, so sessions that never background — crashed tabs, killed browsers — are simply absent; your denominator is sessions that reported, not sessions that happened.
One thing your RUM has that CrUX never will: soft navigations. web-vitals reports the initial document load, and CrUX is built the same way — an SPA route change is invisible to both unless you re-measure on each router event and tag it with the new route template. If your app is client-rendered, that per-route RUM is the only performance record of those navigations that exists.
Aggregate like the scoring does
Store raw values; compute p75 per segment. Averages lie — a few 30-second backgrounded-tab outliers will drag a mean anywhere. This runs in the sandbox:
function p75(values) {
const s = [...values].sort((a, b) => a - b);
return s[Math.ceil(s.length * 0.75) - 1];
}
const lcpByDevice = {
desktop: [1100, 1300, 1250, 1900, 1400, 1200, 2100, 1350],
mobile: [2100, 2600, 3900, 2400, 4800, 2200, 3100, 5200],
};
for (const [device, values] of Object.entries(lcpByDevice)) {
const mean = values.reduce((a, b) => a + b, 0) / values.length;
console.log(device, "p75:", p75(values), "mean:", Math.round(mean));
}Field notes
- Segment by device class first. A blended p75 hides a failing mobile experience behind a fast desktop one.
- Record the route template, not the URL — otherwise you get 400,000 "pages" with three samples each and no signal.
- Report on
visibilitychangeto hidden, notunload; web-vitals already does this. Hand-rolledunloadlisteners also break the back/forward cache. - Tag every beacon with the release SHA. "When did this start?" is the first question of every regression, and you want a deploy to point at.
- If you must sample, sample sessions, not metrics — otherwise you can't correlate LCP and INP from the same visit.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
What is Vite? The Build Tool That Made Frontend Development Fast Again
Vite replaced Webpack for a lot of teams without much fanfare. Native ES modules, a dev server that starts in milliseconds, and a production build that doesn't require understanding 300 lines of config. Here's how it works and why the switch is worth it.
PHP API Performance: N+1 Queries, cURL, and Connection Pools
A PHP API case study: fixing an N+1 query, twenty serial cURL calls, missing connection pooling, and stats recalculated on every request with Redis caching.
Inside TypeScript 7: What a Year-Long Rewrite in Go Actually Bought Developers
A deep look at how Microsoft's Go-based TypeScript 7 compiler achieves its speed gains, and what the Visual Studio Code team's year-long migration reveals about adopting it safely.
Node.js vs Deno vs Bun: Picking the Right JavaScript Runtime in 2026
Three JavaScript runtimes. Three different philosophies on what the developer experience should feel like. Here's how they compare on performance, ecosystem, tooling, and the only decision that actually matters for production.