posthog-node 5.74.0 → 6.0.1
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/MIGRATION.md +556 -0
- package/README.md +3 -1
- package/dist/ai-capture/routing.d.ts +0 -3
- package/dist/ai-capture/routing.d.ts.map +1 -1
- package/dist/ai-capture/routing.js +2 -14
- package/dist/ai-capture/routing.mjs +1 -4
- package/dist/capture-lane/lane.d.ts +109 -0
- package/dist/capture-lane/lane.d.ts.map +1 -0
- package/dist/capture-lane/lane.js +308 -0
- package/dist/capture-lane/lane.mjs +270 -0
- package/dist/capture-lane/limits.d.ts +7 -0
- package/dist/capture-lane/limits.d.ts.map +1 -0
- package/dist/{capture-v1/config.js → capture-lane/limits.js} +13 -11
- package/dist/capture-lane/limits.mjs +4 -0
- package/dist/capture-lane/settings.d.ts +30 -0
- package/dist/capture-lane/settings.d.ts.map +1 -0
- package/dist/capture-lane/settings.js +100 -0
- package/dist/capture-lane/settings.mjs +47 -0
- package/dist/capture-v1/compression.d.ts +18 -0
- package/dist/capture-v1/compression.d.ts.map +1 -0
- package/dist/capture-v1/compression.js +70 -0
- package/dist/capture-v1/compression.mjs +26 -0
- package/dist/capture-v1/errors.d.ts +23 -7
- package/dist/capture-v1/errors.d.ts.map +1 -1
- package/dist/capture-v1/errors.js +37 -8
- package/dist/capture-v1/errors.mjs +29 -6
- package/dist/capture-v1/sender.d.ts +63 -23
- package/dist/capture-v1/sender.d.ts.map +1 -1
- package/dist/capture-v1/sender.js +281 -74
- package/dist/capture-v1/sender.mjs +275 -77
- package/dist/capture-v1/serialize.d.ts +28 -0
- package/dist/capture-v1/serialize.d.ts.map +1 -0
- package/dist/capture-v1/serialize.js +82 -0
- package/dist/capture-v1/serialize.mjs +38 -0
- package/dist/capture-v1/transform.d.ts +10 -25
- package/dist/capture-v1/transform.d.ts.map +1 -1
- package/dist/capture-v1/transform.js +33 -64
- package/dist/capture-v1/transform.mjs +28 -53
- package/dist/capture-v1/types.d.ts +16 -14
- package/dist/capture-v1/types.d.ts.map +1 -1
- package/dist/capture-v1/types.js +27 -1
- package/dist/capture-v1/types.mjs +3 -1
- package/dist/capture-v1/uuid.d.ts +9 -0
- package/dist/capture-v1/uuid.d.ts.map +1 -0
- package/dist/capture-v1/uuid.js +75 -0
- package/dist/capture-v1/uuid.mjs +34 -0
- package/dist/client.d.ts +203 -96
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +456 -228
- package/dist/client.mjs +455 -227
- package/dist/compression.node.d.ts +13 -0
- package/dist/compression.node.d.ts.map +1 -0
- package/dist/{capture-v1/routing.js → compression.node.js} +23 -16
- package/dist/compression.node.mjs +18 -0
- package/dist/entrypoints/index.node.d.ts +2 -0
- package/dist/entrypoints/index.node.d.ts.map +1 -1
- package/dist/entrypoints/index.node.js +11 -4
- package/dist/entrypoints/index.node.mjs +4 -0
- package/dist/event-defaults.d.ts +46 -0
- package/dist/event-defaults.d.ts.map +1 -0
- package/dist/event-defaults.js +141 -0
- package/dist/event-defaults.mjs +79 -0
- package/dist/exports.d.ts +3 -0
- package/dist/exports.d.ts.map +1 -1
- package/dist/exports.js +22 -11
- package/dist/exports.mjs +1 -0
- package/dist/extensions/context/context.d.ts +0 -1
- package/dist/extensions/context/context.d.ts.map +1 -1
- package/dist/extensions/context/context.js +4 -3
- package/dist/extensions/context/context.mjs +4 -3
- package/dist/extensions/context/event-context.d.ts.map +1 -1
- package/dist/extensions/context/event-context.js +3 -0
- package/dist/extensions/context/event-context.mjs +3 -0
- package/dist/extensions/context/types.d.ts +9 -1
- package/dist/extensions/context/types.d.ts.map +1 -1
- package/dist/extensions/error-tracking/index.d.ts +1 -1
- package/dist/extensions/error-tracking/index.d.ts.map +1 -1
- package/dist/extensions/error-tracking/index.js +71 -7
- package/dist/extensions/error-tracking/index.mjs +75 -11
- package/dist/extensions/express.d.ts +8 -0
- package/dist/extensions/express.d.ts.map +1 -1
- package/dist/extensions/express.js +3 -3
- package/dist/extensions/express.mjs +4 -4
- package/dist/extensions/fetch-request.d.ts.map +1 -1
- package/dist/extensions/fetch-request.js +2 -2
- package/dist/extensions/fetch-request.mjs +3 -3
- package/dist/extensions/nestjs.d.ts.map +1 -1
- package/dist/extensions/nestjs.js +7 -4
- package/dist/extensions/nestjs.mjs +8 -5
- package/dist/extensions/tracing-headers.d.ts +7 -0
- package/dist/extensions/tracing-headers.d.ts.map +1 -1
- package/dist/extensions/tracing-headers.js +11 -1
- package/dist/extensions/tracing-headers.mjs +9 -2
- package/dist/flag-events.d.ts +1 -1
- package/dist/flag-events.d.ts.map +1 -1
- package/dist/flag-events.js +2 -2
- package/dist/flag-events.mjs +2 -2
- package/dist/types.d.ts +191 -27
- package/dist/types.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/dist/version.mjs +1 -1
- package/package.json +3 -2
- package/src/ai-capture/routing.ts +0 -6
- package/src/capture-lane/lane.ts +414 -0
- package/src/capture-lane/limits.ts +8 -0
- package/src/capture-lane/settings.ts +119 -0
- package/src/capture-v1/compression.ts +50 -0
- package/src/capture-v1/errors.ts +50 -11
- package/src/capture-v1/sender.ts +405 -111
- package/src/capture-v1/serialize.ts +77 -0
- package/src/capture-v1/transform.ts +59 -92
- package/src/capture-v1/types.ts +19 -15
- package/src/capture-v1/uuid.ts +53 -0
- package/src/client.ts +847 -424
- package/src/compression.node.ts +30 -0
- package/src/entrypoints/index.node.ts +6 -0
- package/src/event-defaults.ts +177 -0
- package/src/exports.ts +3 -0
- package/src/extensions/context/context.ts +4 -4
- package/src/extensions/context/event-context.ts +3 -1
- package/src/extensions/context/types.ts +10 -1
- package/src/extensions/error-tracking/index.ts +51 -7
- package/src/extensions/express.ts +12 -3
- package/src/extensions/fetch-request.ts +7 -3
- package/src/extensions/nestjs.ts +9 -5
- package/src/extensions/tracing-headers.ts +26 -7
- package/src/flag-events.ts +5 -2
- package/src/types.ts +211 -44
- package/src/version.ts +1 -1
- package/dist/ai-capture/batching.d.ts +0 -11
- package/dist/ai-capture/batching.d.ts.map +0 -1
- package/dist/ai-capture/batching.js +0 -77
- package/dist/ai-capture/batching.mjs +0 -36
- package/dist/capture-v1/config.d.ts +0 -11
- package/dist/capture-v1/config.d.ts.map +0 -1
- package/dist/capture-v1/config.mjs +0 -8
- package/dist/capture-v1/routing.d.ts +0 -21
- package/dist/capture-v1/routing.d.ts.map +0 -1
- package/dist/capture-v1/routing.mjs +0 -7
- package/src/ai-capture/batching.ts +0 -47
- package/src/capture-v1/config.ts +0 -18
- package/src/capture-v1/routing.ts +0 -28
package/src/types.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
ErrorTracking,
|
|
2
3
|
PostHogCoreOptions,
|
|
3
4
|
ExceptionRateLimiterConfig,
|
|
4
5
|
FeatureFlagValue,
|
|
@@ -8,6 +9,7 @@ import type {
|
|
|
8
9
|
PostHogLogsConfig,
|
|
9
10
|
PostHogFetchOptions,
|
|
10
11
|
PostHogFetchResponse,
|
|
12
|
+
PostHogEventProperties,
|
|
11
13
|
PostHogFlagsAndPayloadsResponse,
|
|
12
14
|
Properties,
|
|
13
15
|
Span,
|
|
@@ -15,6 +17,10 @@ import type {
|
|
|
15
17
|
TracesConfig,
|
|
16
18
|
} from '@posthog/core'
|
|
17
19
|
import { ContextData, ContextOptions } from './extensions/context/types'
|
|
20
|
+
import type { V1EventOptions } from './capture-v1/types'
|
|
21
|
+
|
|
22
|
+
/** Processing options sent with an event to capture v1. */
|
|
23
|
+
export type EventOptions = V1EventOptions
|
|
18
24
|
|
|
19
25
|
import type { Emails } from './emails/types'
|
|
20
26
|
import type { FeatureFlagEvaluations } from './feature-flag-evaluations'
|
|
@@ -24,17 +30,29 @@ export type IdentifyMessage = {
|
|
|
24
30
|
distinctId: string
|
|
25
31
|
properties?: Record<string | number, any>
|
|
26
32
|
disableGeoip?: boolean
|
|
33
|
+
/**
|
|
34
|
+
* Processing options sent with this event to capture v1.
|
|
35
|
+
*/
|
|
36
|
+
options?: EventOptions
|
|
27
37
|
}
|
|
28
38
|
|
|
29
39
|
export type SetPersonPropertiesMessage = {
|
|
30
40
|
distinctId: string
|
|
31
41
|
properties?: Record<string | number, any>
|
|
32
42
|
propertiesOnce?: Record<string | number, any>
|
|
43
|
+
/**
|
|
44
|
+
* Processing options sent with this event to capture v1.
|
|
45
|
+
*/
|
|
46
|
+
options?: EventOptions
|
|
33
47
|
}
|
|
34
48
|
|
|
35
49
|
export type UnsetPersonPropertiesMessage = {
|
|
36
50
|
distinctId: string
|
|
37
51
|
properties: string | string[]
|
|
52
|
+
/**
|
|
53
|
+
* Processing options sent with this event to capture v1.
|
|
54
|
+
*/
|
|
55
|
+
options?: EventOptions
|
|
38
56
|
}
|
|
39
57
|
|
|
40
58
|
export type SendFeatureFlagsOptions = {
|
|
@@ -45,7 +63,11 @@ export type SendFeatureFlagsOptions = {
|
|
|
45
63
|
}
|
|
46
64
|
|
|
47
65
|
export type EventMessage = Omit<IdentifyMessage, 'distinctId'> & {
|
|
48
|
-
|
|
66
|
+
/**
|
|
67
|
+
* The event's distinct id. When it is missing, empty or only whitespace, the context distinct id
|
|
68
|
+
* is used; without one, the event gets a generated id and `options.process_person_profile: false`.
|
|
69
|
+
*/
|
|
70
|
+
distinctId?: string
|
|
49
71
|
event: string
|
|
50
72
|
groups?: Record<string, string | number> // Mapping of group type to group id
|
|
51
73
|
/**
|
|
@@ -72,12 +94,58 @@ export type EventMessage = Omit<IdentifyMessage, 'distinctId'> & {
|
|
|
72
94
|
_originatedFromCaptureException?: boolean
|
|
73
95
|
}
|
|
74
96
|
|
|
97
|
+
/** Options for `captureException()` and `captureExceptionImmediate()`. */
|
|
98
|
+
export type CaptureExceptionOptions = {
|
|
99
|
+
/** The event's distinct id. Without one, the context distinct id is used, else a personless id. */
|
|
100
|
+
distinctId?: string
|
|
101
|
+
/**
|
|
102
|
+
* Properties to add to the event. Exception properties the SDK or PostHog owns, such as
|
|
103
|
+
* `$exception_list` and `$exception_level`, are ignored: use `level` to set the level.
|
|
104
|
+
*/
|
|
105
|
+
properties?: Record<string | number, any>
|
|
106
|
+
/** Per-event options, as in `capture()`. */
|
|
107
|
+
options?: EventOptions
|
|
108
|
+
/** Overrides the generated event UUID. Must be a valid UUID. */
|
|
109
|
+
uuid?: string
|
|
110
|
+
/** A `FeatureFlagEvaluations` snapshot to attach the same flag context as your other events. */
|
|
111
|
+
flags?: FeatureFlagEvaluations
|
|
112
|
+
/**
|
|
113
|
+
* The exception's severity, sent as `$exception_level`. An unknown value is ignored.
|
|
114
|
+
*
|
|
115
|
+
* @default 'error'
|
|
116
|
+
*/
|
|
117
|
+
level?: ErrorTracking.SeverityLevel
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* An event as `prepareEventMessage()` builds it: the shape of `EventMessage`, with the distinct id
|
|
122
|
+
* resolved and the properties and options filled from every layer, after `beforeSend`.
|
|
123
|
+
*/
|
|
124
|
+
export type PreparedEventMessage = {
|
|
125
|
+
distinctId: string
|
|
126
|
+
event: string
|
|
127
|
+
properties: PostHogEventProperties
|
|
128
|
+
/** The event's options, sent to capture unchanged. */
|
|
129
|
+
options?: EventOptions
|
|
130
|
+
uuid?: string
|
|
131
|
+
timestamp?: Date
|
|
132
|
+
disableGeoip?: boolean
|
|
133
|
+
}
|
|
134
|
+
|
|
75
135
|
export type GroupIdentifyMessage = {
|
|
76
136
|
groupType: string
|
|
77
137
|
groupKey: string // Unique identifier for the group
|
|
78
138
|
properties?: Record<string | number, any>
|
|
79
|
-
|
|
139
|
+
/**
|
|
140
|
+
* The event's distinct id. When it is missing, empty or only whitespace, the context distinct id
|
|
141
|
+
* is used, then `$<groupType>_<groupKey>`.
|
|
142
|
+
*/
|
|
143
|
+
distinctId?: string
|
|
80
144
|
disableGeoip?: boolean
|
|
145
|
+
/**
|
|
146
|
+
* Processing options sent with this event to capture v1.
|
|
147
|
+
*/
|
|
148
|
+
options?: EventOptions
|
|
81
149
|
}
|
|
82
150
|
|
|
83
151
|
export type PropertyGroup = {
|
|
@@ -168,8 +236,34 @@ export type FeatureFlagEvaluationRuntime = 'all' | 'client' | 'server'
|
|
|
168
236
|
|
|
169
237
|
export type BeforeSendFn = (event: EventMessage) => EventMessage | null
|
|
170
238
|
|
|
171
|
-
export type PostHogOptions = Omit<
|
|
239
|
+
export type PostHogOptions = Omit<
|
|
240
|
+
PostHogCoreOptions,
|
|
241
|
+
| 'before_send'
|
|
242
|
+
| 'disable_capture_url_hashes'
|
|
243
|
+
| 'disableGeoip'
|
|
244
|
+
| 'flushInterval'
|
|
245
|
+
| 'maxQueueSize'
|
|
246
|
+
| 'fetchRetryCount'
|
|
247
|
+
| 'fetchRetryDelay'
|
|
248
|
+
| 'disableCompression'
|
|
249
|
+
| 'requestTimeout'
|
|
250
|
+
> & {
|
|
172
251
|
persistence?: 'memory'
|
|
252
|
+
/**
|
|
253
|
+
* Whether to strip URL fragments (`#...`) from automatically captured request URLs.
|
|
254
|
+
*
|
|
255
|
+
* @default false
|
|
256
|
+
*/
|
|
257
|
+
disableCaptureUrlHashes?: boolean
|
|
258
|
+
/**
|
|
259
|
+
* Whether to disable GeoIP lookups for events and feature flag requests. When on, every event
|
|
260
|
+
* gets `$geoip_disable: true` unless the event, its context or `register()` sets
|
|
261
|
+
* `$geoip_disable`. A per-call `disableGeoip` argument sets it for that event, under the event's
|
|
262
|
+
* own `$geoip_disable` property.
|
|
263
|
+
*
|
|
264
|
+
* @default true
|
|
265
|
+
*/
|
|
266
|
+
disableGeoip?: boolean
|
|
173
267
|
/**
|
|
174
268
|
* The interval in milliseconds between periodic flushes
|
|
175
269
|
*
|
|
@@ -177,13 +271,88 @@ export type PostHogOptions = Omit<PostHogCoreOptions, 'before_send' | 'flushInte
|
|
|
177
271
|
*/
|
|
178
272
|
flushInterval?: number
|
|
179
273
|
/**
|
|
180
|
-
* The maximum number of
|
|
274
|
+
* The maximum number of analytics events held in memory waiting to be sent (must be higher than `flushAt`).
|
|
275
|
+
* When the queue is full, the oldest event is dropped and reported through the `'error'` event.
|
|
276
|
+
* `captureAi` events have their own queue, sized by `captureAiMaxQueueSize`, and do not count toward this limit.
|
|
181
277
|
*
|
|
182
278
|
* @default 10000
|
|
183
279
|
*/
|
|
184
280
|
maxQueueSize?: number
|
|
185
281
|
/**
|
|
186
|
-
*
|
|
282
|
+
* Whether the Express, NestJS, Hono, and `instrumentRequest` integrations read the `X-POSTHOG-DISTINCT-ID` and
|
|
283
|
+
* `X-POSTHOG-SESSION-ID` request headers into the request context. A distinct id or session id
|
|
284
|
+
* you pass explicitly always wins over these headers, and they are never used for authentication.
|
|
285
|
+
* Turning it off does not turn off `readPostHogCookie`. To stop all request linking, set
|
|
286
|
+
* `captureTracingHeaders: false` and leave `readPostHogCookie` off (its default).
|
|
287
|
+
*
|
|
288
|
+
* @default true
|
|
289
|
+
*/
|
|
290
|
+
captureTracingHeaders?: boolean
|
|
291
|
+
/**
|
|
292
|
+
* How many times a capture request is retried after its first attempt, on both capture lanes.
|
|
293
|
+
* Waits start at 100 ms and double each retry, with jitter, up to 30 seconds; a `Retry-After`
|
|
294
|
+
* header can raise a wait. Only HTTP 404, 408, 429, 500, 502, 503 and 504 and network errors are retried.
|
|
295
|
+
* When not set, `fetchRetryCount` is used.
|
|
296
|
+
*
|
|
297
|
+
* @default 3
|
|
298
|
+
*/
|
|
299
|
+
captureMaxRetries?: number
|
|
300
|
+
/**
|
|
301
|
+
* How many times HTTP requests are retried. Capture requests use `captureMaxRetries` when it is set.
|
|
302
|
+
*
|
|
303
|
+
* @default 3
|
|
304
|
+
*/
|
|
305
|
+
fetchRetryCount?: number
|
|
306
|
+
/**
|
|
307
|
+
* The delay between HTTP request retries in milliseconds. Capture requests do not use it:
|
|
308
|
+
* see `captureMaxRetries` for their retry waits.
|
|
309
|
+
*
|
|
310
|
+
* @default 3000
|
|
311
|
+
*/
|
|
312
|
+
fetchRetryDelay?: number
|
|
313
|
+
/**
|
|
314
|
+
* How analytics capture requests compress their body. `'deflate'` is zlib-wrapped. `'zstd'` needs
|
|
315
|
+
* Node 22.15 or later and falls back to `'gzip'` elsewhere, including the edge build. When not set,
|
|
316
|
+
* `disableCompression: true` means `'none'`.
|
|
317
|
+
*
|
|
318
|
+
* @default 'gzip'
|
|
319
|
+
*/
|
|
320
|
+
captureCompression?: 'none' | 'gzip' | 'deflate' | 'zstd'
|
|
321
|
+
/**
|
|
322
|
+
* How `captureAi` requests compress their body, with the same values as `captureCompression`.
|
|
323
|
+
* It does not read `captureCompression` or `disableCompression`.
|
|
324
|
+
*
|
|
325
|
+
* @default 'gzip'
|
|
326
|
+
*/
|
|
327
|
+
captureAiCompression?: 'none' | 'gzip' | 'deflate' | 'zstd'
|
|
328
|
+
/**
|
|
329
|
+
* Timeout in milliseconds for any calls. `captureAi` requests use `captureAiRequestTimeoutMs`.
|
|
330
|
+
*
|
|
331
|
+
* @default 10000
|
|
332
|
+
*/
|
|
333
|
+
requestTimeout?: number
|
|
334
|
+
/**
|
|
335
|
+
* The maximum number of `captureAi` events held in memory waiting to be sent. When the queue is
|
|
336
|
+
* full, the oldest AI event is dropped and reported through the `'error'` event.
|
|
337
|
+
*
|
|
338
|
+
* @default 1000
|
|
339
|
+
*/
|
|
340
|
+
captureAiMaxQueueSize?: number
|
|
341
|
+
/**
|
|
342
|
+
* Timeout in milliseconds for each `captureAi` request. Analytics capture requests use `requestTimeout`.
|
|
343
|
+
*
|
|
344
|
+
* @default 30000
|
|
345
|
+
*/
|
|
346
|
+
captureAiRequestTimeoutMs?: number
|
|
347
|
+
/**
|
|
348
|
+
* Whether to disable GZIP compression. Analytics capture requests use `captureCompression` when it
|
|
349
|
+
* is set, and `captureAi` requests use `captureAiCompression`.
|
|
350
|
+
*
|
|
351
|
+
* @default false
|
|
352
|
+
*/
|
|
353
|
+
disableCompression?: boolean
|
|
354
|
+
/**
|
|
355
|
+
* Lets the Express, NestJS, Hono, and `instrumentRequest` integrations read the session ID, and the distinct ID of an identified user, from the
|
|
187
356
|
* posthog-js cookie when a request has neither tracing header.
|
|
188
357
|
*
|
|
189
358
|
* Turn it on only when posthog-js stores opt-out consent in a cookie, or when you do not use opt-out: the server
|
|
@@ -195,7 +364,8 @@ export type PostHogOptions = Omit<PostHogCoreOptions, 'before_send' | 'flushInte
|
|
|
195
364
|
* `optOutCapturingByDefault` when posthog-js uses `opt_out_capturing_by_default`, so a visitor with no consent cookie
|
|
196
365
|
* counts as opted out. A request sent right
|
|
197
366
|
* after `identify()` or `reset()` can still carry the previous identity, because posthog-js saves the cookie with a
|
|
198
|
-
* short delay.
|
|
367
|
+
* short delay. When `captureTracingHeaders` is `false`, the tracing headers are ignored and every request falls
|
|
368
|
+
* back to the cookie. To stop all request linking, also leave this option off.
|
|
199
369
|
*
|
|
200
370
|
* @default false
|
|
201
371
|
*/
|
|
@@ -301,12 +471,15 @@ export type PostHogOptions = Omit<PostHogCoreOptions, 'before_send' | 'flushInte
|
|
|
301
471
|
enableExceptionAutocapture?: boolean
|
|
302
472
|
/**
|
|
303
473
|
* The interval in milliseconds between polls for refreshing feature flag definitions. Defaults to 30 seconds.
|
|
474
|
+
* The minimum is 100 ms, and a lower value is raised to it.
|
|
304
475
|
* Set to null to disable automatic polling. Definitions are still loaded on initialization;
|
|
305
476
|
* call reloadFeatureFlags() to refresh them manually. Until refreshed, local evaluation uses the last loaded definitions.
|
|
306
477
|
*/
|
|
307
478
|
featureFlagsPollingInterval?: number | null
|
|
308
|
-
|
|
309
|
-
|
|
479
|
+
/**
|
|
480
|
+
* Maximum number of distinct ids held in the cache that deduplicates $feature_flag_called calls
|
|
481
|
+
* per user. When the cache is full the least recently used distinct ids are evicted. Defaults to 50000.
|
|
482
|
+
*/
|
|
310
483
|
maxCacheSize?: number
|
|
311
484
|
fetch?: (url: string, options: PostHogFetchOptions) => Promise<PostHogFetchResponse>
|
|
312
485
|
// Whether to enable local evaluation and definition polling. Defaults to true when a secretKey, personalApiKey, or flagDefinitionCacheProvider is provided.
|
|
@@ -344,8 +517,21 @@ export type PostHogOptions = Omit<PostHogCoreOptions, 'before_send' | 'flushInte
|
|
|
344
517
|
* Allows modification or dropping of events before they're sent to PostHog.
|
|
345
518
|
* If an array is provided, the functions are run in order.
|
|
346
519
|
* If a function returns null, the event will be dropped.
|
|
520
|
+
*
|
|
521
|
+
* @remarks
|
|
522
|
+
* The hook gets a copy of the finished event: the event's own values, then the values filled
|
|
523
|
+
* from context, `register()` and `registerOptions()`, then the values the SDK adds (such as
|
|
524
|
+
* `$is_server`, `$geoip_disable`, feature flag properties and `options.process_person_profile`).
|
|
525
|
+
* It has the final say: it can change or remove any of them, and nothing is added after it.
|
|
526
|
+
* Set `$geoip_disable` in `properties` to change GeoIP; the `disableGeoip` and `groups` fields
|
|
527
|
+
* are already applied to the properties it sees.
|
|
528
|
+
*
|
|
529
|
+
* On `$identify`, `$create_alias`, `$merge_dangerously`, `$groupidentify`, `$set` and `$set_once`
|
|
530
|
+
* events it sees `options.process_person_profile` and no `$process_person_profile` property.
|
|
531
|
+
* Those events get their default from the event name the call used, so a hook that renames an
|
|
532
|
+
* event to one of them must set `options.process_person_profile` itself.
|
|
347
533
|
*/
|
|
348
|
-
|
|
534
|
+
beforeSend?: BeforeSendFn | BeforeSendFn[]
|
|
349
535
|
/**
|
|
350
536
|
* Evaluation contexts for feature flags.
|
|
351
537
|
* When set, only feature flags that have at least one matching evaluation tag
|
|
@@ -368,7 +554,7 @@ export type PostHogOptions = Omit<PostHogCoreOptions, 'before_send' | 'flushInte
|
|
|
368
554
|
*
|
|
369
555
|
* @default []
|
|
370
556
|
*/
|
|
371
|
-
|
|
557
|
+
customBlockedUserAgents?: string[]
|
|
372
558
|
/**
|
|
373
559
|
* PREVIEW - MAY CHANGE WITHOUT WARNING - DO NOT USE IN PRODUCTION
|
|
374
560
|
* Enables collection of bot traffic as $bot_pageview events instead of dropping them.
|
|
@@ -386,7 +572,7 @@ export type PostHogOptions = Omit<PostHogCoreOptions, 'before_send' | 'flushInte
|
|
|
386
572
|
* })
|
|
387
573
|
* ```
|
|
388
574
|
*/
|
|
389
|
-
|
|
575
|
+
__previewCaptureBotPageviews?: boolean
|
|
390
576
|
/**
|
|
391
577
|
* When enabled, all feature flag evaluations will use local evaluation only,
|
|
392
578
|
* never falling back to server-side evaluation. This prevents unexpected server
|
|
@@ -444,7 +630,8 @@ export type PostHogOptions = Omit<PostHogCoreOptions, 'before_send' | 'flushInte
|
|
|
444
630
|
* react-native events. Set this to `false` when running the SDK as a
|
|
445
631
|
* client/CLI so the event is attributed to the device OS normally instead of
|
|
446
632
|
* being marked as a server event. When `false`, the `$is_server` property is
|
|
447
|
-
* omitted entirely.
|
|
633
|
+
* omitted entirely. A `$is_server` value set on the event, in context or with
|
|
634
|
+
* `register()` wins over this setting.
|
|
448
635
|
*
|
|
449
636
|
* @default true
|
|
450
637
|
* @example
|
|
@@ -582,32 +769,16 @@ export interface IPostHog {
|
|
|
582
769
|
/**
|
|
583
770
|
* @description Capture an exception as a $exception event.
|
|
584
771
|
* @param error The error to capture.
|
|
585
|
-
* @param
|
|
586
|
-
* @param additionalProperties Optional additional properties to include.
|
|
587
|
-
* @param uuid Optional event UUID.
|
|
588
|
-
* @param flags Optional `FeatureFlagEvaluations` snapshot to attach to the event.
|
|
772
|
+
* @param options Optional distinct id, properties, options, uuid, flags snapshot and level.
|
|
589
773
|
*/
|
|
590
|
-
captureException(
|
|
591
|
-
error: unknown,
|
|
592
|
-
distinctId?: string,
|
|
593
|
-
additionalProperties?: Record<string | number, any>,
|
|
594
|
-
uuid?: EventMessage['uuid'],
|
|
595
|
-
flags?: FeatureFlagEvaluations
|
|
596
|
-
): void
|
|
774
|
+
captureException(error: unknown, options?: CaptureExceptionOptions): void
|
|
597
775
|
|
|
598
776
|
/**
|
|
599
777
|
* @description Capture an exception as a $exception event immediately.
|
|
600
778
|
* @param error The error to capture.
|
|
601
|
-
* @param
|
|
602
|
-
* @param additionalProperties Optional additional properties to include.
|
|
603
|
-
* @param flags Optional `FeatureFlagEvaluations` snapshot to attach to the event.
|
|
779
|
+
* @param options Optional distinct id, properties, options, uuid, flags snapshot and level.
|
|
604
780
|
*/
|
|
605
|
-
captureExceptionImmediate(
|
|
606
|
-
error: unknown,
|
|
607
|
-
distinctId?: string,
|
|
608
|
-
additionalProperties?: Record<string | number, any>,
|
|
609
|
-
flags?: FeatureFlagEvaluations
|
|
610
|
-
): Promise<void>
|
|
781
|
+
captureExceptionImmediate(error: unknown, options?: CaptureExceptionOptions): Promise<void>
|
|
611
782
|
|
|
612
783
|
/**
|
|
613
784
|
* @description Capture an AI event on the dedicated AI capture endpoint.
|
|
@@ -684,7 +855,7 @@ export interface IPostHog {
|
|
|
684
855
|
* @param distinctId the current unique id
|
|
685
856
|
* @param alias the unique ID of the user before
|
|
686
857
|
*/
|
|
687
|
-
alias(data: { distinctId: string; alias: string }): void
|
|
858
|
+
alias(data: { distinctId: string; alias: string; disableGeoip?: boolean; options?: EventOptions }): void
|
|
688
859
|
|
|
689
860
|
/**
|
|
690
861
|
* @description To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call.
|
|
@@ -692,7 +863,12 @@ export interface IPostHog {
|
|
|
692
863
|
* @param distinctId the current unique id
|
|
693
864
|
* @param alias the unique ID of the user before
|
|
694
865
|
*/
|
|
695
|
-
aliasImmediate(data: {
|
|
866
|
+
aliasImmediate(data: {
|
|
867
|
+
distinctId: string
|
|
868
|
+
alias: string
|
|
869
|
+
disableGeoip?: boolean
|
|
870
|
+
options?: EventOptions
|
|
871
|
+
}): Promise<void>
|
|
696
872
|
|
|
697
873
|
/**
|
|
698
874
|
* @description PostHog feature flags (https://posthog.com/docs/features/feature-flags)
|
|
@@ -939,22 +1115,13 @@ export interface IPostHog {
|
|
|
939
1115
|
|
|
940
1116
|
/**
|
|
941
1117
|
* @description Run a function with specific context that will be applied to all events captured within that context.
|
|
942
|
-
* @param data Context data to apply (sessionId, distinctId, properties,
|
|
1118
|
+
* @param data Context data to apply (sessionId, distinctId, properties, options)
|
|
943
1119
|
* @param fn Function to run with the context
|
|
944
1120
|
* @param options Context options (fresh)
|
|
945
1121
|
* @returns The return value of the function
|
|
946
1122
|
*/
|
|
947
1123
|
withContext<T>(data: Partial<ContextData>, fn: () => T, options?: ContextOptions): T
|
|
948
1124
|
|
|
949
|
-
/**
|
|
950
|
-
* @description Set context without a callback wrapper. Must be called in the same
|
|
951
|
-
* async scope that makes PostHog calls. Prefer `withContext()` when you can wrap
|
|
952
|
-
* code in a callback.
|
|
953
|
-
* @param data Context data to apply (distinctId, sessionId, properties)
|
|
954
|
-
* @param options Context options (fresh)
|
|
955
|
-
*/
|
|
956
|
-
enterContext(data: Partial<ContextData>, options?: ContextOptions): void
|
|
957
|
-
|
|
958
1125
|
/**
|
|
959
1126
|
* @description Get the current context data.
|
|
960
1127
|
* @returns The current context data, or undefined if no context is set
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "
|
|
1
|
+
export const version = "6.0.1"
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { PostHogEventProperties } from '@posthog/core';
|
|
2
|
-
export type AiBatchPartition = {
|
|
3
|
-
batches: PostHogEventProperties[][];
|
|
4
|
-
dropped: {
|
|
5
|
-
event: string;
|
|
6
|
-
bytes: number;
|
|
7
|
-
}[];
|
|
8
|
-
};
|
|
9
|
-
export declare function eventByteSize(message: PostHogEventProperties): number;
|
|
10
|
-
export declare function partitionAiBatch(messages: (PostHogEventProperties | undefined)[], maxEventBytes?: number, targetBatchBytes?: number): AiBatchPartition;
|
|
11
|
-
//# sourceMappingURL=batching.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"batching.d.ts","sourceRoot":"","sources":["../../src/ai-capture/batching.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAqB,MAAM,eAAe,CAAA;AAMzE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,sBAAsB,EAAE,EAAE,CAAA;IACnC,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;CAC5C,CAAA;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,sBAAsB,GAAG,MAAM,CAErE;AAED,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,CAAC,sBAAsB,GAAG,SAAS,CAAC,EAAE,EAChD,aAAa,GAAE,MAA2B,EAC1C,gBAAgB,GAAE,MAA8B,GAC/C,gBAAgB,CA2BlB"}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __webpack_require__ = {};
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
-
var define = (defs, kind)=>{
|
|
6
|
-
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
[kind]: defs[key]
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
define(getters, "get");
|
|
12
|
-
define(values, "value");
|
|
13
|
-
};
|
|
14
|
-
})();
|
|
15
|
-
(()=>{
|
|
16
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
-
})();
|
|
18
|
-
(()=>{
|
|
19
|
-
__webpack_require__.r = (exports1)=>{
|
|
20
|
-
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
-
value: 'Module'
|
|
22
|
-
});
|
|
23
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
-
value: true
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
})();
|
|
28
|
-
var __webpack_exports__ = {};
|
|
29
|
-
__webpack_require__.r(__webpack_exports__);
|
|
30
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
-
eventByteSize: ()=>eventByteSize,
|
|
32
|
-
partitionAiBatch: ()=>partitionAiBatch
|
|
33
|
-
});
|
|
34
|
-
const core_namespaceObject = require("@posthog/core");
|
|
35
|
-
const external_routing_js_namespaceObject = require("./routing.js");
|
|
36
|
-
const encoder = new TextEncoder();
|
|
37
|
-
function eventByteSize(message) {
|
|
38
|
-
return encoder.encode((0, core_namespaceObject.safeJsonStringify)(message)).length;
|
|
39
|
-
}
|
|
40
|
-
function partitionAiBatch(messages, maxEventBytes = external_routing_js_namespaceObject.AI_MAX_EVENT_BYTES, targetBatchBytes = external_routing_js_namespaceObject.AI_BATCH_TARGET_BYTES) {
|
|
41
|
-
const batches = [];
|
|
42
|
-
const dropped = [];
|
|
43
|
-
let current = [];
|
|
44
|
-
let currentBytes = 0;
|
|
45
|
-
for (const message of messages){
|
|
46
|
-
if (void 0 === message) continue;
|
|
47
|
-
const bytes = eventByteSize(message);
|
|
48
|
-
if (bytes > maxEventBytes) {
|
|
49
|
-
dropped.push({
|
|
50
|
-
event: 'string' == typeof message.event ? message.event : 'unknown',
|
|
51
|
-
bytes
|
|
52
|
-
});
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
if (current.length > 0 && currentBytes + bytes > targetBatchBytes) {
|
|
56
|
-
batches.push(current);
|
|
57
|
-
current = [];
|
|
58
|
-
currentBytes = 0;
|
|
59
|
-
}
|
|
60
|
-
current.push(message);
|
|
61
|
-
currentBytes += bytes;
|
|
62
|
-
}
|
|
63
|
-
if (current.length > 0) batches.push(current);
|
|
64
|
-
return {
|
|
65
|
-
batches,
|
|
66
|
-
dropped
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
exports.eventByteSize = __webpack_exports__.eventByteSize;
|
|
70
|
-
exports.partitionAiBatch = __webpack_exports__.partitionAiBatch;
|
|
71
|
-
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
72
|
-
"eventByteSize",
|
|
73
|
-
"partitionAiBatch"
|
|
74
|
-
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
75
|
-
Object.defineProperty(exports, '__esModule', {
|
|
76
|
-
value: true
|
|
77
|
-
});
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { safeJsonStringify } from "@posthog/core";
|
|
2
|
-
import { AI_BATCH_TARGET_BYTES, AI_MAX_EVENT_BYTES } from "./routing.mjs";
|
|
3
|
-
const encoder = new TextEncoder();
|
|
4
|
-
function eventByteSize(message) {
|
|
5
|
-
return encoder.encode(safeJsonStringify(message)).length;
|
|
6
|
-
}
|
|
7
|
-
function partitionAiBatch(messages, maxEventBytes = AI_MAX_EVENT_BYTES, targetBatchBytes = AI_BATCH_TARGET_BYTES) {
|
|
8
|
-
const batches = [];
|
|
9
|
-
const dropped = [];
|
|
10
|
-
let current = [];
|
|
11
|
-
let currentBytes = 0;
|
|
12
|
-
for (const message of messages){
|
|
13
|
-
if (void 0 === message) continue;
|
|
14
|
-
const bytes = eventByteSize(message);
|
|
15
|
-
if (bytes > maxEventBytes) {
|
|
16
|
-
dropped.push({
|
|
17
|
-
event: 'string' == typeof message.event ? message.event : 'unknown',
|
|
18
|
-
bytes
|
|
19
|
-
});
|
|
20
|
-
continue;
|
|
21
|
-
}
|
|
22
|
-
if (current.length > 0 && currentBytes + bytes > targetBatchBytes) {
|
|
23
|
-
batches.push(current);
|
|
24
|
-
current = [];
|
|
25
|
-
currentBytes = 0;
|
|
26
|
-
}
|
|
27
|
-
current.push(message);
|
|
28
|
-
currentBytes += bytes;
|
|
29
|
-
}
|
|
30
|
-
if (current.length > 0) batches.push(current);
|
|
31
|
-
return {
|
|
32
|
-
batches,
|
|
33
|
-
dropped
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
export { eventByteSize, partitionAiBatch };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/** Capture submission mode: `v0` is the legacy `/batch/` endpoint, `v1` is `/i/v1/analytics/events`. */
|
|
2
|
-
export type CaptureMode = 'v0' | 'v1';
|
|
3
|
-
/**
|
|
4
|
-
* Resolve the effective capture mode from the `POSTHOG_CAPTURE_MODE` environment
|
|
5
|
-
* variable (guarded for edge / no-`process` runtimes). The default is `v0`, so
|
|
6
|
-
* existing users are unaffected unless they explicitly opt in. Capture V1 is
|
|
7
|
-
* intentionally env-var-only during the transition — there is no public option,
|
|
8
|
-
* so nothing on the API surface has to be removed when v1 becomes the default.
|
|
9
|
-
*/
|
|
10
|
-
export declare function resolveCaptureMode(): CaptureMode;
|
|
11
|
-
//# sourceMappingURL=config.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/capture-v1/config.ts"],"names":[],"mappings":"AAAA,wGAAwG;AACxG,MAAM,MAAM,WAAW,GAAG,IAAI,GAAG,IAAI,CAAA;AAMrC;;;;;;GAMG;AACH,wBAAgB,kBAAkB,IAAI,WAAW,CAGhD"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
function isCaptureMode(value) {
|
|
2
|
-
return 'v0' === value || 'v1' === value;
|
|
3
|
-
}
|
|
4
|
-
function resolveCaptureMode() {
|
|
5
|
-
const envMode = "u" > typeof process ? process.env?.POSTHOG_CAPTURE_MODE : void 0;
|
|
6
|
-
return isCaptureMode(envMode) ? envMode : 'v0';
|
|
7
|
-
}
|
|
8
|
-
export { resolveCaptureMode };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { PostHogEventProperties } from '@posthog/core';
|
|
2
|
-
/**
|
|
3
|
-
* Queue route for events eligible for Capture V1 (everything except `$ai_*`). Its queue is the
|
|
4
|
-
* historical {@link PostHogPersistedProperty.Queue}, so v0 mode is byte-identical to before.
|
|
5
|
-
*/
|
|
6
|
-
export declare const ANALYTICS_ROUTE = "analytics";
|
|
7
|
-
/**
|
|
8
|
-
* Queue route for `$ai_*` events, kept on the legacy (v0) transport in v1 mode and isolated on
|
|
9
|
-
* its own queue so a v0 failure can't re-send events already accepted on the V1 route. This route
|
|
10
|
-
* will later host a dedicated v1 AI-events transport once that endpoint exists — segregating it
|
|
11
|
-
* now means no re-plumbing then.
|
|
12
|
-
*/
|
|
13
|
-
export declare const AI_ROUTE = "ai";
|
|
14
|
-
/**
|
|
15
|
-
* True for events that must keep using the legacy (v0) submitter even when the
|
|
16
|
-
* client is in v1 mode. Today that is only `$ai_*` events: the dedicated AI
|
|
17
|
-
* ingestion path has no v1 form, so they stay on v0 until AI v1 is designed.
|
|
18
|
-
* The check runs on the post-`before_send` event name.
|
|
19
|
-
*/
|
|
20
|
-
export declare function isLegacyOnlyEvent(message: PostHogEventProperties): boolean;
|
|
21
|
-
//# sourceMappingURL=routing.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"routing.d.ts","sourceRoot":"","sources":["../../src/capture-v1/routing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AAK3D;;;GAGG;AACH,eAAO,MAAM,eAAe,cAAc,CAAA;AAE1C;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,OAAO,CAAA;AAE5B;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAE1E"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
const AI_EVENT_PREFIX = '$ai_';
|
|
2
|
-
const ANALYTICS_ROUTE = 'analytics';
|
|
3
|
-
const AI_ROUTE = 'ai';
|
|
4
|
-
function isLegacyOnlyEvent(message) {
|
|
5
|
-
return 'string' == typeof message.event && message.event.startsWith(AI_EVENT_PREFIX);
|
|
6
|
-
}
|
|
7
|
-
export { AI_ROUTE, ANALYTICS_ROUTE, isLegacyOnlyEvent };
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { PostHogEventProperties, safeJsonStringify } from '@posthog/core'
|
|
2
|
-
|
|
3
|
-
import { AI_BATCH_TARGET_BYTES, AI_MAX_EVENT_BYTES } from './routing'
|
|
4
|
-
|
|
5
|
-
const encoder = new TextEncoder()
|
|
6
|
-
|
|
7
|
-
export type AiBatchPartition = {
|
|
8
|
-
batches: PostHogEventProperties[][]
|
|
9
|
-
dropped: { event: string; bytes: number }[]
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function eventByteSize(message: PostHogEventProperties): number {
|
|
13
|
-
return encoder.encode(safeJsonStringify(message)).length
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function partitionAiBatch(
|
|
17
|
-
messages: (PostHogEventProperties | undefined)[],
|
|
18
|
-
maxEventBytes: number = AI_MAX_EVENT_BYTES,
|
|
19
|
-
targetBatchBytes: number = AI_BATCH_TARGET_BYTES
|
|
20
|
-
): AiBatchPartition {
|
|
21
|
-
const batches: PostHogEventProperties[][] = []
|
|
22
|
-
const dropped: { event: string; bytes: number }[] = []
|
|
23
|
-
let current: PostHogEventProperties[] = []
|
|
24
|
-
let currentBytes = 0
|
|
25
|
-
|
|
26
|
-
for (const message of messages) {
|
|
27
|
-
if (message === undefined) {
|
|
28
|
-
continue
|
|
29
|
-
}
|
|
30
|
-
const bytes = eventByteSize(message)
|
|
31
|
-
if (bytes > maxEventBytes) {
|
|
32
|
-
dropped.push({ event: typeof message.event === 'string' ? message.event : 'unknown', bytes })
|
|
33
|
-
continue
|
|
34
|
-
}
|
|
35
|
-
if (current.length > 0 && currentBytes + bytes > targetBatchBytes) {
|
|
36
|
-
batches.push(current)
|
|
37
|
-
current = []
|
|
38
|
-
currentBytes = 0
|
|
39
|
-
}
|
|
40
|
-
current.push(message)
|
|
41
|
-
currentBytes += bytes
|
|
42
|
-
}
|
|
43
|
-
if (current.length > 0) {
|
|
44
|
-
batches.push(current)
|
|
45
|
-
}
|
|
46
|
-
return { batches, dropped }
|
|
47
|
-
}
|
package/src/capture-v1/config.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/** Capture submission mode: `v0` is the legacy `/batch/` endpoint, `v1` is `/i/v1/analytics/events`. */
|
|
2
|
-
export type CaptureMode = 'v0' | 'v1'
|
|
3
|
-
|
|
4
|
-
function isCaptureMode(value: unknown): value is CaptureMode {
|
|
5
|
-
return value === 'v0' || value === 'v1'
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Resolve the effective capture mode from the `POSTHOG_CAPTURE_MODE` environment
|
|
10
|
-
* variable (guarded for edge / no-`process` runtimes). The default is `v0`, so
|
|
11
|
-
* existing users are unaffected unless they explicitly opt in. Capture V1 is
|
|
12
|
-
* intentionally env-var-only during the transition — there is no public option,
|
|
13
|
-
* so nothing on the API surface has to be removed when v1 becomes the default.
|
|
14
|
-
*/
|
|
15
|
-
export function resolveCaptureMode(): CaptureMode {
|
|
16
|
-
const envMode = typeof process !== 'undefined' ? process.env?.POSTHOG_CAPTURE_MODE : undefined
|
|
17
|
-
return isCaptureMode(envMode) ? envMode : 'v0'
|
|
18
|
-
}
|