Page view tracking is how you understand what your users are actually doing on your site. PostHog captures these automatically by default, but you might need manual tracking if you're building a single-page app or want custom metadata attached to each view.
Enable Auto Page View Tracking
The easiest approach: let PostHog handle page views automatically as part of its web SDK initialization.
Install the PostHog SDK
Add the posthog-js package to your project.
npm install posthog-jsInitialize PostHog with auto-capture enabled
In your app's entry point, call posthog.init() with capture_pageview: true. This tells PostHog to automatically fire a $pageview event whenever the URL changes.
import posthog from 'posthog-js'
posthog.init('phc_YOUR_API_KEY', {
api_host: 'https://us.i.posthog.com',
capture_pageview: true
})View page views in the **Events** table
Once initialized, navigate your app normally. Go to Data management > Events and filter by $pageview. Each entry shows $pathname, $current_url, and timestamp.
// PostHog automatically captures:
// {
// event: '$pageview',
// properties: {
// $current_url: 'https://example.com/docs',
// $pathname: '/docs',
// $host: 'example.com'
// }
// }Manually Track Page Views in Single-Page Apps
For React, Vue, or Next.js apps with client-side routing, auto-capture might miss route changes. Manually fire page view events when your router detects navigation.
Listen for route changes in your router
Detect when the URL has changed. In Next.js, use the router's routeChangeComplete event. In React Router, use useEffect with useLocation.
import { useEffect } from 'react'
import { useRouter } from 'next/router'
import posthog from 'posthog-js'
export default function App() {
const router = useRouter()
useEffect(() => {
const handleRouteChange = (url) => {
posthog.capture('$pageview', {
$current_url: window.location.href
})
}
router.events.on('routeChangeComplete', handleRouteChange)
return () => router.events.off('routeChangeComplete', handleRouteChange)
}, [router.events])
return null
}Attach custom properties to describe the page
Add metadata so you can segment page views later. Include page type, section, user tier, or any ID relevant to your product.
posthog.capture('$pageview', {
$current_url: window.location.href,
page_type: 'product-listing',
category: 'electronics',
filters_applied: ['in-stock', 'under-$50']
})Disable auto-capture to avoid double-counting
If you're manually tracking, set capture_pageview: false in your init config to prevent the same page view from being recorded twice.
posthog.init('phc_YOUR_API_KEY', {
api_host: 'https://us.i.posthog.com',
capture_pageview: false // Manual tracking only
})Build Insights from Page Views
Once you're capturing page views, segment them to find patterns and drop-off points.
Create a trends insight to see your most visited pages
Go to Insights > New insight > Trends. Filter by $pageview and break down by $pathname. This shows you which pages get the most traffic and how it changes over time.
// Example filtering via the Events table:
// Filter: event = '$pageview'
// Break down by: $pathname
// Date range: Last 7 daysBuild a funnel to track the user journey
Use Insights > New funnel to add page views as conversion steps. For example: / → /pricing → /signup → /onboarding. This shows where users drop off.
// Funnel steps (configure in PostHog UI):
// Step 1: $pageview where $pathname = '/'
// Step 2: $pageview where $pathname = '/pricing'
// Step 3: $pageview where $pathname = '/signup'
// Step 4: $pageview where $pathname = '/onboarding'Common Pitfalls
- Forgetting to disable
capture_pageviewwhen switching to manual tracking — this causes every route change to be counted twice. - Not including custom properties on page views —
$pathnamealone doesn't tell you what type of content the user saw (article, product, settings, etc.). - Tracking PII in pageview events — avoid storing user names, emails, or sensitive data in
$current_urlor custom properties. - Hash-based route changes not being tracked — PostHog's auto-capture doesn't detect changes to
#/routepatterns; use manual tracking instead.
Wrapping Up
Page views are your first lens into user behavior. With auto-capture, you get them for free; with manual tracking, you get control and SPA support. Once you're tracking consistently, you can build funnels and cohorts to understand the full user journey. If you want to track this automatically across tools, Product Analyst can help.