chore(gtag): add analytics tracking - #42
Merged
Merged
Conversation
shrinkray
commented
Aug 13, 2026
Contributor
- add new Google Analytics tracking asset, set with env variable
- update docs
- add new tracking property - update docs
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Removed the redundant window.gtag = gtag; from src/layouts/BaseLayout.astro. The function gtag() declaration already puts it on window.
Contributor
There was a problem hiding this comment.
Pull request overview
Adds optional Google Analytics 4 (gtag.js) tracking to the Astro site, controlled via a public environment variable, and documents how to enable it alongside existing Vercel Analytics.
Changes:
- Inject GA4
gtag.js+ manual pageview tracking inBaseLayoutwhenPUBLIC_GA_MEASUREMENT_IDis set. - Add
PUBLIC_GA_MEASUREMENT_IDtyping toImportMetaEnv. - Document the new optional GA4 configuration in
README.mdand.env.example.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/layouts/BaseLayout.astro | Conditionally loads GA4 tag and records page views on astro:page-load when configured. |
| src/env.d.ts | Adds TypeScript env typing for PUBLIC_GA_MEASUREMENT_ID. |
| README.md | Documents enabling GA4 via PUBLIC_GA_MEASUREMENT_ID and updates features list. |
| .env.example | Provides an example and notes for the optional GA4 env var. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- pushing via window.dataLayer explicitly
- prettier-plugin-astro was misparsing the define:vars script body. - build the gtag bootstrap as a string in the frontmatter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.