Skip to content

Commit e529fc0

Browse files
authored
feat: environment variables in Node.js article (#38)
* feat: working on env vars article + do not run analytics in dev mode * feat: env vars article improvements (fact fixes, when-to-use section, intro rework) * fix: extract Analytics component so prod-only analytics rendering parses correctly
1 parent 857a441 commit e529fc0

5 files changed

Lines changed: 768 additions & 22 deletions

File tree

‎.claude/content-calendar.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
| # | Status | Article | Primary Keyword | Est. Volume | Pillar |
2323
| --- | ----------- | -------------------------------- | ------------------------------- | ----------- | --------- |
2424
| 1 | COMPLETE | **HTTP request in Node.js** | "node js http request" | 15,000+ | Core APIs |
25-
| 2 | NOT STARTED | Environment variables in Node.js | "node js environment variables" | 8,000+ | Core APIs |
25+
| 2 | COMPLETE | **Environment variables in Node.js** | "node js environment variables" | 8,000+ | Core APIs |
2626
| 3 | NOT STARTED | Using Node.js built-in SQLite | "node js sqlite" | 5,000+ | Modern |
2727
| 4 | NOT STARTED | Writing a CLI with Node.js | "node js cli" | 4,000+ | Core APIs |
2828

‎.prettierignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.agents/
12
.claude/
23
.tmp/
34
pnpm-lock.yaml

‎src/Layout.astro‎

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
import './styles/global.css'
33
import { Font } from 'astro:assets'
4+
import Analytics from './components/Analytics.astro'
45
import Navigation from './components/Navigation.astro'
56
import ThemeSelector from './components/ThemeSelector.astro'
67
import {
@@ -246,27 +247,7 @@ const {
246247
<Font cssVariable="--font-base-serif" preload />
247248
<Font cssVariable="--font-base-mono" preload />
248249

249-
<!-- Google tag (gtag.js) -->
250-
<script
251-
is:inline
252-
async
253-
src="https://www.googletagmanager.com/gtag/js?id=G-NFE37ZH2W3"></script>
254-
<script is:inline>
255-
window.dataLayer = window.dataLayer || []
256-
function gtag() {
257-
// eslint-disable-next-line no-undef
258-
dataLayer.push(arguments)
259-
}
260-
gtag('js', new Date())
261-
// Disable all tracking by default
262-
gtag('consent', 'default', {
263-
ad_storage: 'denied',
264-
ad_user_data: 'denied',
265-
ad_personalization: 'denied',
266-
// analytics_storage: 'denied',
267-
})
268-
gtag('config', 'G-NFE37ZH2W3')
269-
</script>
250+
{import.meta.env.PROD && <Analytics />}
270251
</head>
271252
<body
272253
class="antialiased transition-colors duration-300 bg-base-100 text-base-content"

‎src/components/Analytics.astro‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
// Google Analytics (gtag.js). Rendered by Layout.astro only in production
3+
// builds so that local development does not send tracking data.
4+
---
5+
6+
<!-- Google tag (gtag.js) -->
7+
<script
8+
is:inline
9+
async
10+
src="https://www.googletagmanager.com/gtag/js?id=G-NFE37ZH2W3"></script>
11+
<script is:inline>
12+
window.dataLayer = window.dataLayer || []
13+
function gtag() {
14+
// eslint-disable-next-line no-undef
15+
dataLayer.push(arguments)
16+
}
17+
gtag('js', new Date())
18+
// Disable all tracking by default
19+
gtag('consent', 'default', {
20+
ad_storage: 'denied',
21+
ad_user_data: 'denied',
22+
ad_personalization: 'denied',
23+
// analytics_storage: 'denied',
24+
})
25+
gtag('config', 'G-NFE37ZH2W3')
26+
</script>

0 commit comments

Comments
 (0)