Page Views in PostHog track every time a user lands on a page. Unlike simpler analytics, PostHog doesn't just count—it captures the full context: URL, referrer, device, and session. This matters because you need that data to understand which pages matter most and why users drop off.
How Page Views Work in PostHog
PostHog automatically captures page views via the $pageview event whenever a user navigates to a new page.
Understand automatic $pageview capture
When you install the PostHog web SDK, it automatically fires a $pageview event on every page load or URL change. This works without additional code. Each event includes properties like the current URL, referrer, viewport size, and device info—all captured server-side with PostHog's reserved $ prefix.
import posthog from 'posthog-js'
posthog.init('phc_YOUR_API_KEY', {
api_host: 'https://app.posthog.com',
autocapture: true // Enables automatic $pageview events
})Ensure page views are captured in single-page apps
PostHog includes $current_url, $referrer, $pathname, and device properties in every $pageview event automatically. In single-page apps (React, Vue, Next.js), the SDK detects route changes and fires $pageview accordingly. If your framework uses client-side routing that PostHog doesn't detect, you'll need manual event capture.
import { useEffect } from 'react'
import { useRouter } from 'next/router'
import posthog from 'posthog-js'
export default function MyApp() {
const router = useRouter()
useEffect(() => {
const handleRouteChange = () => {
posthog.capture('$pageview')
}
router.events.on('routeChangeComplete', handleRouteChange)
return () => router.events.off('routeChangeComplete', handleRouteChange)
}, [router.events])
return null
}/#/dashboard), the SDK often won't detect navigation as page changes. You'll need to manually fire posthog.capture('$pageview') on hash change.Analyzing Page Views in PostHog
Once page views are captured, filter and segment them in PostHog's interface to understand traffic patterns.
Filter and segment by path in Insights
In Insights, create an event query and select $pageview. Then segment by $pathname to see which pages get the most traffic. Use Trends to graph page views over time, or Table view to see individual events with full properties. PostHog shows you $current_url (full URL with query params) and $pathname (just the path) separately.
// Using PostHog API to query page views by pathname
const response = await fetch('https://app.posthog.com/api/event/', {
method: 'GET',
headers: {
'Authorization': `Bearer ${POSTHOG_API_KEY}`,
'Content-Type': 'application/json'
}
})
const pageViewEvents = await response.json()
const pricingPageViews = pageViewEvents.filter(
e => e.event === '$pageview' && e.properties.$pathname === '/pricing'
)Build funnels starting with page views
Create a funnel that starts with $pageview on your landing page, then adds downstream events like signups or purchases. This shows exactly where users drop off. In Funnels, select $pageview as your first step, filter by path, then add subsequent actions. Segment by user properties to compare conversion rates across user types.
// Enhance $pageview events with custom properties for funnel analysis
posthog.capture('$pageview', {
properties: {
$current_url: window.location.href,
page_category: 'landing',
traffic_source: 'organic',
utm_campaign: 'q1-2026'
}
})Handling Edge Cases with Page Views
Some setups need special handling to capture page views correctly.
Manually track page views in hash-based routing
If your app uses hash-based routing (e.g., example.com/#/dashboard), the PostHog SDK won't detect navigation as page changes. Listen for hashchange events and manually call posthog.capture('$pageview'). Without this, PostHog records all routes as the same page.
// Track page views in hash-based routing
window.addEventListener('hashchange', () => {
posthog.capture('$pageview', {
properties: {
$current_url: window.location.href
}
})
})
// Also capture on initial load if using hash routing
if (window.location.hash) {
posthog.capture('$pageview')
}Common Pitfalls
- Confusing page views with sessions—PostHog tracks both separately. One session can contain multiple page views.
- Not distinguishing
$pathnamefrom$current_url—pathname is just the path (e.g., '/pricing'), while current_url includes the full URL with query parameters. Filter by the right one for your use case. - Forgetting that SPAs require manual capture—client-side routing doesn't reload the page, so PostHog won't fire
$pageviewunless you manually call it. - Treating all $pageview events as unique visitors—PostHog groups page views by session and user ID. A single user refreshing a page twice creates two page view events but represents one visitor.
Wrapping Up
Page Views in PostHog track every page a user visits, giving you the context to understand traffic patterns and behavior. By using $pageview events in funnels, trends, and cohorts, you can diagnose drop-off and identify high-value pages. If you want to track this automatically across tools, Product Analyst can help.