0.8.0
Minor Changes
-
#4091
3336dbfThanks @dustinbyrne! - Replace thegetPostHogandgetServerSidePostHogexports with acreatePostHog()factory. Configure PostHog once in a shared module — including an optionalgetDistinctIdresolver that attributes server-side events and feature flags to the authenticated user — and use the returnedgetPostHogeverywhere.import 'server-only' import { createPostHog } from '@posthog/next' export const { getPostHog } = createPostHog()
Pass
getDistinctIdto 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 returnedgetPostHog(ctx)requires theGetServerSidePropsContextand 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.
getPostHogis still async,ctxis still required in the Pages Router, and per-callapiKey/optionsmove intocreatePostHog():// 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)becomesgetPostHog(ctx). (2026-07-09)
Patch Changes
- #4091
3336dbfThanks @dustinbyrne! - Fix Pages Router server clients to apply request context after async initialization: the Pages Router path ofcreatePostHog().getPostHog(ctx)now wraps method calls inwithContextinstead of callingenterContext, which does not propagate back to the caller across the helper's await boundary.
(2026-07-09) - Updated dependencies [
e6b5ab2,d0e531a]:- @posthog/core@1.40.1