1. The need #
Measuring without trackers or cookies.
Constraints #
This site wanted to know its real Core Web Vitals without cookies, identifiers or third-party services, so that no consent would be needed for this measurement. The choice: a minimal measurement, aggregated on the server side and exposed to Prometheus.
2. Browser side #
PerformanceObserver and sendBeacon.
The script #
The script observes the browser's performance entries, keeps the latest value of each indicator, and sends a single beacon when the page goes to the background:
var m = {};
new PerformanceObserver(function (list) {
list.getEntries().forEach(function (e) { m.lcp = Math.round(e.startTime); });
}).observe({ type: 'largest-contentful-paint', buffered: true });
// ... idem pour paint (FCP), layout-shift (CLS), event (INP), navigation (TTFB)
document.addEventListener('visibilitychange', function () {
if (document.visibilityState === 'hidden') {
navigator.sendBeacon('/rum.php', new Blob([JSON.stringify({ p: pageType(), m: m })], { type: 'application/json' }));
}
});Good practice:sendBeaconis reliable even when the user closes the tab, unlike a regularfetch. The page type (home, article, lesson...) replaces the URL: no individual browsing data.
3. Server side #
Histograms for Prometheus.
Aggregation and exposure #
The endpoint validates the beacon (types and bounds), then increments histogram counters in Redis (one counter per duration bucket, per indicator and per page type). /metrics exposes them in Prometheus format:
rtm_rum_lcp_bucket{page="article",le="2500"} 1834
rtm_rum_lcp_bucket{page="article",le="4000"} 1977
rtm_rum_lcp_bucket{page="article",le="+Inf"} 2010
rtm_rum_lcp_count{page="article"} 2010# LCP au 75e percentile par type de page
histogram_quantile(0.75, sum by (le, page) (rate(rtm_rum_lcp_bucket[1h])))Good to know: The buckets follow the Core Web Vitals thresholds (for example 2,500 and 4,000 ms for LCP). CLS, being unitless, is multiplied by 1,000 to be stored as an integer: a 0.1 threshold becomes 100.
Faro or minimal RUM? #
| Need | Minimal RUM | Faro |
|---|---|---|
| Aggregated Web Vitals | Yes | Yes |
| JavaScript errors with stack | No | Yes |
| Sessions, business events | No | Yes |
| Front-to-back traces | No | Yes |
| No individual data | Yes | Configurable |
| Components to operate | None new | Alloy, Loki, Tempo |
For a content site, minimal RUM is enough. For an application (checkout funnel, customer area), Faro brings error diagnostics and correlation with the back end.
My progress
Sign in to track your progress and take notes. Sign in
💬 Questions about this lesson
No questions yet: be the first to ask for help or share your configuration.
Course Glossary
Core Web Vitals
Set of three metrics defined by Google to measure the real experience of a web page: loading (LCP (Largest Contentful Paint)), responsiveness (INP (In...
LCP (Largest Contentful Paint)
Time until the largest visible element of the page (image, video or text block) is rendered: it shows when the main content appears. Loading metric of...
INP (Interaction to Next Paint)
Latency of interactions (click, tap, key press) observed over the whole visit: the delay between the user's action and the next paint. The reported va...
CLS (Cumulative Layout Shift)
Measure of visual stability: the sum of unexpected layout shifts (a button moving just as you click, text pushed down by an ad). Unitless, computed ov...
FCP (First Contentful Paint)
Time until the first content (text, image, SVG) is rendered: the moment the user sees the page start loading. It is not a Core Web Vital, but it helps...
TTFB (Time to First Byte)
Time between the start of navigation and the arrival of the first byte of the response: it adds up redirects, DNS, TCP/TLS connection and server proce...
FID (First Input Delay)
Former responsiveness metric of the Core Web Vitals: the delay before the browser starts handling the first interaction (good ≤ 100 ms). It ignored la...
TBT (Total Blocking Time)
Lab metric (Lighthouse): the sum, between FCP (First Contentful Paint) and the end of loading, of the blocking part of each long task (over 50 ms) on ...
CrUX (Chrome UX Report)
Google's public dataset aggregating the Core Web Vitals measured from real Chrome users (at the 75th percentile, per origin and URL, over a rolling 28...
Lighthouse
Google's free audit tool, built into Chrome DevTools and PageSpeed Insights: it loads the page in a simulated environment and scores performance, acce...
Apdex
Application Performance Index: a satisfaction score between 0 and 1 based on a time threshold T. Requests under T are “satisfied”, between T and 4T “t...
Recommended Articles
Real User Monitoring (RUM) and Core Web Vitals: measuring what users experience
Why observe the front end, what RUM measures, Core Web Vitals (LCP, INP, CLS) and their threshold...
Website monitoring: availability, HTTPS monitoring, certificates and performance
Set up website monitoring: availability and HTTPS checks, certificate expiry, response time, Core...
Front-end observability best practices with Faro
Checklist for useful, respectful RUM: SDK configuration, versions, source maps, correlation with ...
RUM and Synthetic Monitoring with Datadog: synthetic transaction monitoring and user experience
Measure user experience with Datadog: browser and mobile RUM, Core Web Vitals, Session Replay, li...
Using Faro data: queries, dashboards, alerts and GDPR
Query Faro data in Loki (Web Vitals, errors, events), build dashboards and alerts, and comply wit...
Digital experience: Browser, mobile and Synthetics
Measuring what users experience with New Relic: browser agent (page load, Core Web Vitals, AJAX, ...
Faro and Alloy: receiving front-end RUM with faro.receiver
Configure faro.receiver: CORS, API key, rate limiting, source maps, then send browser errors, Web...
Grafana Faro: architecture and installation
Install Grafana Faro: the web SDK (npm or CDN), Alloy's faro.receiver, sending to Loki and Tempo,...
Frontend Observability in Grafana Cloud
Frontend Observability in Grafana Cloud: RUM built on Grafana Faro. Web Vitals, JavaScript errors...