fix: replace hardcoded GA tracking ID with environment variable#313
fix: replace hardcoded GA tracking ID with environment variable#313mohitjeswani01 wants to merge 1 commit into
Conversation
✅ Deploy Preview for kmesh-net ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Welcome @mohitjeswani01! It looks like this is your first PR to kmesh-net/website 🎉 |
0912096 to
092e6df
Compare
There was a problem hiding this comment.
Pull request overview
This PR removes the hardcoded Google Analytics tracking ID from the Docusaurus configuration and switches to using GA_TRACKING_ID from the build environment, with a guard that omits the gtag config entirely when the variable is unset.
Changes:
- Replace hardcoded GA tracking ID with a conditional
process.env.GA_TRACKING_IDconfig block indocusaurus.config.js. - Add a new GitHub Actions workflow to build the site and pass
GA_TRACKING_IDfrom repository variables. - Add
.env.exampleand ignore.envin git to support local configuration without committing env files.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
docusaurus.config.js |
Conditionally includes gtag config only when GA_TRACKING_ID is set. |
.gitignore |
Ignores .env to avoid committing local environment files. |
.github/workflows/build.yml |
Adds CI build job and injects GA_TRACKING_ID from ${{ vars.GA_TRACKING_ID }}. |
.env.example |
Provides a template for setting GA_TRACKING_ID. |
Comments suppressed due to low confidence (1)
.github/workflows/build.yml:26
- The workflow runs
npm ci, but this repository does not include apackage-lock.json(onlyyarn.lock).npm ciwill fail without a lockfile. Switch tonpm install(as done in.github/workflows/versioning.yml) or adopt Yarn and install with a frozen lockfile.
- name: Install dependencies
run: npm ci
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@yashisrani @Jayesh0167 @LiZhenCheng9527 interested and looking forward for your review and ready to align as you guide ! |
Signed-off-by: Mohit Jeswani <2022.mohit.jeswani@ves.ac.in>
092e6df to
c55e1cc
Compare
There was a problem hiding this comment.
Code Review
This pull request introduces environment variable support for Google Analytics tracking by adding an .env.example file, updating .gitignore, and modifying docusaurus.config.js to use process.env.GA_TRACKING_ID. Feedback indicates that the CI workflow file required to pass this variable is missing from the PR, which will cause tracking to be disabled in production. Furthermore, it was noted that Docusaurus does not automatically load .env files into the configuration, so the use of dotenv or manual shell configuration is needed for local development.
Summary
Fixes #252
Replaces the hardcoded Google Analytics tracking ID in
docusaurus.config.jswith an environment variable (GA_TRACKING_ID), following maintainer guidance from @hzxuzhonghu to usevars.GA_TRACKING_IDas a repository configuration variable.Why not
secrets?The maintainer explicitly created a repository variable (not secret) named
GA_TRACKING_ID. This PR uses${{ vars.GA_TRACKING_ID }}accordingly — GA tracking IDs are not sensitive and don't need to be encrypted.What went wrong with PR #283
PR #283 attempted to fix this issue but fails the Netlify build CI check because it uses:
Docusaurus's
@docusaurus/plugin-google-gtagvalidates thattrackingIDmust be a non-empty string matching the GA format. An empty string""fails Joi schema validation with:This PR's approach — conditional spread
Instead of providing a fallback empty string, this PR conditionally includes the entire
gtagblock only when the environment variable is set:✅
GA_TRACKING_IDis set →gtagconfig is included → analytics works✅
GA_TRACKING_IDis NOT set →gtagconfig is omitted entirely → build succeeds with no analytics (Netlify, local dev, forks)Changes
docusaurus.config.jsprocess.env.GA_TRACKING_ID.github/workflows/build.ymlvars.GA_TRACKING_ID.env.example.gitignore.enventryBuild verification
Tested locally with

npm run build— bothenandzhlocales build successfully withoutGA_TRACKING_IDset.Checklist
vars.GA_TRACKING_ID(notsecrets) per maintainer guidanceGA_TRACKING_IDset (graceful fallback)GA_TRACKING_IDset (analytics works).envadded to.gitignore