Skip to content

Commit 0ccbf69

Browse files
committed
feat: install GTM
1 parent 8403e15 commit 0ccbf69

3 files changed

Lines changed: 27 additions & 4 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ jobs:
2626

2727
- run: npm ci
2828
- run: npm run build
29+
env:
30+
PUBLIC_GTM_ID: ${{ vars.PUBLIC_GTM_ID }}
2931

3032
- uses: actions/upload-pages-artifact@v3
3133
with:

CLAUDE.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,12 @@ Chart.register(LineController, LineElement, PointElement, LinearScale, Tooltip);
9292
3. Provide values for all years 1970–2026 following S-curve shape
9393
4. No code changes needed — charts load data dynamically
9494

95-
## Deployment (future)
96-
Cloudflare Pages via GitHub Actions with `cloudflare/wrangler-action`.
97-
Secrets needed: `CLOUDFLARE_API_TOKEN`, `CLOUDFLARE_ACCOUNT_ID`.
98-
Project name: `devdrift-dev`. Build output: `devdrift/dist/`.
95+
## Deployment
96+
GitHub Pages via GitHub Actions (`.github/workflows/deploy.yml`). Every push to `main` builds and publishes `dist/`.
97+
98+
## Analytics
99+
Google Tag Manager is injected into `BaseLayout.astro` when `PUBLIC_GTM_ID` is set at build time. GA4 is configured inside the GTM container (not in code), so tag changes never require a redeploy.
100+
101+
- Local: set `PUBLIC_GTM_ID=GTM-XXXXXXX` in `devdrift/.env` (gitignored).
102+
- CI: set a repository **Variable** `PUBLIC_GTM_ID` in GitHub → Settings → Secrets and variables → Actions → Variables. The deploy workflow passes it to the build step via `env:`.
103+
- When unset, the snippet is omitted entirely (graceful no-op for local dev).

src/layouts/BaseLayout.astro

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,23 @@ const {
77
title = 'DevDrift — How Programming Changed · 1970–2026',
88
description = 'An open-source timeline documenting how the skills and expectations of software developers have evolved from 1970 to 2026.'
99
} = Astro.props;
10+
const GTM_ID = import.meta.env.PUBLIC_GTM_ID;
1011
---
1112
<!DOCTYPE html>
1213
<html lang="en">
1314
<head>
1415
<meta charset="UTF-8" />
1516
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
1617
<title>{title}</title>
18+
{GTM_ID && (
19+
<script is:inline define:vars={{ GTM_ID }}>
20+
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
21+
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
22+
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
23+
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
24+
})(window,document,'script','dataLayer',GTM_ID);
25+
</script>
26+
)}
1727
<meta name="description" content={description} />
1828
<meta property="og:title" content={title} />
1929
<meta property="og:description" content={description} />
@@ -27,6 +37,12 @@ const {
2737
<link rel="stylesheet" href="/src/styles/global.css" />
2838
</head>
2939
<body class="min-h-screen" style="background:#1E1E1E;color:#F2F0E5;font-family:'Inter',system-ui,sans-serif;">
40+
{GTM_ID && (
41+
<noscript>
42+
<iframe src={`https://www.googletagmanager.com/ns.html?id=${GTM_ID}`}
43+
height="0" width="0" style="display:none;visibility:hidden"></iframe>
44+
</noscript>
45+
)}
3046
<slot />
3147
</body>
3248
</html>

0 commit comments

Comments
 (0)