@posthog/next 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/LICENSE +299 -0
  2. package/README.md +122 -0
  3. package/dist/app/PostHogProvider.d.ts +62 -0
  4. package/dist/app/PostHogProvider.d.ts.map +1 -0
  5. package/dist/app/PostHogProvider.js +67 -0
  6. package/dist/app/PostHogProvider.js.map +1 -0
  7. package/dist/client/ClientPostHogProvider.d.ts +28 -0
  8. package/dist/client/ClientPostHogProvider.d.ts.map +1 -0
  9. package/dist/client/ClientPostHogProvider.js +34 -0
  10. package/dist/client/ClientPostHogProvider.js.map +1 -0
  11. package/dist/client/PostHogPageView.d.ts +30 -0
  12. package/dist/client/PostHogPageView.d.ts.map +1 -0
  13. package/dist/client/PostHogPageView.js +54 -0
  14. package/dist/client/PostHogPageView.js.map +1 -0
  15. package/dist/client/hooks.d.ts +2 -0
  16. package/dist/client/hooks.d.ts.map +1 -0
  17. package/dist/client/hooks.js +3 -0
  18. package/dist/client/hooks.js.map +1 -0
  19. package/dist/index.client.d.ts +6 -0
  20. package/dist/index.client.d.ts.map +1 -0
  21. package/dist/index.client.js +6 -0
  22. package/dist/index.client.js.map +1 -0
  23. package/dist/index.d.ts +9 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.edge.d.ts +7 -0
  26. package/dist/index.edge.d.ts.map +1 -0
  27. package/dist/index.edge.js +7 -0
  28. package/dist/index.edge.js.map +1 -0
  29. package/dist/index.js +7 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/index.react-server.d.ts +5 -0
  32. package/dist/index.react-server.d.ts.map +1 -0
  33. package/dist/index.react-server.js +6 -0
  34. package/dist/index.react-server.js.map +1 -0
  35. package/dist/middleware/postHogMiddleware.d.ts +95 -0
  36. package/dist/middleware/postHogMiddleware.d.ts.map +1 -0
  37. package/dist/middleware/postHogMiddleware.js +88 -0
  38. package/dist/middleware/postHogMiddleware.js.map +1 -0
  39. package/dist/pages/PostHogPageView.d.ts +25 -0
  40. package/dist/pages/PostHogPageView.d.ts.map +1 -0
  41. package/dist/pages/PostHogPageView.js +38 -0
  42. package/dist/pages/PostHogPageView.js.map +1 -0
  43. package/dist/pages/PostHogProvider.d.ts +16 -0
  44. package/dist/pages/PostHogProvider.d.ts.map +1 -0
  45. package/dist/pages/PostHogProvider.js +38 -0
  46. package/dist/pages/PostHogProvider.js.map +1 -0
  47. package/dist/pages/getServerSidePostHog.d.ts +27 -0
  48. package/dist/pages/getServerSidePostHog.d.ts.map +1 -0
  49. package/dist/pages/getServerSidePostHog.js +40 -0
  50. package/dist/pages/getServerSidePostHog.js.map +1 -0
  51. package/dist/pages.d.ts +9 -0
  52. package/dist/pages.d.ts.map +1 -0
  53. package/dist/pages.js +7 -0
  54. package/dist/pages.js.map +1 -0
  55. package/dist/server/getPostHog.d.ts +29 -0
  56. package/dist/server/getPostHog.d.ts.map +1 -0
  57. package/dist/server/getPostHog.js +61 -0
  58. package/dist/server/getPostHog.js.map +1 -0
  59. package/dist/server/nodeClientCache.d.ts +14 -0
  60. package/dist/server/nodeClientCache.d.ts.map +1 -0
  61. package/dist/server/nodeClientCache.js +33 -0
  62. package/dist/server/nodeClientCache.js.map +1 -0
  63. package/dist/shared/config.d.ts +36 -0
  64. package/dist/shared/config.d.ts.map +1 -0
  65. package/dist/shared/config.js +35 -0
  66. package/dist/shared/config.js.map +1 -0
  67. package/dist/shared/constants.d.ts +6 -0
  68. package/dist/shared/constants.d.ts.map +1 -0
  69. package/dist/shared/constants.js +6 -0
  70. package/dist/shared/constants.js.map +1 -0
  71. package/dist/shared/cookie.d.ts +69 -0
  72. package/dist/shared/cookie.d.ts.map +1 -0
  73. package/dist/shared/cookie.js +126 -0
  74. package/dist/shared/cookie.js.map +1 -0
  75. package/dist/shared/identity.d.ts +6 -0
  76. package/dist/shared/identity.d.ts.map +1 -0
  77. package/dist/shared/identity.js +9 -0
  78. package/dist/shared/identity.js.map +1 -0
  79. package/package.json +89 -0
  80. package/src/app/PostHogProvider.tsx +141 -0
  81. package/src/client/ClientPostHogProvider.tsx +51 -0
  82. package/src/client/PostHogPageView.tsx +63 -0
  83. package/src/client/hooks.ts +8 -0
  84. package/src/index.client.ts +9 -0
  85. package/src/index.edge.ts +10 -0
  86. package/src/index.react-server.ts +7 -0
  87. package/src/index.ts +8 -0
  88. package/src/middleware/postHogMiddleware.ts +170 -0
  89. package/src/pages/PostHogPageView.tsx +41 -0
  90. package/src/pages/PostHogProvider.tsx +61 -0
  91. package/src/pages/getServerSidePostHog.ts +49 -0
  92. package/src/pages.ts +8 -0
  93. package/src/server/getPostHog.ts +66 -0
  94. package/src/server/nodeClientCache.ts +37 -0
  95. package/src/shared/config.ts +52 -0
  96. package/src/shared/constants.ts +5 -0
  97. package/src/shared/cookie.ts +162 -0
  98. package/src/shared/identity.ts +9 -0
@@ -0,0 +1,29 @@
1
+ import 'server-only';
2
+ import type { PostHogOptions, IPostHog } from 'posthog-node';
3
+ /**
4
+ * Returns a PostHog server client scoped to the current request.
5
+ *
6
+ * Reads the user's identity from the PostHog cookie and returns a
7
+ * request-scoped client. Methods like `getAllFlags()`, `getFeatureFlagResult()`,
8
+ * and `capture()` automatically use the current user's identity.
9
+ *
10
+ * Calls `cookies()` internally, which opts the route into dynamic rendering.
11
+ *
12
+ * @param apiKey - PostHog project API key. If omitted, reads from `NEXT_PUBLIC_POSTHOG_KEY`.
13
+ * @param options - Optional `posthog-node` configuration (e.g., `{ host: '...' }`).
14
+ * @returns A `posthog-node` client scoped to the current user.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * import { getPostHog } from '@posthog/next'
19
+ *
20
+ * export default async function Page() {
21
+ * const posthog = await getPostHog()
22
+ * const flags = await posthog.getAllFlags()
23
+ * posthog.capture({ event: 'page_viewed' })
24
+ * return <div>...</div>
25
+ * }
26
+ * ```
27
+ */
28
+ export declare function getPostHog(apiKey?: string, options?: Partial<PostHogOptions>): Promise<IPostHog>;
29
+ //# sourceMappingURL=getPostHog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getPostHog.d.ts","sourceRoot":"","sources":["../../src/server/getPostHog.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAA;AAGpB,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAM5D;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAsB,UAAU,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CA+BtG"}
@@ -0,0 +1,61 @@
1
+ import 'server-only';
2
+ import { isFunction } from '@posthog/core';
3
+ import { cookies } from 'next/headers';
4
+ import { getOrCreateNodeClient } from './nodeClientCache';
5
+ import { readPostHogCookie, cookieStateToProperties, isOptedOut } from '../shared/cookie';
6
+ import { resolveApiKey } from '../shared/config';
7
+ /**
8
+ * Returns a PostHog server client scoped to the current request.
9
+ *
10
+ * Reads the user's identity from the PostHog cookie and returns a
11
+ * request-scoped client. Methods like `getAllFlags()`, `getFeatureFlagResult()`,
12
+ * and `capture()` automatically use the current user's identity.
13
+ *
14
+ * Calls `cookies()` internally, which opts the route into dynamic rendering.
15
+ *
16
+ * @param apiKey - PostHog project API key. If omitted, reads from `NEXT_PUBLIC_POSTHOG_KEY`.
17
+ * @param options - Optional `posthog-node` configuration (e.g., `{ host: '...' }`).
18
+ * @returns A `posthog-node` client scoped to the current user.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * import { getPostHog } from '@posthog/next'
23
+ *
24
+ * export default async function Page() {
25
+ * const posthog = await getPostHog()
26
+ * const flags = await posthog.getAllFlags()
27
+ * posthog.capture({ event: 'page_viewed' })
28
+ * return <div>...</div>
29
+ * }
30
+ * ```
31
+ */
32
+ export async function getPostHog(apiKey, options) {
33
+ const resolvedApiKey = resolveApiKey(apiKey);
34
+ const host = options?.host ?? process.env.NEXT_PUBLIC_POSTHOG_HOST;
35
+ const resolvedOptions = host ? { ...options, host } : options;
36
+ const client = await getOrCreateNodeClient(resolvedApiKey, resolvedOptions);
37
+ const cookieStore = await cookies();
38
+ if (isOptedOut(cookieStore, resolvedApiKey)) {
39
+ return client;
40
+ }
41
+ const state = readPostHogCookie(cookieStore, resolvedApiKey);
42
+ const properties = cookieStateToProperties(state);
43
+ const contextData = { distinctId: state?.distinctId, sessionId: state?.sessionId, properties };
44
+ // Wrap the shared client in a Proxy that applies request-scoped context
45
+ // to every method call. We can't use enterContext() here because
46
+ // AsyncLocalStorage.enterWith() doesn't propagate back to the caller
47
+ // across the await boundary of this async function.
48
+ return new Proxy(client, {
49
+ get(target, prop, receiver) {
50
+ if (prop === 'withContext') {
51
+ return Reflect.get(target, prop, receiver);
52
+ }
53
+ const value = Reflect.get(target, prop, receiver);
54
+ if (isFunction(value)) {
55
+ return (...args) => target.withContext(contextData, () => value.apply(target, args));
56
+ }
57
+ return value;
58
+ },
59
+ });
60
+ }
61
+ //# sourceMappingURL=getPostHog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getPostHog.js","sourceRoot":"","sources":["../../src/server/getPostHog.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAA;AAEpB,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAE1C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AACzD,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AACzF,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,MAAe,EAAE,OAAiC,EAAqB;IACpG,MAAM,cAAc,GAAG,aAAa,CAAC,MAAM,CAAC,CAAA;IAC5C,MAA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AAI,CAAC,CAAC,CAAA;YACnG,CAAC;YACD,OAAO,KAAK,CAAA;QAAA,CACf;KACJ,CAAa,CAAA;AAAA,CACjB"}
@@ -0,0 +1,14 @@
1
+ import { PostHog } from 'posthog-node';
2
+ import type { PostHogOptions } from 'posthog-node';
3
+ /**
4
+ * Returns a cached PostHog node client, creating one if needed.
5
+ *
6
+ * Clients are cached by project key + host. Only the options from the first
7
+ * call for a given key+host pair take effect; subsequent calls with different
8
+ * options (e.g. flushAt, flushInterval) will return the existing client.
9
+ *
10
+ * On first call, awaits auto-detection of @vercel/functions waitUntil
11
+ * and merges it into options. Explicit options.waitUntil takes priority.
12
+ */
13
+ export declare function getOrCreateNodeClient(apiKey: string, options?: Partial<PostHogOptions>): Promise<PostHog>;
14
+ //# sourceMappingURL=nodeClientCache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nodeClientCache.d.ts","sourceRoot":"","sources":["../../src/server/nodeClientCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAYlD;;;;;;;;;GASG;AACH,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAa/G"}
@@ -0,0 +1,33 @@
1
+ import { PostHog } from 'posthog-node';
2
+ const cache = new Map();
3
+ // Auto-detect waitUntil from @vercel/functions at module load.
4
+ // Fails gracefully in environments where it's not available.
5
+ const autoDetectedWaitUntil = import(
6
+ /* webpackIgnore: true */ '@vercel/functions')
7
+ .then((mod) => mod.waitUntil)
8
+ .catch(() => undefined);
9
+ /**
10
+ * Returns a cached PostHog node client, creating one if needed.
11
+ *
12
+ * Clients are cached by project key + host. Only the options from the first
13
+ * call for a given key+host pair take effect; subsequent calls with different
14
+ * options (e.g. flushAt, flushInterval) will return the existing client.
15
+ *
16
+ * On first call, awaits auto-detection of @vercel/functions waitUntil
17
+ * and merges it into options. Explicit options.waitUntil takes priority.
18
+ */
19
+ export async function getOrCreateNodeClient(apiKey, options) {
20
+ const key = `${apiKey}:${options?.host ?? ''}`;
21
+ let client = cache.get(key);
22
+ if (!client) {
23
+ const waitUntil = options?.waitUntil ?? (await autoDetectedWaitUntil);
24
+ const mergedOptions = {
25
+ ...(waitUntil ? { waitUntil } : {}),
26
+ ...options,
27
+ };
28
+ client = new PostHog(apiKey, mergedOptions);
29
+ cache.set(key, client);
30
+ }
31
+ return client;
32
+ }
33
+ //# sourceMappingURL=nodeClientCache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nodeClientCache.js","sourceRoot":"","sources":["../../src/server/nodeClientCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAGtC,MAAM,KAAK,GAAG,IAAI,GAAG,EAAmB,CAAA;AAExC,+DAA+D;AAC/D,6DAA6D;AAC7D,MAAM,qBAAqB,GAAyD,MAAM;AACtF,yBAAyB,CAAC,mBAAmB,CAChD;KACI,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC;KAC5B,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA;AAE3B;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,MAAc,EAAE,OAAiC,EAAoB;IAC7G,MAAM,GAAG,GAAG,GAAG,MAAM,IAAI,OAAO,EAAE,IAAI,IAAI,EAAE,EAAE,CAAA;IAC9C,IAAI,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAC3B,IAAI,CAAC,MAAM,EAAE,CAAC;QACV,MAAM,SAAS,GAAG,OAAO,EAAE,SAAS,IAAI,CAAC,MAAM,qBAAqB,CAAC,CAAA;QACrE,MAAM,aAAa,GAA4B;YAC3C,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACnC,GAAG,OAAO;SACb,CAAA;QACD,MAAM,GAAG,IAAI,OAAO,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;QAC3C,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;IAC1B,CAAC;IACD,OAAO,MAAM,CAAA;AAAA,CAChB"}
@@ -0,0 +1,36 @@
1
+ import type { PostHogConfig } from 'posthog-js';
2
+ import type { PostHogOptions } from 'posthog-node';
3
+ /**
4
+ * Configuration for the client-side PostHog provider.
5
+ * Extends the standard posthog-js config.
6
+ */
7
+ export type PostHogClientConfig = Partial<PostHogConfig>;
8
+ /**
9
+ * Configuration for the server-side PostHog client.
10
+ * Extends the standard posthog-node options.
11
+ */
12
+ export type PostHogServerConfig = PostHogOptions;
13
+ /**
14
+ * Resolves the PostHog API key from an explicit value or the
15
+ * `NEXT_PUBLIC_POSTHOG_KEY` environment variable.
16
+ *
17
+ * Throws if neither is available.
18
+ */
19
+ export declare function resolveApiKey(apiKey?: string): string;
20
+ /**
21
+ * Next.js-specific defaults for the posthog-js client.
22
+ *
23
+ * These ensure the server can read both identity and consent state from cookies:
24
+ * - `capture_pageview: false` — disables posthog-js automatic pageviews so the
25
+ * `PostHogPageView` component can handle them without duplicates
26
+ * - `persistence: 'localStorage+cookie'` — already the posthog-js default, made explicit
27
+ * - `opt_out_capturing_persistence_type: 'cookie'` — writes consent state to a cookie
28
+ * so middleware/server components can read it (posthog-js default is 'localStorage')
29
+ * - `opt_out_persistence_by_default: true` — when opted out, disables persistence
30
+ * so posthog-js does not write cookies or localStorage; the middleware
31
+ * handles deleting the identity cookie separately
32
+ *
33
+ * Users can override any of these via the `options` prop on PostHogProvider.
34
+ */
35
+ export declare const NEXTJS_CLIENT_DEFAULTS: Partial<PostHogConfig>;
36
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/shared/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAElD;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAAG,OAAO,CAAC,aAAa,CAAC,CAAA;AAExD;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAAG,cAAc,CAAA;AAEhD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAQrD;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,sBAAsB,EAAE,OAAO,CAAC,aAAa,CAKzD,CAAA"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Resolves the PostHog API key from an explicit value or the
3
+ * `NEXT_PUBLIC_POSTHOG_KEY` environment variable.
4
+ *
5
+ * Throws if neither is available.
6
+ */
7
+ export function resolveApiKey(apiKey) {
8
+ const resolved = apiKey || process.env.NEXT_PUBLIC_POSTHOG_KEY;
9
+ if (!resolved) {
10
+ throw new Error('[PostHog Next.js] apiKey is required. Either pass it explicitly or set the NEXT_PUBLIC_POSTHOG_KEY environment variable.');
11
+ }
12
+ return resolved;
13
+ }
14
+ /**
15
+ * Next.js-specific defaults for the posthog-js client.
16
+ *
17
+ * These ensure the server can read both identity and consent state from cookies:
18
+ * - `capture_pageview: false` — disables posthog-js automatic pageviews so the
19
+ * `PostHogPageView` component can handle them without duplicates
20
+ * - `persistence: 'localStorage+cookie'` — already the posthog-js default, made explicit
21
+ * - `opt_out_capturing_persistence_type: 'cookie'` — writes consent state to a cookie
22
+ * so middleware/server components can read it (posthog-js default is 'localStorage')
23
+ * - `opt_out_persistence_by_default: true` — when opted out, disables persistence
24
+ * so posthog-js does not write cookies or localStorage; the middleware
25
+ * handles deleting the identity cookie separately
26
+ *
27
+ * Users can override any of these via the `options` prop on PostHogProvider.
28
+ */
29
+ export const NEXTJS_CLIENT_DEFAULTS = {
30
+ capture_pageview: false,
31
+ persistence: 'localStorage+cookie',
32
+ opt_out_capturing_persistence_type: 'cookie',
33
+ opt_out_persistence_by_default: true,
34
+ };
35
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/shared/config.ts"],"names":[],"mappings":"AAeA;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,MAAe,EAAU;IACnD,MAAM,QAAQ,GAAG,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAA;IAC9D,IAAI,CAAC,QAAQ,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CACX,0HAA0H,CAC7H,CAAA;IACL,CAAC;IACD,OAAO,QAAQ,CAAA;AAAA,CAClB;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAA2B;IAC1D,gBAAgB,EAAE,KAAK;IACvB,WAAW,EAAE,qBAAqB;IAClC,kCAAkC,EAAE,QAAQ;IAC5C,8BAA8B,EAAE,IAAI;CACvC,CAAA"}
@@ -0,0 +1,6 @@
1
+ export declare const COOKIE_PREFIX = "ph_";
2
+ export declare const COOKIE_SUFFIX = "_posthog";
3
+ export declare const DEFAULT_API_HOST = "https://us.i.posthog.com";
4
+ export declare const COOKIE_MAX_AGE_SECONDS: number;
5
+ export declare const DEFAULT_INGEST_PATH = "/ingest";
6
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/shared/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,QAAQ,CAAA;AAClC,eAAO,MAAM,aAAa,aAAa,CAAA;AACvC,eAAO,MAAM,gBAAgB,6BAA6B,CAAA;AAC1D,eAAO,MAAM,sBAAsB,QAAqB,CAAA;AACxD,eAAO,MAAM,mBAAmB,YAAY,CAAA"}
@@ -0,0 +1,6 @@
1
+ export const COOKIE_PREFIX = 'ph_';
2
+ export const COOKIE_SUFFIX = '_posthog';
3
+ export const DEFAULT_API_HOST = 'https://us.i.posthog.com';
4
+ export const COOKIE_MAX_AGE_SECONDS = 365 * 24 * 60 * 60;
5
+ export const DEFAULT_INGEST_PATH = '/ingest';
6
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/shared/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,CAAA;AAClC,MAAM,CAAC,MAAM,aAAa,GAAG,UAAU,CAAA;AACvC,MAAM,CAAC,MAAM,gBAAgB,GAAG,0BAA0B,CAAA;AAC1D,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAA;AACxD,MAAM,CAAC,MAAM,mBAAmB,GAAG,SAAS,CAAA"}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Minimal cookie-reading interface compatible with Next.js `cookies()`,
3
+ * `request.cookies`, and plain objects.
4
+ */
5
+ export interface CookieStore {
6
+ get(name: string): {
7
+ value: string;
8
+ } | undefined;
9
+ }
10
+ /**
11
+ * Adapts a raw `Cookie` header string into a {@link CookieStore}.
12
+ */
13
+ export declare function cookieStoreFromHeader(cookieHeader: string): CookieStore;
14
+ export interface PostHogCookieState {
15
+ distinctId: string;
16
+ isIdentified: boolean;
17
+ sessionId?: string;
18
+ deviceId?: string;
19
+ }
20
+ /**
21
+ * Returns the PostHog cookie name for the given API key.
22
+ *
23
+ * PostHog-js stores state in a cookie named `ph_<sanitized_token>_posthog`.
24
+ * The token is sanitized by replacing `+` with `PL`, `/` with `SL`, `=` with `EQ`.
25
+ *
26
+ * @param apiKey - The PostHog project API key
27
+ * @returns The cookie name string
28
+ */
29
+ export declare function getPostHogCookieName(apiKey: string): string;
30
+ /**
31
+ * Serializes an anonymous ID into the JSON format posthog-js expects.
32
+ *
33
+ * When `distinct_id === $device_id`, posthog-js treats the user as anonymous.
34
+ *
35
+ * @param anonymousId - The anonymous distinct ID to serialize
36
+ * @returns JSON string suitable for the PostHog cookie value
37
+ */
38
+ export declare function serializePostHogCookie(anonymousId: string): string;
39
+ /**
40
+ * Reads and parses the PostHog cookie from a cookie store.
41
+ *
42
+ * Compatible with Next.js `cookies()`, `request.cookies`, and any object
43
+ * with a `get(name)` method that returns `{ value: string } | undefined`.
44
+ */
45
+ export declare function readPostHogCookie(cookies: CookieStore, apiKey: string): PostHogCookieState | null;
46
+ /**
47
+ * Converts cookie state into PostHog properties (e.g. `$session_id`, `$device_id`).
48
+ */
49
+ export declare function cookieStateToProperties(state: PostHogCookieState | null): Record<string, string> | undefined;
50
+ /**
51
+ * Parses a PostHog cookie value and extracts identity information.
52
+ *
53
+ * The cookie value is a JSON object containing `distinct_id` and `$user_state`.
54
+ * A user is considered identified if `$user_state` is `'identified'`.
55
+ *
56
+ * @param cookieValue - The raw cookie string value
57
+ * @returns Parsed identity state, or null if the cookie is missing/invalid
58
+ */
59
+ export declare function parsePostHogCookie(cookieValue: string): PostHogCookieState | null;
60
+ export interface ConsentCookieConfig {
61
+ consent_persistence_name?: string | null;
62
+ opt_out_capturing_cookie_prefix?: string | null;
63
+ }
64
+ export declare function getConsentCookieName(apiKey: string, config?: ConsentCookieConfig): string;
65
+ export interface ConsentConfig extends ConsentCookieConfig {
66
+ opt_out_capturing_by_default?: boolean;
67
+ }
68
+ export declare function isOptedOut(cookies: CookieStore, apiKey: string, config?: ConsentConfig): boolean;
69
+ //# sourceMappingURL=cookie.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cookie.d.ts","sourceRoot":"","sources":["../../src/shared/cookie.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,MAAM,WAAW,WAAW;IACxB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,C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uidv7, isNoLike, isArray } from '@posthog/core';
2
+ import { COOKIE_PREFIX, COOKIE_SUFFIX } from './constants';
3
+ /**
4
+ * Adapts a raw `Cookie` header string into a {@link CookieStore}.
5
+ */
6
+ export function cookieStoreFromHeader(cookieHeader) {
7
+ const cookies = {};
8
+ if (cookieHeader) {
9
+ for (const pair of cookieHeader.split(';')) {
10
+ const [key, ...valueParts] = pair.trim().split('=');
11
+ if (key) {
12
+ cookies[key.trim()] = decodeURIComponent(valueParts.join('=').trim());
13
+ }
14
+ }
15
+ }
16
+ return { get: (name) => (name in cookies ? { value: cookies[name] } : undefined) };
17
+ }
18
+ /**
19
+ * Returns the PostHog cookie name for the given API key.
20
+ *
21
+ * PostHog-js stores state in a cookie named `ph_<sanitized_token>_posthog`.
22
+ * The token is sanitized by replacing `+` with `PL`, `/` with `SL`, `=` with `EQ`.
23
+ *
24
+ * @param apiKey - The PostHog project API key
25
+ * @returns The cookie name string
26
+ */
27
+ export function getPostHogCookieName(apiKey) {
28
+ const sanitized = apiKey.replace(/\+/g, 'PL').replace(/\//g, 'SL').replace(/=/g, 'EQ');
29
+ return `${COOKIE_PREFIX}${sanitized}${COOKIE_SUFFIX}`;
30
+ }
31
+ /**
32
+ * Serializes an anonymous ID into the JSON format posthog-js expects.
33
+ *
34
+ * When `distinct_id === $device_id`, posthog-js treats the user as anonymous.
35
+ *
36
+ * @param anonymousId - The anonymous distinct ID to serialize
37
+ * @returns JSON string suitable for the PostHog cookie value
38
+ */
39
+ export function serializePostHogCookie(anonymousId) {
40
+ const now = Date.now();
41
+ const sessionId = uuidv7();
42
+ return JSON.stringify({
43
+ distinct_id: anonymousId,
44
+ $device_id: anonymousId,
45
+ $user_state: 'anonymous',
46
+ $sesid: [now, sessionId, now],
47
+ });
48
+ }
49
+ /**
50
+ * Reads and parses the PostHog cookie from a cookie store.
51
+ *
52
+ * Compatible with Next.js `cookies()`, `request.cookies`, and any object
53
+ * with a `get(name)` method that returns `{ value: string } | undefined`.
54
+ */
55
+ export function readPostHogCookie(cookies, apiKey) {
56
+ const cookieName = getPostHogCookieName(apiKey);
57
+ const cookie = cookies.get(cookieName);
58
+ return cookie ? parsePostHogCookie(cookie.value) : null;
59
+ }
60
+ /**
61
+ * Converts cookie state into PostHog properties (e.g. `$session_id`, `$device_id`).
62
+ */
63
+ export function cookieStateToProperties(state) {
64
+ if (!state) {
65
+ return undefined;
66
+ }
67
+ const props = {};
68
+ if (state.sessionId) {
69
+ props.$session_id = state.sessionId;
70
+ }
71
+ if (state.deviceId) {
72
+ props.$device_id = state.deviceId;
73
+ }
74
+ return Object.keys(props).length > 0 ? props : undefined;
75
+ }
76
+ /**
77
+ * Parses a PostHog cookie value and extracts identity information.
78
+ *
79
+ * The cookie value is a JSON object containing `distinct_id` and `$user_state`.
80
+ * A user is considered identified if `$user_state` is `'identified'`.
81
+ *
82
+ * @param cookieValue - The raw cookie string value
83
+ * @returns Parsed identity state, or null if the cookie is missing/invalid
84
+ */
85
+ export function parsePostHogCookie(cookieValue) {
86
+ if (!cookieValue) {
87
+ return null;
88
+ }
89
+ try {
90
+ const parsed = JSON.parse(cookieValue);
91
+ if (!parsed || typeof parsed !== 'object' || !parsed.distinct_id) {
92
+ return null;
93
+ }
94
+ // $sesid is stored as [lastActivityTimestamp, sessionId, sessionStartTimestamp]
95
+ const sesid = isArray(parsed.$sesid) ? parsed.$sesid[1] : undefined;
96
+ return {
97
+ distinctId: String(parsed.distinct_id),
98
+ isIdentified: parsed.$user_state === 'identified',
99
+ sessionId: typeof sesid === 'string' ? sesid : undefined,
100
+ deviceId: typeof parsed.$device_id === 'string' ? parsed.$device_id : undefined,
101
+ };
102
+ }
103
+ catch {
104
+ return null;
105
+ }
106
+ }
107
+ const CONSENT_PREFIX = '__ph_opt_in_out_';
108
+ export function getConsentCookieName(apiKey, config) {
109
+ if (config?.consent_persistence_name) {
110
+ return config.consent_persistence_name;
111
+ }
112
+ if (config?.opt_out_capturing_cookie_prefix) {
113
+ return config.opt_out_capturing_cookie_prefix + apiKey;
114
+ }
115
+ return CONSENT_PREFIX + apiKey;
116
+ }
117
+ export function isOptedOut(cookies, apiKey, config) {
118
+ const cookieName = getConsentCookieName(apiKey, config);
119
+ const cookie = cookies.get(cookieName);
120
+ if (cookie) {
121
+ return isNoLike(cookie.value);
122
+ }
123
+ // No consent cookie means pending — defer to config
124
+ return config?.opt_out_capturing_by_default ?? false;
125
+ }
126
+ //# sourceMappingURL=cookie.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cookie.js","sourceRoot":"","sources":["../../src/shared/cookie.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACzD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAU1D;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,YAAoB,EAAe;IACrE,MAAM,OAAO,GAA2B,EAAE,CAAA;IAC1C,IAAI,YAAY,EAAE,CAAC;QACf,KAAK,MAAM,IAAI,IAAI,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;YACzC,MAAM,CAAC,GAAG,EAAE,GAAG,UAAU,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YACnD,IAAI,GAAG,EAAE,CAAC;gBACN,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,GAAG,kBAAkB,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,CAAA;YACzE,CAAC;QACL,CAAC;IACL,CAAC;IACD,OAAO,EAAE,GAAG,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC,IAAI,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,CAAA;AAAA,CAC7F;AASD;;;;;;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B,CAAC,MAAc,EAAE,MAA4B,EAAU;IACvF,IAAI,MAAM,EAAE,wBAAwB,EAAE,CAAC;QACnC,OAAO,MAAM,CAAC,wBAAwB,CAAA;IAC1C,CAAC;IACD,IAAI,MAAM,EAAE,+BAA+B,EAAE,CAAC;QAC1C,OAAO,MAAM,CAAC,+BAA+B,GAAG,MAAM,CAAA;IAC1D,CAAC;IACD,OAAO,cAAc,GAAG,MAAM,CAAA;AAAA,CACjC;AAMD,MAAM,UAAU,UAAU,CAAC,OAAoB,EAAE,MAAc,EAAE,MAAsB,EAAW;IAC9F,MAAM,UAAU,GAAG,oBAAoB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACvD,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;IAEtC,IAAI,MAAM,EAAE,CAAC;QACT,OAAO,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IACjC,CAAC;IAED,sDAAoD;IACpD,OAAO,MAAM,EAAE,4BAA4B,IAAI,KAAK,CAAA;AAAA,CACvD"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Generates a random anonymous distinct_id using UUIDv7.
3
+ * Used as a fallback when no PostHog cookie is available.
4
+ */
5
+ export declare function generateAnonymousId(): string;
6
+ //# sourceMappingURL=identity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../src/shared/identity.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,CAE5C"}
@@ -0,0 +1,9 @@
1
+ import { uuidv7 } from '@posthog/core';
2
+ /**
3
+ * Generates a random anonymous distinct_id using UUIDv7.
4
+ * Used as a fallback when no PostHog cookie is available.
5
+ */
6
+ export function generateAnonymousId() {
7
+ return uuidv7();
8
+ }
9
+ //# sourceMappingURL=identity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity.js","sourceRoot":"","sources":["../../src/shared/identity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAEtC;;;GAGG;AACH,MAAM,UAAU,mBAAmB,GAAW;IAC1C,OAAO,MAAM,EAAE,CAAA;AAAA,CAClB"}
package/package.json ADDED
@@ -0,0 +1,89 @@
1
+ {
2
+ "name": "@posthog/next",
3
+ "version": "0.1.0",
4
+ "description": "PostHog integration for Next.js",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/PostHog/posthog-js.git",
8
+ "directory": "packages/next"
9
+ },
10
+ "author": {
11
+ "name": "PostHog",
12
+ "email": "hey@posthog.com",
13
+ "url": "https://posthog.com"
14
+ },
15
+ "type": "module",
16
+ "license": "MIT",
17
+ "keywords": [
18
+ "posthog",
19
+ "nextjs",
20
+ "analytics",
21
+ "feature-flags"
22
+ ],
23
+ "sideEffects": false,
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "edge-light": "./dist/index.edge.js",
28
+ "edge": "./dist/index.edge.js",
29
+ "worker": "./dist/index.edge.js",
30
+ "browser": "./dist/index.client.js",
31
+ "react-server": "./dist/index.js",
32
+ "default": "./dist/index.client.js"
33
+ },
34
+ "./pages": {
35
+ "types": "./dist/pages.d.ts",
36
+ "default": "./dist/pages.js"
37
+ }
38
+ },
39
+ "main": "./dist/index.client.js",
40
+ "types": "./dist/index.d.ts",
41
+ "files": [
42
+ "dist",
43
+ "src",
44
+ "!src/__tests__"
45
+ ],
46
+ "dependencies": {
47
+ "server-only": "^0.0.1",
48
+ "@posthog/core": "1.23.2",
49
+ "posthog-js": "1.359.1",
50
+ "posthog-node": "5.28.0"
51
+ },
52
+ "devDependencies": {
53
+ "@testing-library/jest-dom": "^6.6.3",
54
+ "@testing-library/react": "^16.1.0",
55
+ "@types/jest": "^29.5.14",
56
+ "@types/react": "^19.0.0",
57
+ "@typescript/native-preview": "7.0.0-dev.20260216.1",
58
+ "@vercel/functions": "^3.4.3",
59
+ "jest": "^29.7.0",
60
+ "jest-environment-jsdom": "^29.7.0",
61
+ "next": "^15.0.0",
62
+ "react": "^19.0.0",
63
+ "react-dom": "^19.0.0",
64
+ "ts-jest": "^29.2.5",
65
+ "typescript": "5.8.2",
66
+ "@posthog-tooling/tsconfig-base": "1.1.1"
67
+ },
68
+ "peerDependencies": {
69
+ "@vercel/functions": ">=1.0.0",
70
+ "next": ">=13.0.0",
71
+ "react": ">=18.0.0",
72
+ "react-dom": ">=18.0.0"
73
+ },
74
+ "peerDependenciesMeta": {
75
+ "@vercel/functions": {
76
+ "optional": true
77
+ }
78
+ },
79
+ "scripts": {
80
+ "clean": "rimraf dist",
81
+ "build": "tsgo -p tsconfig.build.json",
82
+ "dev": "tsgo -p tsconfig.build.json --watch",
83
+ "test:unit": "jest",
84
+ "test": "pnpm test:unit",
85
+ "lint": "eslint src",
86
+ "lint:fix": "eslint src --fix",
87
+ "package": "pnpm pack --out $PACKAGE_DEST/%s.tgz"
88
+ }
89
+ }