Skip to content

Commit 6ba29a3

Browse files
committed
Add Plausible analytics to blog and docs builds
1 parent 46bee50 commit 6ba29a3

57 files changed

Lines changed: 399 additions & 10 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
"test:fixtures": "node test/fixtures/run.mjs",
1313
"test:anonymous": "node test/anonymous/run.mjs",
1414
"build:blog": "node scripts/build-blog.mjs",
15-
"build:web": "node web/build/build.mjs",
15+
"build:docs": "node scripts/build-docs.mjs",
16+
"build:web:landing": "node web/build/build.mjs",
17+
"build:web": "npm run build:web:landing && npm run build:blog && npm run build:docs",
1618
"build:zip": "node scripts/build-zip.mjs",
1719
"sync:logo": "python3 scripts/sync-logo-assets.py && python3 scripts/gen-store-promos.py && node assets/webstore-explainer-2026/render.mjs",
1820
"bump": "node scripts/bump-version.mjs",

scripts/build-blog.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { mkdir, readdir, readFile, stat, writeFile } from 'node:fs/promises';
3737
import { existsSync } from 'node:fs';
3838
import path from 'node:path';
3939
import { fileURLToPath } from 'node:url';
40+
import { PLAUSIBLE_ANALYTICS } from '../web/build/plausible.mjs';
4041

4142
const __dirname = path.dirname(fileURLToPath(import.meta.url));
4243
const REPO_ROOT = path.resolve(__dirname, '..');
@@ -1168,6 +1169,7 @@ function sharedHead({ title, description, canonical, ogType = 'website', ogTitle
11681169
${hreflangLinks(site)}
11691170
${blogStyle()}
11701171
${themeBootstrapScript()}
1172+
${PLAUSIBLE_ANALYTICS}
11711173
<script type="application/ld+json">
11721174
${escJsonLd(jsonLd)}
11731175
</script>

scripts/build-docs.mjs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env node
2+
/**
3+
* Ensures every documentation page includes the shared site analytics partial.
4+
*
5+
* This idempotent pass recursively covers new HTML pages added under web/docs,
6+
* so authors do not have to copy the analytics block page by page.
7+
*/
8+
9+
import { readdir, readFile, writeFile } from 'node:fs/promises';
10+
import path from 'node:path';
11+
import { fileURLToPath } from 'node:url';
12+
import { PLAUSIBLE_SCRIPT_URL, withPlausibleAnalytics } from '../web/build/plausible.mjs';
13+
14+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
15+
const REPO_ROOT = path.resolve(__dirname, '..');
16+
const DOCS_DIR = path.join(REPO_ROOT, 'web', 'docs');
17+
18+
async function listHtmlFiles(dir) {
19+
const files = [];
20+
for (const entry of await readdir(dir, { withFileTypes: true })) {
21+
const fullPath = path.join(dir, entry.name);
22+
if (entry.isDirectory()) files.push(...await listHtmlFiles(fullPath));
23+
else if (entry.isFile() && entry.name.endsWith('.html')) files.push(fullPath);
24+
}
25+
return files.sort();
26+
}
27+
28+
async function main() {
29+
const files = await listHtmlFiles(DOCS_DIR);
30+
for (const file of files) {
31+
const original = await readFile(file, 'utf8');
32+
const generated = withPlausibleAnalytics(original);
33+
const occurrences = generated.split(PLAUSIBLE_SCRIPT_URL).length - 1;
34+
if (occurrences !== 1) {
35+
throw new Error(`${path.relative(REPO_ROOT, file)} contains ${occurrences} Plausible scripts`);
36+
}
37+
if (generated !== original) await writeFile(file, generated, 'utf8');
38+
console.log(`wrote ${path.relative(process.cwd(), file)}`);
39+
}
40+
}
41+
42+
main().catch((error) => {
43+
console.error(error);
44+
process.exit(1);
45+
});

web/ar/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,12 +2098,14 @@
20982098
})();
20992099
</script>
21002100

2101+
<!-- Plausible analytics: start -->
21012102
<!-- Privacy-friendly analytics by Plausible -->
21022103
<script async src="https://plausible.io/js/pa-yWGfwxkkKSVs-eTuaKYpy.js"></script>
21032104
<script>
21042105
window.plausible=window.plausible||function(){(plausible.q=plausible.q||[]).push(arguments)},plausible.init=plausible.init||function(i){plausible.o=i||{}};
21052106
plausible.init()
21062107
</script>
2108+
<!-- Plausible analytics: end -->
21072109
</head>
21082110
<body>
21092111

