Packages

@posthog/next

0.11.1 · 17 Nov 2026MIT95k / weekRepositorynpmAtom feed

Your version

0.8.0

9 Jul 2026Where it was published

0.11.1 is the newest release of 0.8.x.

In short

1 new1 fixed1 internal

Release note

Minor Changes

  • Replace the getPostHog and getServerSidePostHog exports with a createPostHog() factory. Configure PostHog once in a shared module — including an optional getDistinctId resolver that attributes server-side events and feature flags to the authenticated user — and use the returned getPostHog everywhere.

    import 'server-only'
    import { createPostHog } from '@posthog/next'
    
    export const { getPostHog } = createPostHog()

    Pass getDistinctId to resolve identity from your auth session:

    import 'server-only'
    import { createPostHog } from '@posthog/next'
    import { auth } from '@/auth'
    
    export const { getPostHog } = createPostHog({
        getDistinctId: async () => (await auth())?.user?.id,
    })

    In the Pages Router, import from @posthog/next/pages; the returned getPostHog(ctx) requires the GetServerSidePropsContext and passes it to the resolver:

    import { createPostHog } from '@posthog/next/pages'
    
    export const { getPostHog } = createPostHog({
        getDistinctId: async (ctx) =>
            ctx ? (await getServerSession(ctx.req, ctx.res, authOptions))?.user?.id : undefined,
    })

    Call sites are unchanged apart from the import. getPostHog is still async, ctx is still required in the Pages Router, and per-call apiKey/options move into createPostHog():

    // Before
    import { getPostHog } from '@posthog/next'
    const posthog = await getPostHog(apiKey, { host })
    
    // After
    import { getPostHog } from '@/lib/posthog'
    const posthog = await getPostHog()

    In the Pages Router, getServerSidePostHog(ctx) becomes getPostHog(ctx). (2026-07-09)

Patch Changes

  • Fix Pages Router server clients to apply request context after async initialization: the Pages Router path of createPostHog().getPostHog(ctx) now wraps method calls in withContext instead of calling enterContext, which does not propagate back to the caller across the helper's await boundary.
    (2026-07-09)

A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.