derrickreimer/fathom-client

SPA route changes not being tracked

michavie opened this issue · 6 comments

I am using this package with NextJs hosted on Vercel, have implemented the tracking code as shown on the bottom of the README file, and notice the following:

  • Opening up ANY route on the page counts as a hit for the ROOT page (/)
  • Navigating the site NEVER shows page visits other than the ROOT page in the Dashboard

To fix this, I have played with different kind of config settings (spa, ...) and also the slightly different way proposed directly by Vercel in their official Fathom guide: https://vercel.com/guides/deploying-nextjs-using-fathom-analytics-with-vercel

Has anyone experienced this kind of behavior before?

Hi @michaviehauser I'm having trouble reproducing this. One of my products is a Next.js app and I'm using the config from the README. I navigated directly to my /pricing page and then clicked an internal link to the /docs page, and this is what the request log is showing:

Pasted_Image_9_14_20__4_06_PM

Is your repo public, or can you paste the relevant snippet here from your app?

@derrickreimer I mirrored the scenario you'd described and this is what it looks on my end:
Screenshot 2020-09-14 at 11 33 18 PM

Not sure if the encoded URL has something to do with it, but it certainly only shows the encoded root path %2F on both calls for the "p" query param.

This is the implementation part:
Screenshot 2020-09-14 at 11 41 28 PM

Additionally, I have tried disabling all kinds of service workers that could interfere but with the same result.

Do you have a <link rel="canonical" ...> tag in your <head> set to /, by chance? This will override what's in the window location unless you set canonical to false in your load call:

Fathom.load(id, {
  canonical: false,
  // rest...
})

Correct guess! There was a badly placed canonical tag within the <head> that I removed.

Thank you so much for helping out @derrickreimer !

Awesome! Glad to help. I've run into weirdness with canonical tags myself before 😅

They are the worst! (at least when you don't need them)