fix(goatcounter): asign spaPreserve to analytics script

Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
This commit is contained in:
Aaron Pham 2025-01-26 08:39:43 -05:00
parent cdc5728c52
commit cd863a88e3
No known key found for this signature in database
GPG Key ID: 18974753009D2BFA

View File

@ -122,14 +122,13 @@ function addGlobalPageResources(ctx: BuildCtx, componentResources: ComponentReso
`) `)
} else if (cfg.analytics?.provider === "goatcounter") { } else if (cfg.analytics?.provider === "goatcounter") {
componentResources.afterDOMLoaded.push(` componentResources.afterDOMLoaded.push(`
document.addEventListener("nav", () => { const goatcounterScript = document.createElement("script")
const goatcounterScript = document.createElement("script") goatcounterScript.src = "${cfg.analytics.scriptSrc ?? "https://gc.zgo.at/count.js"}"
goatcounterScript.src = "${cfg.analytics.scriptSrc ?? "https://gc.zgo.at/count.js"}" goatcounterScript.async = true
goatcounterScript.async = true goatcounterScript.setAttribute("spa-preserve", "true")
goatcounterScript.setAttribute("data-goatcounter", goatcounterScript.setAttribute("data-goatcounter",
"https://${cfg.analytics.websiteId}.${cfg.analytics.host ?? "goatcounter.com"}/count") "https://${cfg.analytics.websiteId}.${cfg.analytics.host ?? "goatcounter.com"}/count")
document.head.appendChild(goatcounterScript) document.head.appendChild(goatcounterScript)
})
`) `)
} else if (cfg.analytics?.provider === "posthog") { } else if (cfg.analytics?.provider === "posthog") {
componentResources.afterDOMLoaded.push(` componentResources.afterDOMLoaded.push(`