Skip to content

Commit ae885de

Browse files
authored
feat(docs): add Matomo analytics to documentation site (#469)
* feat(docs): add Matomo analytics to documentation site Add Matomo tracking to the docs site, matching the portal's setup (cookies disabled, link tracking enabled, same Matomo Cloud instance). The tracking script is deployed as a single root-level file (`/matomo.js`) rather than baked into each versioned build, so the site ID can be updated without rebuilding existing versions. > **TODO**: Replace `CHANGEME` in `docs-site/matomo.js` with the actual > Matomo site ID once IT creates the site for `cli.internetcomputer.org`. * chore(docs): set Matomo site ID to 21 * chore(docs): add cache headers for matomo.js
1 parent d1a7cc9 commit ae885de

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

.github/workflows/docs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ jobs:
8888
# Copy custom domain file
8989
cp docs-site/public/.well-known/ic-domains root/.well-known/ic-domains
9090
91+
# Copy Matomo analytics script (site ID defined once here, not per-version)
92+
cp docs-site/matomo.js root/matomo.js
93+
9194
# Extract the latest version from versions.json
9295
LATEST_VERSION=$(jq -r ".versions[] | select(.latest == true) | .version" docs-site/versions.json)
9396

docs-site/.ic-assets.json5

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,12 @@
3333
"headers": {
3434
"Cache-Control": "public, max-age=60"
3535
}
36+
},
37+
{
38+
// Matomo analytics — short cache so site ID changes are picked up quickly
39+
"match": "matomo.js",
40+
"headers": {
41+
"Cache-Control": "public, max-age=300"
42+
}
3643
}
3744
]

docs-site/astro.config.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ export default defineConfig({
5252
});
5353
`,
5454
},
55+
// Matomo analytics — loaded from root so the site ID is defined once,
56+
// not baked into each versioned build
57+
{
58+
tag: 'script',
59+
attrs: { src: '/matomo.js', async: true },
60+
},
5561
],
5662
social: [
5763
{ icon: 'github', label: 'GitHub', href: 'https://github.com/dfinity/icp-cli' },

docs-site/matomo.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
var _paq = (window._paq = window._paq || []);
2+
_paq.push(["disableCookies"]);
3+
_paq.push(["enableLinkTracking"]);
4+
_paq.push(["trackPageView"]);
5+
(function () {
6+
var u = "https://internetcomputer.matomo.cloud/";
7+
_paq.push(["setTrackerUrl", u + "matomo.php"]);
8+
_paq.push(["setSiteId", "21"]);
9+
var d = document,
10+
g = d.createElement("script"),
11+
s = d.getElementsByTagName("script")[0];
12+
g.async = true;
13+
g.src = "https://cdn.matomo.cloud/internetcomputer.matomo.cloud/matomo.js";
14+
s.parentNode.insertBefore(g, s);
15+
})();

0 commit comments

Comments
 (0)