Nuxt session replay installation

  1. Install the package

    Required

    Install the PostHog JavaScript library using your package manager:

    npm install posthog-js
    Nuxt version

    This guide is for Nuxt v3.0 and above. For Nuxt v2.16 and below, see our Nuxt docs.

  2. Add environment variables

    Required

    Add your PostHog API key and host to your nuxt.config.js file:

    nuxt.config.js
    export default defineNuxtConfig({
    runtimeConfig: {
    public: {
    posthogPublicKey: '<ph_project_api_key>',
    posthogHost: 'https://us.i.posthog.com',
    posthogDefaults: '2025-11-30'
    }
    }
    })
  3. Create a plugin

    Required

    Create a new plugin by creating a new file posthog.client.js in your plugins directory:

    plugins/posthog.client.js
    import { defineNuxtPlugin } from '#app'
    import posthog from 'posthog-js'
    export default defineNuxtPlugin(nuxtApp => {
    const runtimeConfig = useRuntimeConfig();
    const posthogClient = posthog.init(runtimeConfig.public.posthogPublicKey, {
    api_host: runtimeConfig.public.posthogHost,
    defaults: runtimeConfig.public.posthogDefaults,
    loaded: (posthog) => {
    if (import.meta.env.MODE === 'development') posthog.debug();
    }
    })
    return {
    provide: {
    posthog: () => posthogClient
    }
    }
    })
  4. Watch session recordings

    Recommended

    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.

    Watch your first recording →

  5. Next steps

    Recommended

    Now that you're recording sessions, continue with the resources below to learn what else Session Replay enables within the PostHog platform.

    ResourceDescription
    Watching recordingsHow to find and watch session recordings
    Privacy controlsHow to mask sensitive data in recordings
    Network recordingHow to capture network requests in recordings
    Console log recordingHow to capture console logs in recordings
    More tutorialsOther real-world examples and use cases

Community questions

Was this page useful?

Questions about this page? or post a community question.