5 min read

What Is Page Views in PostHog

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.

javascript
import posthog from 'posthog-js'

posthog.init('phc_YOUR_API_KEY', {
  api_host: 'https://app.posthog.com',
  autocapture: true // Enables automatic $pageview events
})
PostHog SDK automatically fires $pageview when autocapture is enabled

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.

javascript
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
}
Manually capture $pageview in Next.js if the SDK doesn't detect route changes
Watch out: If you're using hash-based routing (e.g., /#/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.

javascript
// 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'
)
Query page view events filtered by pathname using PostHog's API

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.

javascript
// 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'
  }
})
Add custom properties to $pageview for better segmentation in funnels
Tip: Combine page views with cohorts. Create a cohort of users who viewed your pricing page in the last 7 days, then email them. Use PostHog's API to export these lists.

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.

javascript
// 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')
}
Listen for hash changes and fire $pageview manually for client-side routes
Watch out: PostHog's SDK may not work in iframes or heavily sandboxed contexts. If frontend tracking fails, use PostHog's backend API or server-side event capture instead.

Common Pitfalls

  • Confusing page views with sessions—PostHog tracks both separately. One session can contain multiple page views.
  • Not distinguishing $pathname from $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 $pageview unless 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.

Track these metrics automatically

Product Analyst connects to your stack and surfaces the insights that matter.

Try Product Analyst — Free