Contents

@posthog/next

0.11.1

Patch Changes

0.11.0

Minor Changes

  • #5473 5c8f314 Thanks @ablaszkiewicz! - feat: onRequestError takes identity from PostHog tracing headers before the cookie, drops a cookie session that posthog-js would have ended, and adds the request URL, method, path and user agent. New withPostHogProxy captures errors thrown in proxy.ts or middleware without delaying the response. Errors that escape middleware or a proxy are marked unhandled. (2026-11-03)

Patch Changes

0.10.0

Minor Changes

  • #5315 e4df2d5 Thanks @pauldambra! - Add an optional Node.js App Router span context bridge that reuses the configured PostHog client and request identity. (2026-10-28)

Patch Changes

0.9.0

Minor Changes

  • #4656 39aa650 Thanks @marandaneto! - Add opt-in $route template capture for App Router and Pages Router pageviews. (2026-09-01)

Patch Changes

0.8.6

Patch Changes

0.8.5

Patch Changes

0.8.4

Patch Changes

0.8.3

Patch Changes

  • #4152 2578f08 Thanks @dustinbyrne! - Remove the Pages Router PostHogProvider.bootstrap prop; move its value to clientOptions.bootstrap. For App Router server-evaluated bootstrap, use fresh evaluated flags and payloads while preserving configured identity and session fields. (2026-07-16)

0.8.2

Patch Changes

  • #4150 2e9405b Thanks @dustinbyrne! - Fix Pages Router SSR feature flag hooks when Node loads the CommonJS posthog-js entrypoint. (2026-07-16)

0.8.1

Patch Changes

  • #4093 4da3b41 Thanks @dustinbyrne! - Dedupe getDistinctId resolution per request in the App Router: repeated getPostHog() calls within one request (e.g. across a layout and its pages) now share a single resolver invocation, keyed on the request's headers() instance. (2026-07-14)

0.8.0

Minor Changes

  • #4091 3336dbf Thanks @dustinbyrne! - 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.

     1import "server-only";
     2import { createPostHog } from "@posthog/next";
     3
     4export const { getPostHog } = createPostHog();
    

    Pass getDistinctId to resolve identity from your auth session:

     1import "server-only";
     2import { createPostHog } from "@posthog/next";
     3import { auth } from "@/auth";
     4
     5export const { getPostHog } = createPostHog({
     6  getDistinctId: async () => (await auth())?.user?.id,
     7});
    

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

     1import { createPostHog } from "@posthog/next/pages";
     2
     3export const { getPostHog } = createPostHog({
     4  getDistinctId: async (ctx) =>
     5    ctx
     6      ? (await getServerSession(ctx.req, ctx.res, authOptions))?.user?.id
     7      : undefined,
     8});
    

    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():

     1// Before
     2import { getPostHog } from "@posthog/next";
     3const posthog = await getPostHog(apiKey, { host });
     4
     5// After
     6import { getPostHog } from "@/lib/posthog";
     7const posthog = await getPostHog();
    

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

Patch Changes

  • #4091 3336dbf Thanks @dustinbyrne! - 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)
  • Updated dependencies [e6b5ab2, d0e531a]:

0.7.2

Patch Changes

  • #4092 335dd05 Thanks @dustinbyrne! - Fix @posthog/next/pages in Pages Router server bundles so server APIs like getServerSideProps resolve correctly instead of importing the client entrypoint. (2026-07-08)

0.7.1

Patch Changes

0.7.0

Minor Changes

0.6.0

Minor Changes

  • #3925 1b0191c Thanks @dustinbyrne! - Enable exception capture by default.
    • Client-side PostHog initialization now sets capture_exceptions: true by default. Pass clientOptions.capture_exceptions to override this.
    • Apps can export onRequestError from @posthog/next in instrumentation.ts to capture server-side request errors handled by Next.js, including in the Edge runtime.
    • Alternatively, import captureRequestError and call it from onRequestError. (2026-06-23)

Patch Changes

0.5.0

