Skip to content

fix(docs): track SPA navigation in Google Analytics#221

Merged
polaz merged 3 commits intomainfrom
fix/#220-ga-spa-tracking
Jan 25, 2026
Merged

fix(docs): track SPA navigation in Google Analytics#221
polaz merged 3 commits intomainfrom
fix/#220-ga-spa-tracking

Conversation

@polaz
Copy link
Copy Markdown
Member

@polaz polaz commented Jan 25, 2026

Summary

  • Remove broken vitepress-plugin-google-analytics plugin that only tracked initial page load
  • Implement proper GA4 integration using VitePress router hooks
  • Now tracks all SPA navigations, not just the first page

Problem

The plugin only sent page_view on initial load:

gtag('config', id)  // One-time - ignores SPA navigation

Solution

Watch VitePress router and send page_view for every navigation:

watch(() => router.route.path, (path) => {
  trackPageView(path);
});

Test plan

  • Deploy to staging
  • Open GA4 Real-Time view
  • Navigate between multiple pages
  • Verify each page appears in Real-Time events

Fixes #220

- Remove vitepress-plugin-google-analytics (only tracked initial page load)
- Implement proper GA4 integration using VitePress router hooks
- Send page_view events on initial load and all SPA navigations
- Include page_path, page_location, and page_title in events

Fixes #220
Copilot AI review requested due to automatic review settings January 25, 2026 17:39
@github-actions
Copy link
Copy Markdown

Test Coverage Report

Overall Coverage: 94.34%

Metric Percentage
Statements 93.76%
Branches 85.4%
Functions 84.26%
Lines 94.34%

View detailed coverage report

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes Google Analytics tracking in the VitePress documentation site by replacing a broken plugin that only tracked initial page loads with a custom GA4 integration that properly tracks all SPA navigation events.

Changes:

  • Removed vitepress-plugin-google-analytics dependency that only sent page_view on initial load
  • Implemented custom GA4 integration using VitePress router hooks to track all SPA navigations
  • Used Vue's watch to monitor route changes and send page_view events for each navigation

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 4 comments.

File Description
package.json Removed vitepress-plugin-google-analytics dependency
yarn.lock Removed lockfile entries for the deleted plugin
docs/.vitepress/theme/index.ts Implemented custom GA4 integration with router watching for SPA navigation tracking

polaz added 2 commits January 25, 2026 20:50
- Replace setTimeout(100ms) with nextTick for DOM-ready timing
- Add explicit type annotation for watch callback path parameter
- Document GA_ID fallback value as production property
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 3 changed files in this pull request and generated no new comments.

@polaz polaz merged commit 252f0be into main Jan 25, 2026
27 checks passed
@polaz polaz deleted the fix/#220-ga-spa-tracking branch January 25, 2026 19:00
sw-release-bot bot pushed a commit that referenced this pull request Jan 25, 2026
## [6.48.1](v6.48.0...v6.48.1) (2026-01-25)

### Bug Fixes

* **ci:** remove deleted worker deploy job ([#227](#227)) ([f33f3ba](f33f3ba)), closes [#223](#223) [#226](#226)
* **docs:** track SPA navigation in Google Analytics ([#221](#221)) ([252f0be](252f0be)), closes [#220](#220)
@sw-release-bot
Copy link
Copy Markdown

🎉 This PR is included in version 6.48.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(docs): Google Analytics not tracking SPA navigation in VitePress

2 participants