#Analytics based on route change (in the middleware function)

1 messages · Page 1 of 1 (latest)

slow barnBOT
#

Hi @drowsy totem. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

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.

  1. 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)

  2. 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/analytics package and add the Analytics component to your app. Learn more (https://vercel.com/docs/frameworks/nextjs)

  3. useReportWebVitals: You can use the useReportWebVitals function 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 the id value 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

drowsy totem
#

@slow barn

slow barnBOT
#

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?

drowsy totem
#

@slow barn

slow barnBOT
#

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?

drowsy totem
#

Does the useReportWebVitals give insight about route changes and params and stuff like that?

#

@slow barn

slow barnBOT
#

Let me check the knowledge base for you. One moment! :books: