diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index bc95050a..617e077d 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -88,6 +88,9 @@ jobs: # Copy custom domain file cp docs-site/public/.well-known/ic-domains root/.well-known/ic-domains + # Copy Matomo analytics script (site ID defined once here, not per-version) + cp docs-site/matomo.js root/matomo.js + # Extract the latest version from versions.json LATEST_VERSION=$(jq -r ".versions[] | select(.latest == true) | .version" docs-site/versions.json) diff --git a/docs-site/.ic-assets.json5 b/docs-site/.ic-assets.json5 index a630eef6..f35b23d6 100644 --- a/docs-site/.ic-assets.json5 +++ b/docs-site/.ic-assets.json5 @@ -33,5 +33,12 @@ "headers": { "Cache-Control": "public, max-age=60" } + }, + { + // Matomo analytics — short cache so site ID changes are picked up quickly + "match": "matomo.js", + "headers": { + "Cache-Control": "public, max-age=300" + } } ] diff --git a/docs-site/astro.config.mjs b/docs-site/astro.config.mjs index 3f0c47d9..43dfea45 100644 --- a/docs-site/astro.config.mjs +++ b/docs-site/astro.config.mjs @@ -52,6 +52,12 @@ export default defineConfig({ }); `, }, + // Matomo analytics — loaded from root so the site ID is defined once, + // not baked into each versioned build + { + tag: 'script', + attrs: { src: '/matomo.js', async: true }, + }, ], social: [ { icon: 'github', label: 'GitHub', href: 'https://github.com/dfinity/icp-cli' }, diff --git a/docs-site/matomo.js b/docs-site/matomo.js new file mode 100644 index 00000000..77a0156c --- /dev/null +++ b/docs-site/matomo.js @@ -0,0 +1,15 @@ +var _paq = (window._paq = window._paq || []); +_paq.push(["disableCookies"]); +_paq.push(["enableLinkTracking"]); +_paq.push(["trackPageView"]); +(function () { + var u = "https://internetcomputer.matomo.cloud/"; + _paq.push(["setTrackerUrl", u + "matomo.php"]); + _paq.push(["setSiteId", "21"]); + var d = document, + g = d.createElement("script"), + s = d.getElementsByTagName("script")[0]; + g.async = true; + g.src = "https://cdn.matomo.cloud/internetcomputer.matomo.cloud/matomo.js"; + s.parentNode.insertBefore(g, s); +})();