Vue session replay installation

  1. Install the package

    Required

    Install the PostHog JavaScript library using your package manager:

    npm install posthog-js
    Vue version

    This guide is for Vue 3 and above. For Vue 2.x, see our Vue docs.

  2. Create a composable

    Required

    Create a new file src/composables/usePostHog.js:

    src/composables/usePostHog.js
    import posthog from 'posthog-js'
    export function usePostHog() {
    posthog.init('<ph_project_api_key>', {
    api_host: 'https://us.i.posthog.com',
    defaults: '2025-11-30'
    })
    return { posthog }
    }
  3. Import in your router

    Required

    In router/index.js, import the usePostHog composable and call it:

    router/index.js
    import { createRouter, createWebHistory } from 'vue-router'
    import HomeView from '../views/HomeView.vue'
    import { usePostHog } from '@/composables/usePostHog'
    const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    routes: [
    {
    path: '/',
    name: 'home',
    component: HomeView,
    },
    {
    path: '/about',
    name: 'about',
    component: () => import('../views/AboutView.vue'),
    },
    ],
    })
    const { posthog } = usePostHog()
    export default router
  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.