Skip to content

Add Google Analytics with a BUILD_ENV-driven site config#408

Merged
erinxocon merged 2 commits into
masterfrom
add-google-analytics
Jul 14, 2026
Merged

Add Google Analytics with a BUILD_ENV-driven site config#408
erinxocon merged 2 commits into
masterfrom
add-google-analytics

Conversation

@erinxocon

Copy link
Copy Markdown
Member

Summary

  • Replace the PROD-based ternary in astro.config.mjs with a BUILD_ENV env var (local / staging / production) read via process.env, since config files evaluate before Vite loads .env/import.meta.env. Unknown values throw a clear error.
    • local (or unset) → http://localhost:4321/tech-docs
    • staginghttps://genesis76.com/tech-docs
    • productionhttps://system76.com/tech-docs
  • Convert astro.config.mjsastro.config.ts for proper typing of the new config.
  • Add Google Analytics (gtag.js) via Starlight's native head config option, gated to only load when BUILD_ENV === "production".
  • Wire BUILD_ENV: staging / BUILD_ENV: production into the corresponding GitHub Actions deploy workflows.

…taging / production) read via process.env (not import.meta.env Unknown values throw a clear error. staging resolves to https://genesis76.com/tech-docs, production to https://system76.com/tech-docs, unset/local to http://localhost:4321/tech-docs

- set BUILD_ENV: staging / BUILD_ENV: production on the pnpm build step.
CI's build step (ci.yml) is left without BUILD_ENV, so it defaults to local — fine since it only checks the build succeeds.
…LD_ENV variable (local/staging/production);

-convert astro.config.mjs to astro.config.ts.
@erinxocon
erinxocon force-pushed the add-google-analytics branch from 294779f to cdd4bc9 Compare July 14, 2026 03:46
@erinxocon
erinxocon requested review from a team and jacobgkau and removed request for a team July 14, 2026 03:47

@jacobgkau jacobgkau left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine locally with the tag not present.

@erinxocon
erinxocon merged commit 52646a5 into master Jul 14, 2026
1 check passed
@erinxocon
erinxocon deleted the add-google-analytics branch July 14, 2026 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants