Web Vitals
The following metrics are reported:useReportWebVitals
The useReportWebVitals hook is called every time a metric value is available in the browser:
app/components/WebVitals.tsx
Because
useReportWebVitals requires the 'use client' directive, create a separate component for it rather than adding it directly to the root layout (which is a Server Component).The metric object
Themetric argument passed to the callback has the following shape:
A unique identifier for the metric in the context of the current page load.
The metric name. One of
'TTFB', 'FCP', 'LCP', 'FID', 'CLS', 'INP'.The metric value. For time-based metrics, the unit is milliseconds. For CLS, it is a unitless score.
The delta between the current value and the last reported value. Useful for calculating the total value when sending to analytics.
The qualitative rating of the metric. One of
'good', 'needs-improvement', or 'poor'.How the page was loaded. One of
'navigate', 'reload', 'back-forward', 'back-forward-cache', 'prerender'.Sending metrics to an analytics service
Send metrics to any analytics service inside theuseReportWebVitals callback. The following examples show common integrations:
- Generic (fetch)
- Google Analytics
- Datadog
app/components/WebVitals.tsx
Vercel Speed Insights
Vercel provides Speed Insights as a built-in analytics product for applications deployed on Vercel. No additional code is required—Speed Insights is enabled automatically in the Vercel dashboard. For self-hosted deployments or to collect metrics manually, use theuseReportWebVitals hook as shown above.
Performance budget
Use therating field to alert when metrics fall outside acceptable ranges:
app/components/WebVitals.tsx
