Skip to content

feat: SPA page tracking for VitePress and Vue Router#22

Merged
polaz merged 3 commits intomainfrom
feature/#21-spa-page-tracking
Jan 31, 2026
Merged

feat: SPA page tracking for VitePress and Vue Router#22
polaz merged 3 commits intomainfrom
feature/#21-spa-page-tracking

Conversation

@polaz
Copy link
Copy Markdown
Member

@polaz polaz commented Jan 31, 2026

Summary

  • Add sendPageView config option to disable automatic page_view for SPA apps
  • Add trackPageView() method to gtag, ConsentManager, and useConsent() composable
  • VitePress enhanceWithConsent() now auto-tracks SPA navigation via router watch
  • Pass send_page_view option through to gtag("config", ...) call

Test plan

  • yarn build passes
  • yarn test passes
  • yarn lint clean
  • VitePress docs site tracks page views correctly in GA4 DebugView

Closes #21

- 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
Copy link
Copy Markdown
Contributor

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 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 sendPageView configuration 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.

Comment thread src/core/consent-manager.ts
Comment thread src/core/gtag.ts Outdated
Comment thread src/vitepress/index.ts
Comment thread src/vitepress/index.ts
Comment thread src/vitepress/index.ts
polaz added 2 commits January 31, 2026 14:13
- 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
@polaz polaz merged commit 5ca7805 into main Jan 31, 2026
2 checks passed
@polaz polaz deleted the feature/#21-spa-page-tracking branch January 31, 2026 12:15
sw-release-bot bot pushed a commit that referenced this pull request Jan 31, 2026
## [1.1.0](v1.0.0...v1.1.0) (2026-01-31)

### Features

* SPA page tracking for VitePress and Vue Router ([#22](#22)) ([5ca7805](5ca7805)), closes [#21](#21)
@sw-release-bot
Copy link
Copy Markdown

🎉 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
polaz pushed a commit that referenced this pull request Jan 31, 2026
## [1.1.0](v1.0.0...v1.1.0) (2026-01-31)

### Features

* SPA page tracking for VitePress and Vue Router ([#22](#22)) ([1ab76f6](1ab76f6)), closes [#21](#21)
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.

feat: SPA page tracking support for VitePress and Vue Router

2 participants