Tracking page views in a Single Page App
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 counterscalescripttag. (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!
@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.
@ninjaPixel Hey, can you look at #143 and tell me if that would help?
It's also possible #140 (which landed on main and is in version 2.4.0) could just address the issue out-of-the-box.
I think this is now covered by manually tracking pageviews, which is how #143 wound up.