0PricingLogin
React Academy · Lesson

Real User Monitoring and Web Vitals

Capture LCP, FID, CLS, and custom performance marks as OTel metrics using the web-vitals library.

The web-vitals Library

Google's web-vitals npm package provides a simple API for measuring Core Web Vitals in real user browsers. Install it with npm install web-vitals and import individual metric callbacks: onLCP, onFID (deprecated), onCLS, onFCP, onTTFB, and the modern onINP for Interaction to Next Paint.

Metric Callbacks and Metric Objects

Each callback (onLCP, onCLS, onINP, etc.) receives a metric object containing: name ('LCP'), value (milliseconds or unitless score), rating ('good', 'needs-improvement', 'poor'), and id (a unique identifier for deduplication). The callback fires once the metric value is finalized.

All lessons in this course

  1. Frontend Observability: What and Why
  2. OpenTelemetry Traces from the Browser
  3. Real User Monitoring and Web Vitals
  4. Correlating Frontend and Backend Traces
← Back to React Academy