Skip to content

Page changes are no longer tracked in SvelteKit 2 #121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mattpilott opened this issue Dec 20, 2023 · 9 comments · Fixed by sveltejs/kit#11657
Closed

Page changes are no longer tracked in SvelteKit 2 #121

mattpilott opened this issue Dec 20, 2023 · 9 comments · Fixed by sveltejs/kit#11657

Comments

@mattpilott
Copy link

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
Copy link

mschmdb commented Jan 10, 2024

Experiencing the same

@hchris21
Copy link

hchris21 commented Jan 14, 2024

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.

dummdidumm added a commit to sveltejs/kit that referenced this issue Jan 17, 2024
…nkeypatch it

Some other libraries might hook into `history.replaceState/pushState` to do additional work. This no longer works since the introduction of shallow routing because we're stashing away the original history methods. This PR adjusts the DEV time check logic so that this is no longer necessary.
Related to vercel/analytics#121
@tobiaslins
Copy link
Collaborator

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
Copy link

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

@tobiaslins
Copy link
Collaborator

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

@hchris21
Copy link

@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
Copy link

hchris21 commented Jan 17, 2024

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
Copy link
Collaborator

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

@tobiaslins
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants