Skip to content

Commit b8b1bc9

Browse files
committed
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 cf0c0cd commit b8b1bc9

4 files changed

Lines changed: 68 additions & 0 deletions

File tree

.github/workflows/docs.yml

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

docs-site/.ic-assets.json5

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[
2+
{
3+
// Static assets built by Astro — content-hashed filenames, cache forever
4+
"match": "**/_astro/**",
5+
"headers": {
6+
"Cache-Control": "public, max-age=31536000, immutable"
7+
}
8+
},
9+
{
10+
// Search index
11+
"match": "**/pagefind/**",
12+
"headers": {
13+
"Cache-Control": "public, max-age=31536000, immutable"
14+
}
15+
},
16+
{
17+
// HTML pages — short cache so updates are visible quickly
18+
"match": "**/*.html",
19+
"headers": {
20+
"Cache-Control": "public, max-age=300"
21+
}
22+
},
23+
{
24+
// Markdown endpoints and llms.txt — short cache so updates are visible quickly
25+
"match": "**/*.{md,txt}",
26+
"headers": {
27+
"Cache-Control": "public, max-age=300"
28+
}
29+
},
30+
{
31+
// Version list — very short cache so version switcher sees updates quickly
32+
"match": "versions.json",
33+
"headers": {
34+
"Cache-Control": "public, max-age=60"
35+
}
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+
}
43+
}
44+
]

docs-site/astro.config.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ export default defineConfig({
5353
});
5454
`,
5555
},
56+
// Matomo analytics — loaded from root so the site ID is defined once,
57+
// not baked into each versioned build
58+
{
59+
tag: 'script',
60+
attrs: { src: '/matomo.js', async: true },
61+
},
5662
],
5763
social: [
5864
{ 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)