Minor Changes

  • #3921 c28b161 Thanks @marandaneto! - Add disable_capture_url_hashes to strip URL fragments from automatically captured URLs. It is disabled by default for backwards compatibility, and enabled automatically when config.defaults is '2026-06-25' or later. Enabling it (either explicitly or via the '2026-06-25' defaults) is a breaking behavior change for SPAs that rely on URL hashes for routing or analytics, because hash-based routes will be collapsed to the same URL without the fragment in fields such as $current_url, $initial_current_url, $session_entry_url, autocapture $elements[*].attr__href, $external_click_url, replay href URLs, heatmaps, web vitals $current_url, logs url.full, conversations current_url/request_url, or Next.js Pages Router $pageview $current_url.

    If you only want to capture some hashes, leave hash capture enabled and use before_send to remove or redact sensitive hash values before events are sent. (2026-06-23)

Patch Changes

0.4.97

Patch Changes

  • #3886 e6d7fe2 Thanks @marandaneto! - Stop sending deprecated no-op top-level type, library, and library_version fields in event batch payloads. Use properties.$lib and properties.$lib_version for SDK metadata; legacy queued library and library_version values are used as fallbacks when the official $ properties are missing. (2026-06-18)
  • Updated dependencies [e6d7fe2]:

0.4.96

Patch Changes

0.4.95

Patch Changes

0.4.94

Patch Changes

0.4.93

Patch Changes

0.4.92

Patch Changes

0.4.91

Patch Changes

0.4.90

Patch Changes

0.4.89

Patch Changes

0.4.88

Patch Changes

0.4.87

Patch Changes

0.4.86

Patch Changes

0.4.85

Patch Changes

0.4.84

Patch Changes

0.4.83

Patch Changes

0.4.82

Patch Changes

0.4.81

Patch Changes

0.4.80

Patch Changes

0.4.79

Patch Changes

0.4.78

Patch Changes

0.4.77

Patch Changes

0.4.76

Patch Changes

0.4.75

Patch Changes

0.4.74

Patch Changes

0.4.73

Patch Changes

0.4.72

Patch Changes

0.4.71

Patch Changes

0.4.70

Patch Changes

0.4.69

Patch Changes

0.4.68

Patch Changes

0.4.67

Patch Changes

0.4.66

Patch Changes

0.4.65

Patch Changes

0.4.64

Patch Changes

0.4.63

Patch Changes

0.4.62

Patch Changes

0.4.61

Patch Changes

0.4.60

Patch Changes

0.4.59

Patch Changes

0.4.58

Patch Changes

0.4.57

Patch Changes

0.4.56

Patch Changes

0.4.55

Patch Changes

0.4.54

Patch Changes

0.4.53

Patch Changes

0.4.52

Patch Changes

0.4.51

Patch Changes

  • #3549 77ee9df Thanks @brandonhines-mialabs! - Fix @posthog/next/pages default export condition to resolve to the client barrel (pages.client.js) instead of the server barrel (pages.js), matching the behavior of the root "." export. This prevents bundlers that don't match a more specific condition from pulling in server-only and posthog-node unnecessarily. (2026-05-14)

0.4.50

Patch Changes

0.4.49

Patch Changes

0.4.48

Patch Changes

  • #3599 ad60818 Thanks @turnipdabeets! - Expose UUID and cookie helpers from @posthog/core and posthog-node for users managing distinct_id outside the browser SDK (e.g. Lambda functions handing out cross-domain redirects). The helpers were already implemented in @posthog/next — this change lifts them to core so all SDKs can re-use them. @posthog/next now re-exports the same surface from @posthog/core to keep existing consumers working without churn. Closes #2143. (2026-05-12)
  • Updated dependencies [ad60818]:

0.4.47

Patch Changes

0.4.46

Patch Changes

0.4.45

Patch Changes

0.4.44

Patch Changes

0.4.43

Patch Changes

  • #3543 ece3097 Thanks @dustinbyrne! - Publish @posthog/next from the release workflow so npm catches up with the versions already recorded in the changelog. (2026-05-07)

0.4.42

