fix(analytics): always use defer over async to account for document nav event
This commit is contained in:
parent
80c3196fee
commit
2c30abe457
1 changed files with 4 additions and 5 deletions
|
@ -86,7 +86,7 @@ function addGlobalPageResources(ctx: BuildCtx, componentResources: ComponentReso
|
||||||
componentResources.afterDOMLoaded.push(`
|
componentResources.afterDOMLoaded.push(`
|
||||||
const gtagScript = document.createElement("script")
|
const gtagScript = document.createElement("script")
|
||||||
gtagScript.src = "https://www.googletagmanager.com/gtag/js?id=${tagId}"
|
gtagScript.src = "https://www.googletagmanager.com/gtag/js?id=${tagId}"
|
||||||
gtagScript.async = true
|
gtagScript.defer = true
|
||||||
document.head.appendChild(gtagScript)
|
document.head.appendChild(gtagScript)
|
||||||
|
|
||||||
window.dataLayer = window.dataLayer || [];
|
window.dataLayer = window.dataLayer || [];
|
||||||
|
@ -121,7 +121,7 @@ function addGlobalPageResources(ctx: BuildCtx, componentResources: ComponentReso
|
||||||
umamiScript.src = "${cfg.analytics.host ?? "https://analytics.umami.is"}/script.js"
|
umamiScript.src = "${cfg.analytics.host ?? "https://analytics.umami.is"}/script.js"
|
||||||
umamiScript.setAttribute("data-website-id", "${cfg.analytics.websiteId}")
|
umamiScript.setAttribute("data-website-id", "${cfg.analytics.websiteId}")
|
||||||
umamiScript.setAttribute("data-auto-track", "false")
|
umamiScript.setAttribute("data-auto-track", "false")
|
||||||
umamiScript.async = true
|
umamiScript.defer = true
|
||||||
document.head.appendChild(umamiScript)
|
document.head.appendChild(umamiScript)
|
||||||
|
|
||||||
document.addEventListener("nav", () => {
|
document.addEventListener("nav", () => {
|
||||||
|
@ -132,7 +132,7 @@ function addGlobalPageResources(ctx: BuildCtx, componentResources: ComponentReso
|
||||||
componentResources.afterDOMLoaded.push(`
|
componentResources.afterDOMLoaded.push(`
|
||||||
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.defer = 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)
|
||||||
|
@ -173,14 +173,13 @@ function addGlobalPageResources(ctx: BuildCtx, componentResources: ComponentReso
|
||||||
const cabinScript = document.createElement("script")
|
const cabinScript = document.createElement("script")
|
||||||
cabinScript.src = "${cfg.analytics.host ?? "https://scripts.withcabin.com"}/hello.js"
|
cabinScript.src = "${cfg.analytics.host ?? "https://scripts.withcabin.com"}/hello.js"
|
||||||
cabinScript.defer = true
|
cabinScript.defer = true
|
||||||
cabinScript.async = true
|
|
||||||
document.head.appendChild(cabinScript)
|
document.head.appendChild(cabinScript)
|
||||||
`)
|
`)
|
||||||
} else if (cfg.analytics?.provider === "clarity") {
|
} else if (cfg.analytics?.provider === "clarity") {
|
||||||
componentResources.afterDOMLoaded.push(`
|
componentResources.afterDOMLoaded.push(`
|
||||||
const clarityScript = document.createElement("script")
|
const clarityScript = document.createElement("script")
|
||||||
clarityScript.innerHTML= \`(function(c,l,a,r,i,t,y){c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
|
clarityScript.innerHTML= \`(function(c,l,a,r,i,t,y){c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
|
||||||
t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
|
t=l.createElement(r);t.defer=1;t.src="https://www.clarity.ms/tag/"+i;
|
||||||
y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
|
y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
|
||||||
})(window, document, "clarity", "script", "${cfg.analytics.projectId}");\`
|
})(window, document, "clarity", "script", "${cfg.analytics.projectId}");\`
|
||||||
document.head.appendChild(clarityScript)
|
document.head.appendChild(clarityScript)
|
||||||
|
|
Loading…
Add table
Reference in a new issue