-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
fix(goatcounter): properly count SPA page hits #1718
base: v4
Are you sure you want to change the base?
Conversation
485b1ee
to
9400d64
Compare
9400d64
to
812a57a
Compare
So I finally actually deployed a quartz site and I tested the goatcounter thing - apparently my previous fix didn't quite work. The new way (force-pushed) is the only one I've found to actually work relatively reliably at least. |
On the surface it seems that only google and plausible scripts handle the SPA correctly - but I don't know if maybe others handle window.history API themselves somehow or something like that. However, I am trying out goatcounter and in it's docs I see that it does no special SPA handling, so this has to be fixed. Just doing the dynamic script thing on every nav seems to do the trick. The script is not "spa-preserve" so they wouldn't accumulate - and when I tried the "spa-preserve" + call goatcounter api route it didn't quite work, they actually did accumulate
812a57a
to
cdc5728
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plausible works given that the plausible script will attach a window.plausible :)
Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
Can you check again if this works? |
Owie owie owies, what did you do to the branch lol Anyway, re-tested your exact commit to be sure, but just "spa-preserve" like that does nothing - it only counts the first pageload. The only thing that seemingly worked great is this ugly re-adding the script on nav events - at least the script itself is cached, and also tiny so not like we re-execute alot, pfew |
On the surface it seems that only google and plausible scripts handle
the SPA correctly - but I don't know if maybe others handle
window.history API themselves somehow or something like that.
However, I am trying out goatcounter and in it's docs I see that it
does no special SPA handling, so this has to be added.
Note:
The whole
significantLoad
thing is to correctly count things -goatcounter will not be loaded and initialized yet when the initial
"nav" is dispatched (because of the weird dynamic script tag insertion
thing you guys have going on here), but it will count that page load
when it itself is loaded.
If there was a way to ensure goatcounter is loaded before the first
nav, you could just configure it to not count anything on it's own load
(like in their spa example) and
have the "nav" call it unconditionally, but that's not the case 🤷