Analytics
Measure and track page performance using Next.js Speed Insights
Next.js has built-in support for measuring and reporting performance metrics. You can either use the useReportWebVitals
hook to manage reporting yourself, or alternatively, Vercel provides a managed service to automatically collect and visualize metrics for you.
Build Your Own
Since the useReportWebVitals
hook requires the "use client"
directive, the most performant approach is to create a separate component that the root layout imports. This confines the client boundary exclusively to the WebVitals
component.
View the API Reference for more information.
Web Vitals
Web Vitals are a set of useful metrics that aim to capture the user experience of a web page. The following web vitals are all included:
- Time to First Byte (TTFB)
- First Contentful Paint (FCP)
- Largest Contentful Paint (LCP)
- First Input Delay (FID)
- Cumulative Layout Shift (CLS)
- Interaction to Next Paint (INP)
You can handle all the results of these metrics using the name
property.
Sending results to external systems
You can send results to any endpoint to measure and track real user performance on your site. For example:
Good to know: If you use Google Analytics, using the
id
value can allow you to construct metric distributions manually (to calculate percentiles,
etc.)
Read more about sending results to Google Analytics.