You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -5,48 +5,62 @@ description: Measure and track page performance using Next.js Speed Insights
5
5
6
6
{/* The content of this doc is shared between the app and pages router. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */}
7
7
8
-
[Next.js Speed Insights](https://nextjs.org/analytics) allows you to analyze and measure the performance of
9
-
pages using different metrics.
10
-
11
-
You can start collecting your [Real Experience Score](https://vercel.com/docs/concepts/speed-insights#core-web-vitals-explained?utm_source=next-site&utm_medium=docs&utm_campaign=next-website) with zero-configuration on [Vercel deployments](https://vercel.com/docs/concepts/speed-insights?utm_source=next-site&utm_medium=docs&utm_campaign=next-website).
12
-
13
-
The rest of this documentation describes the built-in relayer Next.js Speed Insights uses.
14
-
15
-
<PagesOnly>
8
+
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](https://vercel.com/analytics?utm_source=next-site&utm_medium=docs&utm_campaign=next-website) to automatically collect and visualize metrics for you.
16
9
17
10
## Build Your Own
18
11
19
-
First, you will need to create a [custom App](/docs/pages/building-your-application/routing/custom-app) component and define a `reportWebVitals` function:
This function is fired when the final values for any of the metrics have finished calculating on
34
-
the page. You can use to log any of the results to the console or send to a particular endpoint.
26
+
View the [API Reference](/docs/pages/api-reference/functions/use-report-web-vitals) for more information.
27
+
28
+
</PagesOnly>
35
29
36
-
The `metric` object returned to the function consists of a number of properties:
30
+
<AppOnly>
37
31
38
-
-`id`: Unique identifier for the metric in the context of the current page load
39
-
-`name`: Metric name
40
-
-`startTime`: First recorded timestamp of the performance entry in [milliseconds](https://developer.mozilla.org/docs/Web/API/DOMHighResTimeStamp) (if applicable)
41
-
-`value`: Value, or duration in [milliseconds](https://developer.mozilla.org/docs/Web/API/DOMHighResTimeStamp), of the performance entry
42
-
-`label`: Type of metric (`web-vital` or `custom`)
> 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.
60
+
61
+
View the [API Reference](/docs/app/api-reference/functions/use-report-web-vitals) for more information.
62
+
63
+
</AppOnly>
50
64
51
65
## Web Vitals
52
66
@@ -58,55 +72,81 @@ experience of a web page. The following web vitals are all included:
> Read more about [sending results to Google Analytics](https://github.com/GoogleChrome/web-vitals#send-the-results-to-google-analytics).
189
-
190
-
## TypeScript
191
-
192
-
If you are using TypeScript, you can use the built-in type `NextWebVitalsMetric`:
0 commit comments