Patch Changes

  • #3533 eb546b4 Thanks @brandonhines-mialabs! - Fix @posthog/next/pages packaging so the documented Pages Router setup builds without a server-only import error.

    The ./pages subpath previously had no per-runtime exports conditions, so any module importing from @posthog/next/pages (e.g. pages/_app.tsx) transitively pulled in 'server-only' and posthog-node. Next.js rejects 'server-only' from client modules before tree-shaking can drop the unused re-exports, breaking next build. The barrel is now split per runtime:

    • browser → ./dist/pages.client.js — PostHogProvider, PostHogPageView
    • edge-light / edge / worker → ./dist/pages.edge.js — postHogMiddleware, PostHogPageView, DEFAULT_INGEST_PATH
    • react-server / default → ./dist/pages.js — full surface including getServerSidePostHog and getPostHog

    Existing imports (from '@posthog/next/pages') keep working unchanged; the resolver picks the right barrel per runtime. (2026-05-06)

0.4.41

Patch Changes

0.4.40

Patch Changes

0.4.39

Patch Changes

0.4.38

Patch Changes

0.4.37

Patch Changes

0.4.36

Patch Changes

0.4.35

Patch Changes

0.4.34

Patch Changes

0.4.33

Patch Changes

0.4.32

Patch Changes

0.4.31

Patch Changes

0.4.30

Patch Changes

0.4.29

Patch Changes

0.4.28

Patch Changes

0.4.27

Patch Changes

0.4.26

Patch Changes

0.4.25

Patch Changes

0.4.24

Patch Changes

0.4.23

Patch Changes

0.4.22

Patch Changes

0.4.21

Patch Changes

0.4.20

Patch Changes

0.4.19

Patch Changes

0.4.18

Patch Changes

0.4.17

Patch Changes

0.4.16

Patch Changes

0.4.15

Patch Changes

0.4.14

Patch Changes

  • #3376 e8548a5 Thanks @dustinbyrne! - fix: pass bootstrap flags via React context so feature flag hooks return correct values during SSR (2026-04-15)

0.4.13

Patch Changes

0.4.12

Patch Changes

0.4.11

Patch Changes

0.4.10

Patch Changes

0.4.9

Patch Changes

0.4.8

Patch Changes

0.4.7

Patch Changes

0.4.6

Patch Changes

0.4.5

Patch Changes

0.4.4

Patch Changes

0.4.3

Patch Changes

0.4.2

Patch Changes

0.4.1

Patch Changes

0.4.0

Minor Changes

Patch Changes

0.3.1

Patch Changes

0.3.0

Minor Changes

  • #3301 bd4b0ac Thanks @dustinbyrne! - Read PostHog tracing headers (X-POSTHOG-SESSION-ID, X-POSTHOG-DISTINCT-ID, X-POSTHOG-WINDOW-ID) in getPostHog() and getServerSidePostHog() (2026-04-02)

Patch Changes

0.2.19

Patch Changes

0.2.18

Patch Changes

0.2.17

Patch Changes

0.2.16

Patch Changes

0.2.15

Patch Changes

0.2.14

Patch Changes

0.2.13

Patch Changes

0.2.12

Patch Changes

0.2.11

Patch Changes

0.2.10

Patch Changes

0.2.9

Patch Changes

0.2.8

Patch Changes

0.2.7

Patch Changes

0.2.6

Patch Changes

0.2.5

Patch Changes

0.2.4

Patch Changes

0.2.3

Patch Changes

0.2.2

Patch Changes

0.2.1

Patch Changes

0.2.0

Minor Changes

  • #3215 429b389 Thanks @dustinbyrne! - feat: rename optOutByDefault to seedAnonymousCookie

    Renamed to better express what the option does: to control whether the middleware seeds a cookie containing an anonymous identifier on first page load.

    Migration: replace optOutByDefault: true with seedAnonymousCookie: false. (2026-03-10)

0.1.1

Patch Changes

0.1.0

Minor Changes

  • #3122 706adb8 Thanks @dustinbyrne! - Initial release of @posthog/next, a PostHog integration with Next.js (2026-03-06)

Patch Changes