Compare commits

...

4 Commits

Author SHA1 Message Date
Anton Bulakh
cb49dbc97e
Merge 43b6053e10d5609a07f6c4bf51ca57fbd342e905 into 7be47742a6dc86f22d148ca9d304f7a9eea318cf 2025-01-31 06:46:48 -05:00
Aaron Pham
43b6053e10
Merge branch 'v4' into goatcounter-spa 2025-01-26 08:39:56 -05:00
Aaron Pham
cd863a88e3
fix(goatcounter): asign spaPreserve to analytics script
Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
2025-01-26 08:39:43 -05:00
Anton Bulakh
cdc5728c52
fix(goatcounter): properly count SPA page hits
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
2025-01-25 21:24:19 +02:00

View File

@ -125,6 +125,7 @@ function addGlobalPageResources(ctx: BuildCtx, componentResources: ComponentReso
const goatcounterScript = document.createElement("script")
goatcounterScript.src = "${cfg.analytics.scriptSrc ?? "https://gc.zgo.at/count.js"}"
goatcounterScript.async = true
goatcounterScript.setAttribute("spa-preserve", "true")
goatcounterScript.setAttribute("data-goatcounter",
"https://${cfg.analytics.websiteId}.${cfg.analytics.host ?? "goatcounter.com"}/count")
document.head.appendChild(goatcounterScript)