Tracking page views in a Single Page App
ninjaPixel opened this issue · 2 comments
ninjaPixel commented
I'm using counterscale with Next.js and on page load it sends a trackPageview event to Cloudflare. However, on subsequent page views (where Next.js is effectively a SPA) nothing is sent to Cloudflare. I have tried:
- Calling
window.counterscale("trackPageview")
on navigation - Setting the
data-spa="auto"
property on the counterscalescript
tag. (This property is available on the Fathom script so I thought I'd give it a go here!)
How can I make sure that my SPA page views are tracked? Thanks!
benvinegar commented
@ninjaPixel First, thanks for submitting this. 🙏
How can I make sure that my SPA page views are tracked?
I think we need to augment tracker.js
to be aware of (and track) navigation changes using PopStateEvent
(mdn).
But before that, we need to add tests to the tracker using Playwright or something similar. I've been reticent to add functionality to the tracker because it's not covered at the moment.