Overview
Databuddy automatically tracks pageviews in both traditional multi-page applications and modern single-page applications (SPAs). Pageviews are captured asscreen_view events with contextual information like path, title, referrer, and UTM parameters.
Automatic Tracking
Pageview tracking is enabled by default and requires no configuration. The tracker automatically detects:- Initial page load - First pageview when the tracker initializes
- Client-side navigation - Route changes in React, Vue, Next.js, and other SPA frameworks
- Browser history - Back/forward button navigation
- Hash changes - Optional, must be explicitly enabled
How It Works
The tracker intercepts browser navigation APIs:No manual tracking is needed for route changes in frameworks like Next.js, React Router, or Vue Router. The tracker automatically detects these changes.
Configuration
Track Hash Changes
By default, hash changes (e.g.,/page#section1 to /page#section2) are not tracked as separate pageviews. Enable this if you use hash-based routing:
Skip Patterns
Exclude specific paths from tracking:/admin/*- Matches/admin/users,/admin/settings, etc./admin/**- Matches all nested paths under/admin
Mask Patterns
Mask sensitive information in URLs:*- Masks one path segment:/users/123becomes/users/***- Masks all remaining segments:/users/123/profilebecomes/users/*
Manual Tracking
You can manually track pageviews using thescreenView() function.
Function Signature
Basic Usage
With Properties
Add custom properties to pageview events:React Router Example
Pageview Data
Eachscreen_view event includes:
Automatic Properties
Full URL including origin, path, search params, and hash.
Example:
https://example.com/products?category=widgets#reviewsDocument title from
<title> tag.Previous page URL or
"direct" if none.Number of pages viewed in the current session.
Browser viewport dimensions in format
"width x height" (e.g., "1920x1080").User’s timezone from
Intl.DateTimeFormat(). Example: "America/New_York"Browser language from
navigator.language. Example: "en-US"UTM Parameters
UTM parameters from the URL are automatically captured:Traffic source. Example:
"google", "newsletter"Marketing medium. Example:
"cpc", "email"Campaign name. Example:
"spring_sale"Paid search keywords.
Content variation identifier for A/B testing.
Session Context
Persistent user identifier (stored in localStorage).
Format:
"anon_[uuid]"Current session identifier (stored in sessionStorage).
Format:
"sess_[uuid]"Event timestamp in milliseconds since epoch.
Page Exit Events
Databuddy automatically tracks when users leave a page withpage_exit events. These include engagement metrics:
- On navigation to another page
- On window
beforeunloadevent (closing tab, external navigation) - On window
pagehideevent (mobile browsers)
Advanced Scenarios
Custom Event Filter
Filter pageviews based on custom logic:Sampling
Track only a percentage of pageviews:Back/Forward Cache (bfcache)
The tracker automatically handles browser back/forward cache restoration:Troubleshooting
Pageviews Not Tracked
- Check initialization: Ensure the tracker is loaded before navigation occurs
- Verify client ID: Confirm your
clientIdis set correctly - Check skip patterns: Make sure the path isn’t excluded by
skipPatterns - Enable debug mode: Add
debugprop to see tracking logs
Duplicate Pageviews
If you see duplicate pageviews:- Remove manual tracking: Don’t call
screenView()if automatic tracking is enabled - Check framework integration: Ensure you’re not tracking the same navigation twice
- Verify hash change setting: Disable
trackHashChangesif not needed
Related Documentation
- Sessions - Session lifecycle and expiration
- User Identification - Anonymous and session IDs
- Custom Events - Track user interactions