usefathom / fathom

Fathom Lite. Simple, privacy-focused website analytics. Built with Golang & Preact.
https://usefathom.com/
MIT License
7.55k stars 367 forks source link

Tracking URL updates on a single page? #178

Closed weavermedia closed 5 years ago

weavermedia commented 5 years ago

My site runs on Carrd, a site builder and hosting platform. It emulates multiple page websites by hiding and showing sections on demand.

When a nav link is clicked, the required section shows and the URL is updated to, for example, /#contact. Somewhat different to a regular SPA because no remote data requests are made for new sections. All the section content is loaded at once and simply hidden/shown on demand.

I added fathom('trackPageview'); to each nav button to track views of each section but the URL hash fragments aren't being tracked.

How do I track with the hash fragment?

Example: https://meatbeats.com

dannyvankooten commented 5 years ago

Hey,

Is there a setting in Carrd that lets you update the actual URL of the page instead of using the hash fragments, so for example clicking the contact link would change the page URL to /contact (still without reloading) instead of /#contact?

That would allow Fathom to pick-up on the URL with success and pretty much all browsers nowadays support updating the URL on the fly like that (without having to use hash fragments). Fathom won't pick up on hash fragments right now because a lot of times, this is used for data that you don't want in your analytics tools.

Alternatively, I'm thinking of mimicking Google Analytics by allowing an additional variable to override the page URL in the call to fathom('trackPageview').

Example:

fathom('trackPageview', {
    path: '/path-of-page-you-want-to-increment-tracking-stats-for' 
})

Would the latter approach work for you (if the former isn't an option)?

weavermedia commented 5 years ago

I'll check in with the Carrd dev about using non-hash URLs. There is an option for redirects. If a add a redirect like /contact=#contact I wonder if that would be picked up by Fathom? 🤔

Otherwise, yes the override method would work very well indeed. I actually tried fathom('trackPageview', '/contact'); in case there was some undocumented functionality but, alas, no. 😀

weavermedia commented 5 years ago

@dannyvankooten Just saw the commit. Wow, that was fast! Will this be in the next release?

dannyvankooten commented 5 years ago

Yes, definitely @weavermedia!