vercel / analytics

Privacy-friendly, real-time traffic insights
https://vercel.com/analytics
Mozilla Public License 2.0
416 stars 24 forks source link

Page changes are no longer tracked in SvelteKit 2 #121

Closed mattpilott closed 6 months ago

mattpilott commented 7 months ago

Using @vercel/analytics with SvelteKit v2 only registers the initial page load and ignores all subsequent requests.

Followed the guide here: https://vercel.com/docs/analytics/quickstart

Implemented the inject function in layout.js, tried inside and outside the load function plus tried it in the layout.svelte file and all give the same result. The only way to get a navigation to register beyond the initial page load is to do a page reload

This means web analytics with SvelteKit 2 is currently of limited use and is largely broken

mschmdb commented 6 months ago

Experiencing the same

hchris21 commented 6 months ago

It has (most probably) nothing to do with SvelteKit, I am using plain Next.js (latest version) and unfortunately I am experiencing the same issues as described by @mattpilott.

It will only recognise the route of the initial page load OR on a full refresh.

I am using the next/link package for navigation.

tobiaslins commented 6 months ago

Hey @mattpilott

This should be resolved by the SvelteKit patch you see linked above.

@hchris21
This shouldn't happen. Can you share a domain with us so I can check? Soft navigations should be reported as expected for all frameworks

hchris21 commented 6 months ago

Hey @tobiaslins, thanks for the reply. Here is the domain: https://www.hornxengineering.dev

tobiaslins commented 6 months ago

@hchris21 which Next.js version are you on? did you add the Analytics component to the layout.tsx?

hchris21 commented 6 months ago

@tobiaslins, on my latest build I am using Next.js 14.0.3, and yes, the Analytics component is added inside the root layout.tsx as mentioned in the docs, like:

<html lang="en">
   <body>
       <main>
          <Navbar /> // this is the component with the Links
          {children}
       </main>
       <Analytics />
   </body>
</html>

I have also tried it out with the <Analytics /> being inside the <main> (together with the Navbar and children), but it did not make a difference

hchris21 commented 6 months ago

Hey @tobiaslins, I have updated the dependencies and now it is showing the page views on my non-root pages as well. (tested it with different users on different devices)

I assume it has to do with the fact that the next version is now 14.0.4, because the other deps that were updated were packages like: autoprefixer, classnames, eslint-config-next, geist and tailwindcss, I believe none of these packages have conflicted with the Analytics.

tobiaslins commented 6 months ago

For me it looks fine. On your page, /work gets tracked on navigating

image
tobiaslins commented 6 months ago

Will close this here! feel free to reopen if there are other issues