web/blog/agent-security-model/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,14 @@
456456
}
457457
})();
458458
</script>
459+
<!-- Plausible analytics: start -->
460+
<!-- Privacy-friendly analytics by Plausible -->
461+
<script async src="https://plausible.io/js/pa-yWGfwxkkKSVs-eTuaKYpy.js"></script>
462+
<script>
463+
window.plausible=window.plausible||function(){(plausible.q=plausible.q||[]).push(arguments)},plausible.init=plausible.init||function(i){plausible.o=i||{}};
464+
plausible.init()
465+
</script>
466+
<!-- Plausible analytics: end -->
459467
<script type="application/ld+json">
460468
{
461469
"@context": "https://schema.org",

web/blog/agents-a1-webbrain-planner-benchmark/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,14 @@
456456
}
457457
})();
458458
</script>
459+
<!-- Plausible analytics: start -->
460+
<!-- Privacy-friendly analytics by Plausible -->
461+
<script async src="https://plausible.io/js/pa-yWGfwxkkKSVs-eTuaKYpy.js"></script>
462+
<script>
463+
window.plausible=window.plausible||function(){(plausible.q=plausible.q||[]).push(arguments)},plausible.init=plausible.init||function(i){plausible.o=i||{}};
464+
plausible.init()
465+
</script>
466+
<!-- Plausible analytics: end -->
459467
<script type="application/ld+json">
460468
{
461469
"@context": "https://schema.org",

web/blog/five-things-you-shouldnt-do-with-webbrain/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,14 @@
456456
}
457457
})();
458458
</script>
459+
<!-- Plausible analytics: start -->
460+
<!-- Privacy-friendly analytics by Plausible -->
461+
<script async src="https://plausible.io/js/pa-yWGfwxkkKSVs-eTuaKYpy.js"></script>
462+
<script>
463+
window.plausible=window.plausible||function(){(plausible.q=plausible.q||[]).push(arguments)},plausible.init=plausible.init||function(i){plausible.o=i||{}};
464+
plausible.init()
465+
</script>
466+
<!-- Plausible analytics: end -->
459467
<script type="application/ld+json">
460468
{
461469
"@context": "https://schema.org",

web/blog/gemma-4-12b-qat-planner-benchmark/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,14 @@
456456
}
457457
})();
458458
</script>
459+
<!-- Plausible analytics: start -->
460+
<!-- Privacy-friendly analytics by Plausible -->
461+
<script async src="https://plausible.io/js/pa-yWGfwxkkKSVs-eTuaKYpy.js"></script>
462+
<script>
463+
window.plausible=window.plausible||function(){(plausible.q=plausible.q||[]).push(arguments)},plausible.init=plausible.init||function(i){plausible.o=i||{}};
464+
plausible.init()
465+
</script>
466+
<!-- Plausible analytics: end -->
459467
<script type="application/ld+json">
460468
{
461469
"@context": "https://schema.org",

web/blog/gemma-4-31b-qat-planner-benchmark/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,14 @@
456456
}
457457
})();
458458
</script>
459+
<!-- Plausible analytics: start -->
460+
<!-- Privacy-friendly analytics by Plausible -->
461+
<script async src="https://plausible.io/js/pa-yWGfwxkkKSVs-eTuaKYpy.js"></script>
462+
<script>
463+
window.plausible=window.plausible||function(){(plausible.q=plausible.q||[]).push(arguments)},plausible.init=plausible.init||function(i){plausible.o=i||{}};
464+
plausible.init()
465+
</script>
466+
<!-- Plausible analytics: end -->
459467
<script type="application/ld+json">
460468
{
461469
"@context": "https://schema.org",

web/blog/gemma4-turkish-pruning/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,14 @@
456456
}
457457
})();
458458
</script>
459+
<!-- Plausible analytics: start -->
460+
<!-- Privacy-friendly analytics by Plausible -->
461+
<script async src="https://plausible.io/js/pa-yWGfwxkkKSVs-eTuaKYpy.js"></script>
462+
<script>
463+
window.plausible=window.plausible||function(){(plausible.q=plausible.q||[]).push(arguments)},plausible.init=plausible.init||function(i){plausible.o=i||{}};
464+
plausible.init()
465+
</script>
466+
<!-- Plausible analytics: end -->
459467
<script type="application/ld+json">
460468
{
461469
"@context": "https://schema.org",

0 commit comments

Comments
 (0)