fix(docs): track SPA navigation in Google Analytics#221
Merged
Conversation
- 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
Test Coverage ReportOverall Coverage: 94.34%
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
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-analyticsdependency that only sent page_view on initial load - Implemented custom GA4 integration using VitePress router hooks to track all SPA navigations
- Used Vue's
watchto 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 |
- 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
|
🎉 This PR is included in version 6.48.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.
Summary
vitepress-plugin-google-analyticsplugin that only tracked initial page loadProblem
The plugin only sent
page_viewon initial load:Solution
Watch VitePress router and send
page_viewfor every navigation:Test plan
Fixes #220