feat: SPA page tracking for VitePress and Vue Router#22
Merged
Conversation
- Add sendPageView config option to disable automatic page_view (for SPA) - Add trackPageView() to gtag, ConsentManager, and useConsent composable - VitePress enhanceWithConsent() now auto-tracks SPA navigation via router - Pass send_page_view option through to gtag config call Closes #21
Closed
8 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds SPA (Single Page Application) page tracking support for VitePress and Vue Router by introducing manual page view tracking capabilities. The changes enable proper analytics tracking for client-side navigation in SPAs by disabling automatic page views on GA initialization and providing mechanisms to manually track page views during route changes.
Changes:
- Added
sendPageViewconfiguration option to control automatic page_view events on GA initialization - Implemented
trackPageView()method throughout the stack (gtag, ConsentManager, and useConsent composable) - Enhanced VitePress integration to automatically track SPA navigation by watching router changes
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/core/types.ts | Added sendPageView configuration option with documentation |
| src/core/gtag.ts | Implemented trackPageView() function and added sendPageView parameter to initGoogleAnalytics() |
| src/core/consent-manager.ts | Added trackPageView() and isInitialized() methods, integrated sendPageView config throughout initialization flow |
| src/vue/index.ts | Exposed trackPageView() method in the useConsent() composable |
| src/vitepress/index.ts | Refactored enhanceWithConsent() to manually manage initialization and automatically track SPA navigation via router watching |
| src/index.ts | Exported trackPageView function for direct use |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Remove redundant typeof window check in trackPageView (already guarded) - Add explicit immediate:false to VitePress router watch - Document SPA mode override and Consent Mode behavior for EU users
- Check stored consent before sending page_view events - Avoid unnecessary gtag calls when user rejected analytics
|
🎉 This PR is included in version 1.1.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
polaz
added a commit
that referenced
this pull request
Jan 31, 2026
* feat: add SPA page tracking support for VitePress and Vue Router - Add sendPageView config option to disable automatic page_view (for SPA) - Add trackPageView() to gtag, ConsentManager, and useConsent composable - VitePress enhanceWithConsent() now auto-tracks SPA navigation via router - Pass send_page_view option through to gtag config call Closes #21 * refactor: clean up redundant guards and add explicit watch options - Remove redundant typeof window check in trackPageView (already guarded) - Add explicit immediate:false to VitePress router watch - Document SPA mode override and Consent Mode behavior for EU users * fix(consent): skip page view tracking when analytics is denied - Check stored consent before sending page_view events - Avoid unnecessary gtag calls when user rejected analytics
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
sendPageViewconfig option to disable automaticpage_viewfor SPA appstrackPageView()method to gtag, ConsentManager, anduseConsent()composableenhanceWithConsent()now auto-tracks SPA navigation via router watchsend_page_viewoption through togtag("config", ...)callTest plan
yarn buildpassesyarn testpassesyarn lintcleanCloses #21