Skip to content

Commit 54699c2

Browse files
committed
Add optional Google Analytics to docs
1 parent 76b64a2 commit 54699c2

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

.github/workflows/docs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
runs-on: ubuntu-24.04
2727
env:
2828
TERRARIUM_DOCS_BASE: ${{ vars.TERRARIUM_DOCS_BASE || '/terrarium/' }}
29+
TERRARIUM_DOCS_GA_ID: ${{ vars.TERRARIUM_DOCS_GA_ID }}
2930
steps:
3031
- name: Checkout
3132
uses: actions/checkout@v5

docs/.vitepress/config.mts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,36 @@ function resolveBase(): string {
1212
return withLeadingSlash.endsWith("/") ? withLeadingSlash : `${withLeadingSlash}/`;
1313
}
1414

15+
function resolveGoogleAnalyticsHead() {
16+
const googleAnalyticsId = process.env.TERRARIUM_DOCS_GA_ID?.trim();
17+
if (!googleAnalyticsId) {
18+
return [];
19+
}
20+
21+
return [
22+
[
23+
"script",
24+
{
25+
async: "",
26+
src: `https://www.googletagmanager.com/gtag/js?id=${encodeURIComponent(googleAnalyticsId)}`
27+
}
28+
],
29+
[
30+
"script",
31+
{},
32+
`window.dataLayer = window.dataLayer || [];
33+
function gtag(){dataLayer.push(arguments);}
34+
gtag("js", new Date());
35+
gtag("config", ${JSON.stringify(googleAnalyticsId)});`
36+
]
37+
];
38+
}
39+
1540
export default defineConfig({
1641
title: "Terrarium",
1742
description: "Secure, rewindable VPS environments for agents, dev tools, and isolated apps.",
1843
base: resolveBase(),
44+
head: resolveGoogleAnalyticsHead(),
1945
cleanUrls: true,
2046
lastUpdated: true,
2147
themeConfig: {

0 commit comments

Comments
 (0)