| | |
| | | const umamiScript = document.createElement("script"); |
| | | umamiScript.src = "${cfg.analytics.host ?? "https://analytics.umami.is"}/script.js"; |
| | | umamiScript.setAttribute("data-website-id", "${cfg.analytics.websiteId}"); |
| | | umamiScript.setAttribute("data-auto-track", "false"); |
| | | umamiScript.setAttribute("data-auto-track", "true"); |
| | | umamiScript.defer = true; |
| | | umamiScript.onload = () => { |
| | | umami.track(); |
| | | document.addEventListener("nav", () => { |
| | | umami.track(); |
| | | }); |
| | | }; |
| | | |
| | | document.head.appendChild(umamiScript); |
| | | `) |
| | | } else if (cfg.analytics?.provider === "goatcounter") { |
| | | componentResources.afterDOMLoaded.push(` |
| | | const goatcounterScriptPre = document.createElement('script'); |
| | | goatcounterScriptPre.textContent = \` |
| | | window.goatcounter = { no_onload: true }; |
| | | \`; |
| | | document.head.appendChild(goatcounterScriptPre); |
| | | |
| | | const endpoint = "https://${cfg.analytics.websiteId}.${cfg.analytics.host ?? "goatcounter.com"}/count"; |
| | | const goatcounterScript = document.createElement('script'); |
| | | goatcounterScript.src = "${cfg.analytics.scriptSrc ?? "https://gc.zgo.at/count.js"}"; |
| | | goatcounterScript.defer = true; |
| | | goatcounterScript.setAttribute( |
| | | 'data-goatcounter', |
| | | "https://${cfg.analytics.websiteId}.${cfg.analytics.host ?? "goatcounter.com"}/count" |
| | | ); |
| | | goatcounterScript.setAttribute('data-goatcounter', endpoint); |
| | | goatcounterScript.onload = () => { |
| | | window.goatcounter = { no_onload: true }; |
| | | window.goatcounter.endpoint = endpoint; |
| | | goatcounter.count({ path: location.pathname }); |
| | | document.addEventListener('nav', () => { |
| | | goatcounter.count({ path: location.pathname }); |
| | |
| | | posthog.init('${cfg.analytics.apiKey}', { |
| | | api_host: '${cfg.analytics.host ?? "https://app.posthog.com"}', |
| | | capture_pageview: false, |
| | | })\` |
| | | posthogScript.onload = () => { |
| | | }); |
| | | document.addEventListener('nav', () => { |
| | | posthog.capture('$pageview', { path: location.pathname }); |
| | | |
| | | document.addEventListener('nav', () => { |
| | | posthog.capture('$pageview', { path: location.pathname }); |
| | | }); |
| | | }; |
| | | })\` |
| | | |
| | | document.head.appendChild(posthogScript); |
| | | `) |
| | |
| | | })(window, document, "clarity", "script", "${cfg.analytics.projectId}");\` |
| | | document.head.appendChild(clarityScript) |
| | | `) |
| | | } else if (cfg.analytics?.provider === "matomo") { |
| | | componentResources.afterDOMLoaded.push(` |
| | | const matomoScript = document.createElement("script"); |
| | | matomoScript.innerHTML = \` |
| | | let _paq = window._paq = window._paq || []; |
| | | |
| | | // Track SPA navigation |
| | | // https://developer.matomo.org/guides/spa-tracking |
| | | document.addEventListener("nav", () => { |
| | | _paq.push(['setCustomUrl', location.pathname]); |
| | | _paq.push(['setDocumentTitle', document.title]); |
| | | _paq.push(['trackPageView']); |
| | | }); |
| | | |
| | | _paq.push(['trackPageView']); |
| | | _paq.push(['enableLinkTracking']); |
| | | (function() { |
| | | const u="//${cfg.analytics.host}/"; |
| | | _paq.push(['setTrackerUrl', u+'matomo.php']); |
| | | _paq.push(['setSiteId', ${cfg.analytics.siteId}]); |
| | | const d=document, g=d.createElement('script'), s=d.getElementsByTagName |
| | | ('script')[0]; |
| | | g.type='text/javascript'; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s); |
| | | })(); |
| | | \` |
| | | document.head.appendChild(matomoScript); |
| | | `) |
| | | } else if (cfg.analytics?.provider === "vercel") { |
| | | /** |
| | | * script from {@link https://vercel.com/docs/analytics/quickstart?framework=html#add-the-script-tag-to-your-site|Vercel Docs} |
| | | */ |
| | | componentResources.beforeDOMLoaded.push(` |
| | | window.va = window.va || function () { (window.vaq = window.vaq || []).push(arguments); }; |
| | | `) |
| | | componentResources.afterDOMLoaded.push(` |
| | | const vercelInsightsScript = document.createElement("script") |
| | | vercelInsightsScript.src = "/_vercel/insights/script.js" |
| | | vercelInsightsScript.defer = true |
| | | document.head.appendChild(vercelInsightsScript) |
| | | `) |
| | | } |
| | | |
| | | if (cfg.enableSPA) { |