Skip to content

chore(gtag): add analytics tracking - #42

Merged
shrinkray merged 4 commits into
mainfrom
chore/GaTag
Aug 13, 2026
Merged

chore(gtag): add analytics tracking#42
shrinkray merged 4 commits into
mainfrom
chore/GaTag

Conversation

@shrinkray

Copy link
Copy Markdown
Contributor
  • add new Google Analytics tracking asset, set with env variable
  • update docs

- add new tracking property
- update docs
@vercel

vercel Bot commented Aug 13, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hackmi26 Ready Ready Preview Aug 13, 2026 3:45pm

Removed the redundant window.gtag = gtag; from src/layouts/BaseLayout.astro. The function gtag() declaration already puts it on window.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 in BaseLayout when PUBLIC_GA_MEASUREMENT_ID is set.
  • Add PUBLIC_GA_MEASUREMENT_ID typing to ImportMetaEnv.
  • Document the new optional GA4 configuration in README.md and .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.

Comment thread src/layouts/BaseLayout.astro Outdated
- 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
@shrinkray
shrinkray merged commit 4475a53 into main Aug 13, 2026
6 checks passed
@shrinkray
shrinkray deleted the chore/GaTag branch August 13, 2026 16:48
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