feat(nuxt): re-add Google Analytics via nuxt-gtag - #126
Conversation
Restores GA4 pageview tracking (property G-X1BRPZD4K2), lost when the legacy nuxt/plugins/gtag.js was deleted wholesale as part of the Nuxt 4 rewrite. Uses nuxt-gtag (the Nuxt 3/4-native successor to vue-gtag) instead of porting the old plugin; production-only via enabled: !import.meta.dev, matching the old plugin's dev-skip behaviour. SPA route-change tracking comes from nuxt-gtag's built-in router integration — no manual plugin needed since the site is fully prerendered. See openspec/changes/add-analytics-gtag/ for the proposal.
✅ Deploy Preview for stuartc ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Warning Review limit reached
Next review available in: 34 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. 📝 WalkthroughWalkthroughAdded ChangesGA4 analytics integration
Estimated code review effort: 1 (Trivial) | ~5 minutes Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant NuxtApp
participant NuxtGtag
participant GA4
NuxtApp->>NuxtGtag: Initialize when not in development
NuxtGtag->>GA4: Send events for G-X1BRPZD4K2
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@nuxt/nuxt.config.ts`:
- Around line 37-40: Update the gtag.enabled configuration in nuxt.config.ts to
use the host’s explicit production deploy context, such as NETLIFY_CONTEXT ===
'production', instead of import.meta.dev. Ensure GA4 events are enabled only for
the canonical production deployment and remain disabled for previews and branch
builds.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 12bfe54f-2ed9-4ac4-b771-8b8e52f5c953
⛔ Files ignored due to path filters (1)
nuxt/pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (3)
AGENTS.mdnuxt/nuxt.config.tsnuxt/package.json
enabled: !import.meta.dev fired on any non-dev build, including this PR's own deploy preview and future branch deploys — both send real traffic into the production GA4 property. Restrict to NETLIFY_CONTEXT === 'production' instead. Caught by CodeRabbit review on PR #126.
What
Restores GA4 pageview tracking, lost when the legacy
nuxt/plugins/gtag.js(vue-gtag) was deleted wholesale as part of the Nuxt 4 rewrite — the deletion was a side effect of replacing the whole legacy tree, not an intentional decision to drop analytics.nuxt-gtag(the maintained Nuxt 3/4-native successor tovue-gtag) and registers it innuxt.config.tsG-X1BRPZD4K2) — same site identity, no new property neededenabled: !import.meta.dev), matching the old plugin's dev-skip behaviournuxt-gtag's built-in router integration (site is fully prerendered, no manual plugin needed)AGENTS.md's tech-stack list so it isn't silently dropped again in a future rewriteVerification
pnpm typecheck— cleanpnpm lint— cleanpnpm test— 415/415 passingpnpm generate— confirmedG-X1BRPZD4K2/googletagmanagerpresent in generateddist/index.htmlMirrors GitLab MR !18 (this repo's primary development happens on GitLab; this PR keeps GitHub in sync). See
openspec/changes/add-analytics-gtag/(workspace root repo) for the full proposal.