Next.js session replay installation
Install the PostHog JavaScript library using your package manager: Add your PostHog API key and host to your Choose the integration method based on your Next.js version and router type. If you're using Next.js 15.3+, you can use For the App router, create a Then import the For the Pages router, integrate PostHog at the root of your app in The Once initialized in Use the Visit your site or app and interact with it for at least 10 seconds to generate a recording. Navigate between pages, click buttons, and fill out forms to capture meaningful interactions. Now that you're recording sessions, continue with the resources below to learn what else Session Replay enables within the PostHog platform.Install the package
RequiredAdd environment variables
Required.env.local file and to your hosting provider (e.g. Vercel, Netlify). These values need to start with NEXT_PUBLIC_ to be accessible on the client-side.Initialize PostHog
Requiredinstrumentation-client.ts for a lightweight, fast integration:providers.tsx file in your app folder. The posthog-js library needs to be initialized on the client-side using the 'use client' directive:PostHogProvider component in your app/layout.tsx and wrap your app with it:pages/_app.tsx:defaults option automatically configures PostHog with recommended settings for new projects. See SDK defaults for details.Accessing PostHog on the client
Recommendedinstrumentation-client.ts, import posthog from posthog-js anywhere and call the methods you need:usePostHog hook to access PostHog in client components:Watch session recordings
RecommendedNext steps
RecommendedResource Description Watching recordings How to find and watch session recordings Privacy controls How to mask sensitive data in recordings Network recording How to capture network requests in recordings Console log recording How to capture console logs in recordings More tutorials Other real-world examples and use cases