#Analytics based on route change (in the middleware function)
1 messages · Page 1 of 1 (latest)
Based on the information provided in the extracts, there are a few ways you can track page views and route changes in a Next.js application.
-
Google Analytics: Google Analytics automatically tracks pageviews when the browser history state changes. This means that client-side navigations between Next.js routes will send pageview data without any configuration. To ensure that client-side navigations are being measured correctly, verify that the “Enhanced Measurement” property is enabled in your Admin panel and the “Page changes based on browser history events” checkbox is selected. If you decide to manually send pageview events, make sure to disable the default pageview measurement to avoid having duplicate data. Learn more (https://nextjs.org/docs/app/building-your-application/optimizing/third-party-libraries#tracking-pageviews)
-
Vercel's Web Analytics: Vercel's Web Analytics features enable you to visualize and monitor your application's performance over time. To use Web Analytics, navigate to the Analytics tab of your project dashboard on Vercel and select Enable in the modal that appears. To track visitors and page views, you can install the
@vercel/analyticspackage and add theAnalyticscomponent to your app. Learn more (https://vercel.com/docs/frameworks/nextjs) -
useReportWebVitals: You can use the
useReportWebVitalsfunction in Next.js to send results to any endpoint to measure and track real user performance on your site. If you use Google Analytics, using theidvalue can allow you to construct metric distributions manually. Learn more (https://nextjs.org/docs/pages/api-reference/functions/use-report-web-vitals#sending-results-to-external-systems)
However, none of these methods can directly tell you whether a user clicked on an anchor tag in the site to get redirected or if they landed there themselves. For that level of detail, you might need to implement custom event tracking in your application, which is not covered in the provided extracts.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@drowsy totem kapa.ai is still learning and improving, please let us know how it did by reacting below
@slow barn
Let me check the knowledge base for you. One moment! :books:
Sorry @drowsy totem, I seem to be having a bit of trouble. Don't worry though, I've pinged my supprt and they will try to fix me up! :technologist:
Perhaps try again in 15mins?
@slow barn
Let me check the knowledge base for you. One moment! :books:
Sorry @drowsy totem, I seem to be having a bit of trouble. Don't worry though, I've pinged my supprt and they will try to fix me up! :technologist:
Perhaps try again in 15mins?
Does the useReportWebVitals give insight about route changes and params and stuff like that?
@slow barn
Let me check the knowledge base for you. One moment! :books: