@posthog/next 0.4.47 → 0.4.49
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.
- package/dist/shared/constants.d.ts +0 -2
- package/dist/shared/constants.d.ts.map +1 -1
- package/dist/shared/constants.js +0 -2
- package/dist/shared/constants.js.map +1 -1
- package/dist/shared/cookie.d.ts +2 -68
- package/dist/shared/cookie.d.ts.map +1 -1
- package/dist/shared/cookie.js +5 -125
- package/dist/shared/cookie.js.map +1 -1
- package/package.json +4 -4
- package/src/shared/constants.ts +0 -2
- package/src/shared/cookie.ts +15 -162
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
export declare const COOKIE_PREFIX = "ph_";
|
|
2
|
-
export declare const COOKIE_SUFFIX = "_posthog";
|
|
3
1
|
export declare const DEFAULT_API_HOST = "https://us.i.posthog.com";
|
|
4
2
|
export declare const COOKIE_MAX_AGE_SECONDS: number;
|
|
5
3
|
export declare const DEFAULT_INGEST_PATH = "/ingest";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/shared/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/shared/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,6BAA6B,CAAA;AAC1D,eAAO,MAAM,sBAAsB,QAAqB,CAAA;AACxD,eAAO,MAAM,mBAAmB,YAAY,CAAA"}
|
package/dist/shared/constants.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/shared/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/shared/constants.ts"],"names":[],"mappings":"AAAA,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"}
|
package/dist/shared/cookie.d.ts
CHANGED
|
@@ -1,69 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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;
|
|
1
|
+
export { cookieStateToProperties, cookieStoreFromHeader, getConsentCookieName, getPostHogCookieName, isOptedOut, parsePostHogCookie, readPostHogCookie, serializePostHogCookie, } from '@posthog/core';
|
|
2
|
+
export type { ConsentConfig, ConsentCookieConfig, CookieStore, PostHogCookieState } from '@posthog/core';
|
|
69
3
|
//# sourceMappingURL=cookie.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookie.d.ts","sourceRoot":"","sources":["../../src/shared/cookie.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cookie.d.ts","sourceRoot":"","sources":["../../src/shared/cookie.ts"],"names":[],"mappings":"AAIA,OAAO,EACH,uBAAuB,EACvB,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,EACpB,UAAU,EACV,kBAAkB,EAClB,iBAAiB,EACjB,sBAAsB,GACzB,MAAM,eAAe,CAAA;AACtB,YAAY,EAAE,aAAa,EAAE,mBAAmB,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA"}
|
package/dist/shared/cookie.js
CHANGED
|
@@ -1,126 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
}
|
|
1
|
+
// Cookie helpers were lifted to `@posthog/core` so all SDKs (posthog-node,
|
|
2
|
+
// posthog-js-lite, etc.) can share them. This module re-exports the public
|
|
3
|
+
// surface for any internal `@posthog/next` imports — keep using these from
|
|
4
|
+
// `./shared/cookie` within next/, or import directly from `@posthog/core`.
|
|
5
|
+
export { cookieStateToProperties, cookieStoreFromHeader, getConsentCookieName, getPostHogCookieName, isOptedOut, parsePostHogCookie, readPostHogCookie, serializePostHogCookie, } from '@posthog/core';
|
|
126
6
|
//# sourceMappingURL=cookie.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookie.js","sourceRoot":"","sources":["../../src/shared/cookie.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"cookie.js","sourceRoot":"","sources":["../../src/shared/cookie.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,2EAA2E;AAC3E,6EAA2E;AAC3E,2EAA2E;AAC3E,OAAO,EACH,uBAAuB,EACvB,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,EACpB,UAAU,EACV,kBAAkB,EAClB,iBAAiB,EACjB,sBAAsB,GACzB,MAAM,eAAe,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@posthog/next",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.49",
|
|
4
4
|
"description": "PostHog integration for Next.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -50,10 +50,10 @@
|
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"server-only": "^0.0.1",
|
|
53
|
-
"@posthog/core": "1.
|
|
53
|
+
"@posthog/core": "1.29.1",
|
|
54
54
|
"@posthog/react": "1.9.0",
|
|
55
|
-
"posthog-node": "5.
|
|
56
|
-
"posthog-js": "1.373.
|
|
55
|
+
"posthog-node": "5.34.1",
|
|
56
|
+
"posthog-js": "1.373.4"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@testing-library/jest-dom": "^6.6.3",
|
package/src/shared/constants.ts
CHANGED
package/src/shared/cookie.ts
CHANGED
|
@@ -1,162 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export
|
|
16
|
-
const cookies: Record<string, string> = {}
|
|
17
|
-
if (cookieHeader) {
|
|
18
|
-
for (const pair of cookieHeader.split(';')) {
|
|
19
|
-
const [key, ...valueParts] = pair.trim().split('=')
|
|
20
|
-
if (key) {
|
|
21
|
-
cookies[key.trim()] = decodeURIComponent(valueParts.join('=').trim())
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return { get: (name: string) => (name in cookies ? { value: cookies[name] } : undefined) }
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface PostHogCookieState {
|
|
29
|
-
distinctId: string
|
|
30
|
-
isIdentified: boolean
|
|
31
|
-
sessionId?: string
|
|
32
|
-
deviceId?: string
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Returns the PostHog cookie name for the given API key.
|
|
37
|
-
*
|
|
38
|
-
* PostHog-js stores state in a cookie named `ph_<sanitized_token>_posthog`.
|
|
39
|
-
* The token is sanitized by replacing `+` with `PL`, `/` with `SL`, `=` with `EQ`.
|
|
40
|
-
*
|
|
41
|
-
* @param apiKey - The PostHog project API key
|
|
42
|
-
* @returns The cookie name string
|
|
43
|
-
*/
|
|
44
|
-
export function getPostHogCookieName(apiKey: string): string {
|
|
45
|
-
const sanitized = apiKey.replace(/\+/g, 'PL').replace(/\//g, 'SL').replace(/=/g, 'EQ')
|
|
46
|
-
return `${COOKIE_PREFIX}${sanitized}${COOKIE_SUFFIX}`
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Serializes an anonymous ID into the JSON format posthog-js expects.
|
|
51
|
-
*
|
|
52
|
-
* When `distinct_id === $device_id`, posthog-js treats the user as anonymous.
|
|
53
|
-
*
|
|
54
|
-
* @param anonymousId - The anonymous distinct ID to serialize
|
|
55
|
-
* @returns JSON string suitable for the PostHog cookie value
|
|
56
|
-
*/
|
|
57
|
-
export function serializePostHogCookie(anonymousId: string): string {
|
|
58
|
-
const now = Date.now()
|
|
59
|
-
const sessionId = uuidv7()
|
|
60
|
-
return JSON.stringify({
|
|
61
|
-
distinct_id: anonymousId,
|
|
62
|
-
$device_id: anonymousId,
|
|
63
|
-
$user_state: 'anonymous',
|
|
64
|
-
$sesid: [now, sessionId, now],
|
|
65
|
-
})
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Reads and parses the PostHog cookie from a cookie store.
|
|
70
|
-
*
|
|
71
|
-
* Compatible with Next.js `cookies()`, `request.cookies`, and any object
|
|
72
|
-
* with a `get(name)` method that returns `{ value: string } | undefined`.
|
|
73
|
-
*/
|
|
74
|
-
export function readPostHogCookie(cookies: CookieStore, apiKey: string): PostHogCookieState | null {
|
|
75
|
-
const cookieName = getPostHogCookieName(apiKey)
|
|
76
|
-
const cookie = cookies.get(cookieName)
|
|
77
|
-
return cookie ? parsePostHogCookie(cookie.value) : null
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Converts cookie state into PostHog properties (e.g. `$session_id`, `$device_id`).
|
|
82
|
-
*/
|
|
83
|
-
export function cookieStateToProperties(state: PostHogCookieState | null): Record<string, string> | undefined {
|
|
84
|
-
if (!state) {
|
|
85
|
-
return undefined
|
|
86
|
-
}
|
|
87
|
-
const props: Record<string, string> = {}
|
|
88
|
-
if (state.sessionId) {
|
|
89
|
-
props.$session_id = state.sessionId
|
|
90
|
-
}
|
|
91
|
-
if (state.deviceId) {
|
|
92
|
-
props.$device_id = state.deviceId
|
|
93
|
-
}
|
|
94
|
-
return Object.keys(props).length > 0 ? props : undefined
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Parses a PostHog cookie value and extracts identity information.
|
|
99
|
-
*
|
|
100
|
-
* The cookie value is a JSON object containing `distinct_id` and `$user_state`.
|
|
101
|
-
* A user is considered identified if `$user_state` is `'identified'`.
|
|
102
|
-
*
|
|
103
|
-
* @param cookieValue - The raw cookie string value
|
|
104
|
-
* @returns Parsed identity state, or null if the cookie is missing/invalid
|
|
105
|
-
*/
|
|
106
|
-
export function parsePostHogCookie(cookieValue: string): PostHogCookieState | null {
|
|
107
|
-
if (!cookieValue) {
|
|
108
|
-
return null
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
try {
|
|
112
|
-
const parsed = JSON.parse(cookieValue)
|
|
113
|
-
if (!parsed || typeof parsed !== 'object' || !parsed.distinct_id) {
|
|
114
|
-
return null
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// $sesid is stored as [lastActivityTimestamp, sessionId, sessionStartTimestamp]
|
|
118
|
-
const sesid = isArray(parsed.$sesid) ? parsed.$sesid[1] : undefined
|
|
119
|
-
|
|
120
|
-
return {
|
|
121
|
-
distinctId: String(parsed.distinct_id),
|
|
122
|
-
isIdentified: parsed.$user_state === 'identified',
|
|
123
|
-
sessionId: typeof sesid === 'string' ? sesid : undefined,
|
|
124
|
-
deviceId: typeof parsed.$device_id === 'string' ? parsed.$device_id : undefined,
|
|
125
|
-
}
|
|
126
|
-
} catch {
|
|
127
|
-
return null
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export interface ConsentCookieConfig {
|
|
132
|
-
consent_persistence_name?: string | null
|
|
133
|
-
opt_out_capturing_cookie_prefix?: string | null
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const CONSENT_PREFIX = '__ph_opt_in_out_'
|
|
137
|
-
|
|
138
|
-
export function getConsentCookieName(apiKey: string, config?: ConsentCookieConfig): string {
|
|
139
|
-
if (config?.consent_persistence_name) {
|
|
140
|
-
return config.consent_persistence_name
|
|
141
|
-
}
|
|
142
|
-
if (config?.opt_out_capturing_cookie_prefix) {
|
|
143
|
-
return config.opt_out_capturing_cookie_prefix + apiKey
|
|
144
|
-
}
|
|
145
|
-
return CONSENT_PREFIX + apiKey
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export interface ConsentConfig extends ConsentCookieConfig {
|
|
149
|
-
opt_out_capturing_by_default?: boolean
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export function isOptedOut(cookies: CookieStore, apiKey: string, config?: ConsentConfig): boolean {
|
|
153
|
-
const cookieName = getConsentCookieName(apiKey, config)
|
|
154
|
-
const cookie = cookies.get(cookieName)
|
|
155
|
-
|
|
156
|
-
if (cookie) {
|
|
157
|
-
return isNoLike(cookie.value)
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// No consent cookie means pending — defer to config
|
|
161
|
-
return config?.opt_out_capturing_by_default ?? false
|
|
162
|
-
}
|
|
1
|
+
// Cookie helpers were lifted to `@posthog/core` so all SDKs (posthog-node,
|
|
2
|
+
// posthog-js-lite, etc.) can share them. This module re-exports the public
|
|
3
|
+
// surface for any internal `@posthog/next` imports — keep using these from
|
|
4
|
+
// `./shared/cookie` within next/, or import directly from `@posthog/core`.
|
|
5
|
+
export {
|
|
6
|
+
cookieStateToProperties,
|
|
7
|
+
cookieStoreFromHeader,
|
|
8
|
+
getConsentCookieName,
|
|
9
|
+
getPostHogCookieName,
|
|
10
|
+
isOptedOut,
|
|
11
|
+
parsePostHogCookie,
|
|
12
|
+
readPostHogCookie,
|
|
13
|
+
serializePostHogCookie,
|
|
14
|
+
} from '@posthog/core'
|
|
15
|
+
export type { ConsentConfig, ConsentCookieConfig, CookieStore, PostHogCookieState } from '@posthog/core'
|