posthog-js-lite 3.5.0 → 3.5.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/lib/index.d.ts CHANGED
@@ -1,655 +1,674 @@
1
- type PostHogCoreOptions = {
2
- /** PostHog API host, usually 'https://us.i.posthog.com' or 'https://eu.i.posthog.com' */
3
- host?: string;
4
- /** The number of events to queue before sending to PostHog (flushing) */
5
- flushAt?: number;
6
- /** The interval in milliseconds between periodic flushes */
7
- flushInterval?: number;
8
- /** The maximum number of queued messages to be flushed as part of a single batch (must be higher than `flushAt`) */
9
- maxBatchSize?: number;
10
- /** The maximum number of cached messages either in memory or on the local storage.
11
- * Defaults to 1000, (must be higher than `flushAt`)
12
- */
13
- maxQueueSize?: number;
14
- /** If set to true the SDK is essentially disabled (useful for local environments where you don't want to track anything) */
15
- disabled?: boolean;
16
- /** If set to false the SDK will not track until the `optIn` function is called. */
17
- defaultOptIn?: boolean;
18
- /** Whether to track that `getFeatureFlag` was called (used by Experiments) */
19
- sendFeatureFlagEvent?: boolean;
20
- /** Whether to load feature flags when initialized or not */
21
- preloadFeatureFlags?: boolean;
22
- /**
23
- * Whether to load remote config when initialized or not
24
- * Experimental support
25
- * Default: false - Remote config is loaded by default
26
- */
27
- disableRemoteConfig?: boolean;
28
- /**
29
- * Whether to load surveys when initialized or not
30
- * Experimental support
31
- * Default: false - Surveys are loaded by default, but requires the `PostHogSurveyProvider` to be used
32
- */
33
- disableSurveys?: boolean;
34
- /** Option to bootstrap the library with given distinctId and feature flags */
35
- bootstrap?: {
36
- distinctId?: string;
37
- isIdentifiedId?: boolean;
38
- featureFlags?: Record<string, FeatureFlagValue>;
39
- featureFlagPayloads?: Record<string, JsonType>;
40
- };
41
- /** How many times we will retry HTTP requests. Defaults to 3. */
42
- fetchRetryCount?: number;
43
- /** The delay between HTTP request retries, Defaults to 3 seconds. */
44
- fetchRetryDelay?: number;
45
- /** Timeout in milliseconds for any calls. Defaults to 10 seconds. */
46
- requestTimeout?: number;
47
- /** Timeout in milliseconds for feature flag calls. Defaults to 10 seconds for stateful clients, and 3 seconds for stateless. */
48
- featureFlagsRequestTimeoutMs?: number;
49
- /** Timeout in milliseconds for remote config calls. Defaults to 3 seconds. */
50
- remoteConfigRequestTimeoutMs?: number;
51
- /** For Session Analysis how long before we expire a session (defaults to 30 mins) */
52
- sessionExpirationTimeSeconds?: number;
53
- /** Whether to post events to PostHog in JSON or compressed format. Defaults to 'json' */
54
- captureMode?: 'json' | 'form';
55
- disableGeoip?: boolean;
56
- /** Special flag to indicate ingested data is for a historical migration. */
57
- historicalMigration?: boolean;
58
- };
59
- declare enum PostHogPersistedProperty {
60
- AnonymousId = "anonymous_id",
61
- DistinctId = "distinct_id",
62
- Props = "props",
63
- FeatureFlagDetails = "feature_flag_details",
64
- FeatureFlags = "feature_flags",
65
- FeatureFlagPayloads = "feature_flag_payloads",
66
- BootstrapFeatureFlagDetails = "bootstrap_feature_flag_details",
67
- BootstrapFeatureFlags = "bootstrap_feature_flags",
68
- BootstrapFeatureFlagPayloads = "bootstrap_feature_flag_payloads",
69
- OverrideFeatureFlags = "override_feature_flags",
70
- Queue = "queue",
71
- OptedOut = "opted_out",
72
- SessionId = "session_id",
73
- SessionLastTimestamp = "session_timestamp",
74
- PersonProperties = "person_properties",
75
- GroupProperties = "group_properties",
76
- InstalledAppBuild = "installed_app_build",
77
- InstalledAppVersion = "installed_app_version",
78
- SessionReplay = "session_replay",
79
- DecideEndpointWasHit = "decide_endpoint_was_hit",
80
- SurveyLastSeenDate = "survey_last_seen_date",
81
- SurveysSeen = "surveys_seen",
82
- Surveys = "surveys",
83
- RemoteConfig = "remote_config"
84
- }
85
- type PostHogFetchOptions = {
86
- method: 'GET' | 'POST' | 'PUT' | 'PATCH';
87
- mode?: 'no-cors';
88
- credentials?: 'omit';
89
- headers: {
90
- [key: string]: string;
91
- };
92
- body?: string;
93
- signal?: AbortSignal;
94
- };
95
- type PostHogCaptureOptions = {
96
- /** If provided overrides the auto-generated event ID */
97
- uuid?: string;
98
- /** If provided overrides the auto-generated timestamp */
99
- timestamp?: Date;
100
- disableGeoip?: boolean;
101
- };
102
- type PostHogFetchResponse = {
103
- status: number;
104
- text: () => Promise<string>;
105
- json: () => Promise<any>;
106
- };
107
- type PostHogEventProperties = {
108
- [key: string]: any;
109
- };
110
- type PostHogAutocaptureElement = {
111
- $el_text?: string;
112
- tag_name: string;
113
- href?: string;
114
- nth_child?: number;
115
- nth_of_type?: number;
116
- order?: number;
117
- } & {
118
- [key: string]: any;
119
- };
120
- type PostHogRemoteConfig = {
121
- sessionRecording?: boolean | {
122
- [key: string]: JsonType;
123
- };
124
- /**
125
- * Whether surveys are enabled
126
- */
127
- surveys?: boolean | Survey[];
128
- /**
129
- * Indicates if the team has any flags enabled (if not we don't need to load them)
130
- */
131
- hasFeatureFlags?: boolean;
132
- };
133
- type FeatureFlagValue = string | boolean;
134
- type PostHogDecideResponse = Omit<PostHogRemoteConfig, 'surveys' | 'hasFeatureFlags'> & {
135
- featureFlags: {
136
- [key: string]: FeatureFlagValue;
137
- };
138
- featureFlagPayloads: {
139
- [key: string]: JsonType;
140
- };
141
- flags: {
142
- [key: string]: FeatureFlagDetail;
143
- };
144
- errorsWhileComputingFlags: boolean;
145
- sessionRecording?: boolean | {
146
- [key: string]: JsonType;
147
- };
148
- quotaLimited?: string[];
149
- requestId?: string;
150
- };
151
- /**
152
- * Creates a type with all properties of T, but makes only K properties required while the rest remain optional.
153
- *
154
- * @template T - The base type containing all properties
155
- * @template K - Union type of keys from T that should be required
156
- *
157
- * @example
158
- * interface User {
159
- * id: number;
160
- * name: string;
161
- * email?: string;
162
- * age?: number;
163
- * }
164
- *
165
- * // Makes 'id' and 'name' required, but 'email' and 'age' optional
166
- * type RequiredUser = PartialWithRequired<User, 'id' | 'name'>;
167
- *
168
- * const user: RequiredUser = {
169
- * id: 1, // Must be provided
170
- * name: "John" // Must be provided
171
- * // email and age are optional
172
- * };
173
- */
174
- type PartialWithRequired<T, K extends keyof T> = {
175
- [P in K]: T[P];
176
- } & {
177
- [P in Exclude<keyof T, K>]?: T[P];
178
- };
179
- /**
180
- * These are the fields we care about from PostHogDecideResponse for feature flags.
181
- */
182
- type PostHogFeatureFlagDetails = PartialWithRequired<PostHogDecideResponse, 'flags' | 'featureFlags' | 'featureFlagPayloads' | 'requestId'>;
183
- type JsonType = string | number | boolean | null | {
184
- [key: string]: JsonType;
185
- } | Array<JsonType>;
186
- type FeatureFlagDetail = {
187
- key: string;
188
- enabled: boolean;
189
- variant: string | undefined;
190
- reason: EvaluationReason | undefined;
191
- metadata: FeatureFlagMetadata | undefined;
192
- };
193
- type FeatureFlagMetadata = {
194
- id: number | undefined;
195
- version: number | undefined;
196
- description: string | undefined;
197
- payload: string | undefined;
198
- };
199
- type EvaluationReason = {
200
- code: string | undefined;
201
- condition_index: number | undefined;
202
- description: string | undefined;
203
- };
204
- type SurveyAppearance = {
205
- backgroundColor?: string;
206
- submitButtonColor?: string;
207
- submitButtonText?: string;
208
- submitButtonTextColor?: string;
209
- ratingButtonColor?: string;
210
- ratingButtonActiveColor?: string;
211
- autoDisappear?: boolean;
212
- displayThankYouMessage?: boolean;
213
- thankYouMessageHeader?: string;
214
- thankYouMessageDescription?: string;
215
- thankYouMessageDescriptionContentType?: SurveyQuestionDescriptionContentType;
216
- thankYouMessageCloseButtonText?: string;
217
- borderColor?: string;
218
- position?: SurveyPosition;
219
- placeholder?: string;
220
- shuffleQuestions?: boolean;
221
- surveyPopupDelaySeconds?: number;
222
- widgetType?: SurveyWidgetType;
223
- widgetSelector?: string;
224
- widgetLabel?: string;
225
- widgetColor?: string;
226
- };
227
- declare enum SurveyPosition {
228
- Left = "left",
229
- Right = "right",
230
- Center = "center"
231
- }
232
- declare enum SurveyWidgetType {
233
- Button = "button",
234
- Tab = "tab",
235
- Selector = "selector"
236
- }
237
- declare enum SurveyType {
238
- Popover = "popover",
239
- API = "api",
240
- Widget = "widget"
241
- }
242
- type SurveyQuestion = BasicSurveyQuestion | LinkSurveyQuestion | RatingSurveyQuestion | MultipleSurveyQuestion;
243
- declare enum SurveyQuestionDescriptionContentType {
244
- Html = "html",
245
- Text = "text"
246
- }
247
- type SurveyQuestionBase = {
248
- question: string;
249
- id?: string;
250
- description?: string;
251
- descriptionContentType?: SurveyQuestionDescriptionContentType;
252
- optional?: boolean;
253
- buttonText?: string;
254
- originalQuestionIndex: number;
255
- branching?: NextQuestionBranching | EndBranching | ResponseBasedBranching | SpecificQuestionBranching;
256
- };
257
- type BasicSurveyQuestion = SurveyQuestionBase & {
258
- type: SurveyQuestionType.Open;
259
- };
260
- type LinkSurveyQuestion = SurveyQuestionBase & {
261
- type: SurveyQuestionType.Link;
262
- link?: string;
263
- };
264
- type RatingSurveyQuestion = SurveyQuestionBase & {
265
- type: SurveyQuestionType.Rating;
266
- display: SurveyRatingDisplay;
267
- scale: 3 | 5 | 7 | 10;
268
- lowerBoundLabel: string;
269
- upperBoundLabel: string;
270
- };
271
- declare enum SurveyRatingDisplay {
272
- Number = "number",
273
- Emoji = "emoji"
274
- }
275
- type MultipleSurveyQuestion = SurveyQuestionBase & {
276
- type: SurveyQuestionType.SingleChoice | SurveyQuestionType.MultipleChoice;
277
- choices: string[];
278
- hasOpenChoice?: boolean;
279
- shuffleOptions?: boolean;
280
- };
281
- declare enum SurveyQuestionType {
282
- Open = "open",
283
- MultipleChoice = "multiple_choice",
284
- SingleChoice = "single_choice",
285
- Rating = "rating",
286
- Link = "link"
287
- }
288
- declare enum SurveyQuestionBranchingType {
289
- NextQuestion = "next_question",
290
- End = "end",
291
- ResponseBased = "response_based",
292
- SpecificQuestion = "specific_question"
293
- }
294
- type NextQuestionBranching = {
295
- type: SurveyQuestionBranchingType.NextQuestion;
296
- };
297
- type EndBranching = {
298
- type: SurveyQuestionBranchingType.End;
299
- };
300
- type ResponseBasedBranching = {
301
- type: SurveyQuestionBranchingType.ResponseBased;
302
- responseValues: Record<string, any>;
303
- };
304
- type SpecificQuestionBranching = {
305
- type: SurveyQuestionBranchingType.SpecificQuestion;
306
- index: number;
307
- };
308
- type SurveyResponse = {
309
- surveys: Survey[];
310
- };
311
- declare enum SurveyMatchType {
312
- Regex = "regex",
313
- NotRegex = "not_regex",
314
- Exact = "exact",
315
- IsNot = "is_not",
316
- Icontains = "icontains",
317
- NotIcontains = "not_icontains"
318
- }
319
- type Survey = {
320
- id: string;
321
- name: string;
322
- description?: string;
323
- type: SurveyType;
324
- feature_flag_keys?: {
325
- key: string;
326
- value?: string;
327
- }[];
328
- linked_flag_key?: string;
329
- targeting_flag_key?: string;
330
- internal_targeting_flag_key?: string;
331
- questions: SurveyQuestion[];
332
- appearance?: SurveyAppearance;
333
- conditions?: {
334
- url?: string;
335
- selector?: string;
336
- seenSurveyWaitPeriodInDays?: number;
337
- urlMatchType?: SurveyMatchType;
338
- events?: {
339
- repeatedActivation?: boolean;
340
- values?: {
341
- name: string;
342
- }[];
343
- };
344
- actions?: {
345
- values: SurveyActionType[];
346
- };
347
- deviceTypes?: string[];
348
- deviceTypesMatchType?: SurveyMatchType;
349
- };
350
- start_date?: string;
351
- end_date?: string;
352
- current_iteration?: number;
353
- current_iteration_start_date?: string;
354
- };
355
- type SurveyActionType = {
356
- id: number;
357
- name?: string;
358
- steps?: ActionStepType[];
359
- };
360
- /** Sync with plugin-server/src/types.ts */
361
- declare enum ActionStepStringMatching {
362
- Contains = "contains",
363
- Exact = "exact",
364
- Regex = "regex"
365
- }
366
- type ActionStepType = {
367
- event?: string;
368
- selector?: string;
369
- /** @deprecated Only `selector` should be used now. */
370
- tag_name?: string;
371
- text?: string;
372
- /** @default StringMatching.Exact */
373
- text_matching?: ActionStepStringMatching;
374
- href?: string;
375
- /** @default ActionStepStringMatching.Exact */
376
- href_matching?: ActionStepStringMatching;
377
- url?: string;
378
- /** @default StringMatching.Contains */
379
- url_matching?: ActionStepStringMatching;
1
+ type PostHogCoreOptions = {
2
+ /** PostHog API host, usually 'https://us.i.posthog.com' or 'https://eu.i.posthog.com' */
3
+ host?: string;
4
+ /** The number of events to queue before sending to PostHog (flushing) */
5
+ flushAt?: number;
6
+ /** The interval in milliseconds between periodic flushes */
7
+ flushInterval?: number;
8
+ /** The maximum number of queued messages to be flushed as part of a single batch (must be higher than `flushAt`) */
9
+ maxBatchSize?: number;
10
+ /** The maximum number of cached messages either in memory or on the local storage.
11
+ * Defaults to 1000, (must be higher than `flushAt`)
12
+ */
13
+ maxQueueSize?: number;
14
+ /** If set to true the SDK is essentially disabled (useful for local environments where you don't want to track anything) */
15
+ disabled?: boolean;
16
+ /** If set to false the SDK will not track until the `optIn` function is called. */
17
+ defaultOptIn?: boolean;
18
+ /** Whether to track that `getFeatureFlag` was called (used by Experiments) */
19
+ sendFeatureFlagEvent?: boolean;
20
+ /** Whether to load feature flags when initialized or not */
21
+ preloadFeatureFlags?: boolean;
22
+ /**
23
+ * Whether to load remote config when initialized or not
24
+ * Experimental support
25
+ * Default: false - Remote config is loaded by default
26
+ */
27
+ disableRemoteConfig?: boolean;
28
+ /**
29
+ * Whether to load surveys when initialized or not
30
+ * Experimental support
31
+ * Default: false - Surveys are loaded by default, but requires the `PostHogSurveyProvider` to be used
32
+ */
33
+ disableSurveys?: boolean;
34
+ /** Option to bootstrap the library with given distinctId and feature flags */
35
+ bootstrap?: {
36
+ distinctId?: string;
37
+ isIdentifiedId?: boolean;
38
+ featureFlags?: Record<string, FeatureFlagValue>;
39
+ featureFlagPayloads?: Record<string, JsonType>;
40
+ };
41
+ /** How many times we will retry HTTP requests. Defaults to 3. */
42
+ fetchRetryCount?: number;
43
+ /** The delay between HTTP request retries, Defaults to 3 seconds. */
44
+ fetchRetryDelay?: number;
45
+ /** Timeout in milliseconds for any calls. Defaults to 10 seconds. */
46
+ requestTimeout?: number;
47
+ /** Timeout in milliseconds for feature flag calls. Defaults to 10 seconds for stateful clients, and 3 seconds for stateless. */
48
+ featureFlagsRequestTimeoutMs?: number;
49
+ /** Timeout in milliseconds for remote config calls. Defaults to 3 seconds. */
50
+ remoteConfigRequestTimeoutMs?: number;
51
+ /** For Session Analysis how long before we expire a session (defaults to 30 mins) */
52
+ sessionExpirationTimeSeconds?: number;
53
+ /** Whether to post events to PostHog in JSON or compressed format. Defaults to 'json' */
54
+ captureMode?: 'json' | 'form';
55
+ disableGeoip?: boolean;
56
+ /** Special flag to indicate ingested data is for a historical migration. */
57
+ historicalMigration?: boolean;
58
+ };
59
+ declare enum PostHogPersistedProperty {
60
+ AnonymousId = "anonymous_id",
61
+ DistinctId = "distinct_id",
62
+ Props = "props",
63
+ FeatureFlagDetails = "feature_flag_details",
64
+ FeatureFlags = "feature_flags",
65
+ FeatureFlagPayloads = "feature_flag_payloads",
66
+ BootstrapFeatureFlagDetails = "bootstrap_feature_flag_details",
67
+ BootstrapFeatureFlags = "bootstrap_feature_flags",
68
+ BootstrapFeatureFlagPayloads = "bootstrap_feature_flag_payloads",
69
+ OverrideFeatureFlags = "override_feature_flags",
70
+ Queue = "queue",
71
+ OptedOut = "opted_out",
72
+ SessionId = "session_id",
73
+ SessionLastTimestamp = "session_timestamp",
74
+ PersonProperties = "person_properties",
75
+ GroupProperties = "group_properties",
76
+ InstalledAppBuild = "installed_app_build",
77
+ InstalledAppVersion = "installed_app_version",
78
+ SessionReplay = "session_replay",
79
+ DecideEndpointWasHit = "decide_endpoint_was_hit",
80
+ SurveyLastSeenDate = "survey_last_seen_date",
81
+ SurveysSeen = "surveys_seen",
82
+ Surveys = "surveys",
83
+ RemoteConfig = "remote_config"
84
+ }
85
+ type PostHogFetchOptions = {
86
+ method: 'GET' | 'POST' | 'PUT' | 'PATCH';
87
+ mode?: 'no-cors';
88
+ credentials?: 'omit';
89
+ headers: {
90
+ [key: string]: string;
91
+ };
92
+ body?: string;
93
+ signal?: AbortSignal;
94
+ };
95
+ type PostHogCaptureOptions = {
96
+ /** If provided overrides the auto-generated event ID */
97
+ uuid?: string;
98
+ /** If provided overrides the auto-generated timestamp */
99
+ timestamp?: Date;
100
+ disableGeoip?: boolean;
101
+ };
102
+ type PostHogFetchResponse = {
103
+ status: number;
104
+ text: () => Promise<string>;
105
+ json: () => Promise<any>;
106
+ };
107
+ type PostHogEventProperties = {
108
+ [key: string]: any;
109
+ };
110
+ type PostHogAutocaptureElement = {
111
+ $el_text?: string;
112
+ tag_name: string;
113
+ href?: string;
114
+ nth_child?: number;
115
+ nth_of_type?: number;
116
+ order?: number;
117
+ } & {
118
+ [key: string]: any;
119
+ };
120
+ type PostHogRemoteConfig = {
121
+ sessionRecording?: boolean | {
122
+ [key: string]: JsonType;
123
+ };
124
+ /**
125
+ * Whether surveys are enabled
126
+ */
127
+ surveys?: boolean | Survey[];
128
+ /**
129
+ * Indicates if the team has any flags enabled (if not we don't need to load them)
130
+ */
131
+ hasFeatureFlags?: boolean;
132
+ };
133
+ type FeatureFlagValue = string | boolean;
134
+ type PostHogDecideResponse = Omit<PostHogRemoteConfig, 'surveys' | 'hasFeatureFlags'> & {
135
+ featureFlags: {
136
+ [key: string]: FeatureFlagValue;
137
+ };
138
+ featureFlagPayloads: {
139
+ [key: string]: JsonType;
140
+ };
141
+ flags: {
142
+ [key: string]: FeatureFlagDetail;
143
+ };
144
+ errorsWhileComputingFlags: boolean;
145
+ sessionRecording?: boolean | {
146
+ [key: string]: JsonType;
147
+ };
148
+ quotaLimited?: string[];
149
+ requestId?: string;
150
+ };
151
+ /**
152
+ * Creates a type with all properties of T, but makes only K properties required while the rest remain optional.
153
+ *
154
+ * @template T - The base type containing all properties
155
+ * @template K - Union type of keys from T that should be required
156
+ *
157
+ * @example
158
+ * interface User {
159
+ * id: number;
160
+ * name: string;
161
+ * email?: string;
162
+ * age?: number;
163
+ * }
164
+ *
165
+ * // Makes 'id' and 'name' required, but 'email' and 'age' optional
166
+ * type RequiredUser = PartialWithRequired<User, 'id' | 'name'>;
167
+ *
168
+ * const user: RequiredUser = {
169
+ * id: 1, // Must be provided
170
+ * name: "John" // Must be provided
171
+ * // email and age are optional
172
+ * };
173
+ */
174
+ type PartialWithRequired<T, K extends keyof T> = {
175
+ [P in K]: T[P];
176
+ } & {
177
+ [P in Exclude<keyof T, K>]?: T[P];
178
+ };
179
+ /**
180
+ * These are the fields we care about from PostHogDecideResponse for feature flags.
181
+ */
182
+ type PostHogFeatureFlagDetails = PartialWithRequired<PostHogDecideResponse, 'flags' | 'featureFlags' | 'featureFlagPayloads' | 'requestId'>;
183
+ type JsonType = string | number | boolean | null | {
184
+ [key: string]: JsonType;
185
+ } | Array<JsonType>;
186
+ type FeatureFlagDetail = {
187
+ key: string;
188
+ enabled: boolean;
189
+ variant: string | undefined;
190
+ reason: EvaluationReason | undefined;
191
+ metadata: FeatureFlagMetadata | undefined;
192
+ };
193
+ type FeatureFlagMetadata = {
194
+ id: number | undefined;
195
+ version: number | undefined;
196
+ description: string | undefined;
197
+ payload: string | undefined;
198
+ };
199
+ type EvaluationReason = {
200
+ code: string | undefined;
201
+ condition_index: number | undefined;
202
+ description: string | undefined;
203
+ };
204
+ type SurveyAppearance = {
205
+ backgroundColor?: string;
206
+ submitButtonColor?: string;
207
+ submitButtonText?: string;
208
+ submitButtonTextColor?: string;
209
+ ratingButtonColor?: string;
210
+ ratingButtonActiveColor?: string;
211
+ autoDisappear?: boolean;
212
+ displayThankYouMessage?: boolean;
213
+ thankYouMessageHeader?: string;
214
+ thankYouMessageDescription?: string;
215
+ thankYouMessageDescriptionContentType?: SurveyQuestionDescriptionContentType;
216
+ thankYouMessageCloseButtonText?: string;
217
+ borderColor?: string;
218
+ position?: SurveyPosition;
219
+ placeholder?: string;
220
+ shuffleQuestions?: boolean;
221
+ surveyPopupDelaySeconds?: number;
222
+ widgetType?: SurveyWidgetType;
223
+ widgetSelector?: string;
224
+ widgetLabel?: string;
225
+ widgetColor?: string;
226
+ };
227
+ declare enum SurveyPosition {
228
+ Left = "left",
229
+ Right = "right",
230
+ Center = "center"
231
+ }
232
+ declare enum SurveyWidgetType {
233
+ Button = "button",
234
+ Tab = "tab",
235
+ Selector = "selector"
236
+ }
237
+ declare enum SurveyType {
238
+ Popover = "popover",
239
+ API = "api",
240
+ Widget = "widget"
241
+ }
242
+ type SurveyQuestion = BasicSurveyQuestion | LinkSurveyQuestion | RatingSurveyQuestion | MultipleSurveyQuestion;
243
+ declare enum SurveyQuestionDescriptionContentType {
244
+ Html = "html",
245
+ Text = "text"
246
+ }
247
+ type SurveyQuestionBase = {
248
+ question: string;
249
+ id?: string;
250
+ description?: string;
251
+ descriptionContentType?: SurveyQuestionDescriptionContentType;
252
+ optional?: boolean;
253
+ buttonText?: string;
254
+ originalQuestionIndex: number;
255
+ branching?: NextQuestionBranching | EndBranching | ResponseBasedBranching | SpecificQuestionBranching;
256
+ };
257
+ type BasicSurveyQuestion = SurveyQuestionBase & {
258
+ type: SurveyQuestionType.Open;
259
+ };
260
+ type LinkSurveyQuestion = SurveyQuestionBase & {
261
+ type: SurveyQuestionType.Link;
262
+ link?: string;
263
+ };
264
+ type RatingSurveyQuestion = SurveyQuestionBase & {
265
+ type: SurveyQuestionType.Rating;
266
+ display: SurveyRatingDisplay;
267
+ scale: 3 | 5 | 7 | 10;
268
+ lowerBoundLabel: string;
269
+ upperBoundLabel: string;
270
+ };
271
+ declare enum SurveyRatingDisplay {
272
+ Number = "number",
273
+ Emoji = "emoji"
274
+ }
275
+ type MultipleSurveyQuestion = SurveyQuestionBase & {
276
+ type: SurveyQuestionType.SingleChoice | SurveyQuestionType.MultipleChoice;
277
+ choices: string[];
278
+ hasOpenChoice?: boolean;
279
+ shuffleOptions?: boolean;
280
+ };
281
+ declare enum SurveyQuestionType {
282
+ Open = "open",
283
+ MultipleChoice = "multiple_choice",
284
+ SingleChoice = "single_choice",
285
+ Rating = "rating",
286
+ Link = "link"
287
+ }
288
+ declare enum SurveyQuestionBranchingType {
289
+ NextQuestion = "next_question",
290
+ End = "end",
291
+ ResponseBased = "response_based",
292
+ SpecificQuestion = "specific_question"
293
+ }
294
+ type NextQuestionBranching = {
295
+ type: SurveyQuestionBranchingType.NextQuestion;
296
+ };
297
+ type EndBranching = {
298
+ type: SurveyQuestionBranchingType.End;
299
+ };
300
+ type ResponseBasedBranching = {
301
+ type: SurveyQuestionBranchingType.ResponseBased;
302
+ responseValues: Record<string, any>;
303
+ };
304
+ type SpecificQuestionBranching = {
305
+ type: SurveyQuestionBranchingType.SpecificQuestion;
306
+ index: number;
307
+ };
308
+ type SurveyResponse = {
309
+ surveys: Survey[];
310
+ };
311
+ declare enum SurveyMatchType {
312
+ Regex = "regex",
313
+ NotRegex = "not_regex",
314
+ Exact = "exact",
315
+ IsNot = "is_not",
316
+ Icontains = "icontains",
317
+ NotIcontains = "not_icontains"
318
+ }
319
+ type Survey = {
320
+ id: string;
321
+ name: string;
322
+ description?: string;
323
+ type: SurveyType;
324
+ feature_flag_keys?: {
325
+ key: string;
326
+ value?: string;
327
+ }[];
328
+ linked_flag_key?: string;
329
+ targeting_flag_key?: string;
330
+ internal_targeting_flag_key?: string;
331
+ questions: SurveyQuestion[];
332
+ appearance?: SurveyAppearance;
333
+ conditions?: {
334
+ url?: string;
335
+ selector?: string;
336
+ seenSurveyWaitPeriodInDays?: number;
337
+ urlMatchType?: SurveyMatchType;
338
+ events?: {
339
+ repeatedActivation?: boolean;
340
+ values?: {
341
+ name: string;
342
+ }[];
343
+ };
344
+ actions?: {
345
+ values: SurveyActionType[];
346
+ };
347
+ deviceTypes?: string[];
348
+ deviceTypesMatchType?: SurveyMatchType;
349
+ };
350
+ start_date?: string;
351
+ end_date?: string;
352
+ current_iteration?: number;
353
+ current_iteration_start_date?: string;
354
+ };
355
+ type SurveyActionType = {
356
+ id: number;
357
+ name?: string;
358
+ steps?: ActionStepType[];
359
+ };
360
+ /** Sync with plugin-server/src/types.ts */
361
+ declare enum ActionStepStringMatching {
362
+ Contains = "contains",
363
+ Exact = "exact",
364
+ Regex = "regex"
365
+ }
366
+ type ActionStepType = {
367
+ event?: string;
368
+ selector?: string;
369
+ /** @deprecated Only `selector` should be used now. */
370
+ tag_name?: string;
371
+ text?: string;
372
+ /** @default StringMatching.Exact */
373
+ text_matching?: ActionStepStringMatching;
374
+ href?: string;
375
+ /** @default ActionStepStringMatching.Exact */
376
+ href_matching?: ActionStepStringMatching;
377
+ url?: string;
378
+ /** @default StringMatching.Contains */
379
+ url_matching?: ActionStepStringMatching;
380
380
  };
381
381
 
382
- interface RetriableOptions {
383
- retryCount: number;
384
- retryDelay: number;
385
- retryCheck: (err: any) => boolean;
382
+ interface RetriableOptions {
383
+ retryCount: number;
384
+ retryDelay: number;
385
+ retryCheck: (err: unknown) => boolean;
386
386
  }
387
387
 
388
- declare class SimpleEventEmitter {
389
- events: {
390
- [key: string]: ((...args: any[]) => void)[];
391
- };
392
- constructor();
393
- on(event: string, listener: (...args: any[]) => void): () => void;
394
- emit(event: string, payload: any): void;
388
+ declare class SimpleEventEmitter {
389
+ events: {
390
+ [key: string]: ((...args: any[]) => void)[];
391
+ };
392
+ constructor();
393
+ on(event: string, listener: (...args: any[]) => void): () => void;
394
+ emit(event: string, payload: any): void;
395
395
  }
396
396
 
397
- declare abstract class PostHogCoreStateless {
398
- readonly apiKey: string;
399
- readonly host: string;
400
- readonly flushAt: number;
401
- readonly preloadFeatureFlags: boolean;
402
- readonly disableSurveys: boolean;
403
- private maxBatchSize;
404
- private maxQueueSize;
405
- private flushInterval;
406
- private flushPromise;
407
- private requestTimeout;
408
- private featureFlagsRequestTimeoutMs;
409
- private remoteConfigRequestTimeoutMs;
410
- private captureMode;
411
- private removeDebugCallback?;
412
- private disableGeoip;
413
- private historicalMigration;
414
- protected disabled: boolean;
415
- private defaultOptIn;
416
- private pendingPromises;
417
- protected _events: SimpleEventEmitter;
418
- protected _flushTimer?: any;
419
- protected _retryOptions: RetriableOptions;
420
- protected _initPromise: Promise<void>;
421
- protected _isInitialized: boolean;
422
- protected _remoteConfigResponsePromise?: Promise<PostHogRemoteConfig | undefined>;
423
- abstract fetch(url: string, options: PostHogFetchOptions): Promise<PostHogFetchResponse>;
424
- abstract getLibraryId(): string;
425
- abstract getLibraryVersion(): string;
426
- abstract getCustomUserAgent(): string | void;
427
- abstract getPersistedProperty<T>(key: PostHogPersistedProperty): T | undefined;
428
- abstract setPersistedProperty<T>(key: PostHogPersistedProperty, value: T | null): void;
429
- constructor(apiKey: string, options?: PostHogCoreOptions);
430
- protected logMsgIfDebug(fn: () => void): void;
431
- protected wrap(fn: () => void): void;
432
- protected getCommonEventProperties(): any;
433
- get optedOut(): boolean;
434
- optIn(): Promise<void>;
435
- optOut(): Promise<void>;
436
- on(event: string, cb: (...args: any[]) => void): () => void;
437
- debug(enabled?: boolean): void;
438
- get isDebug(): boolean;
439
- get isDisabled(): boolean;
440
- private buildPayload;
441
- protected addPendingPromise<T>(promise: Promise<T>): Promise<T>;
442
- /***
443
- *** TRACKING
444
- ***/
445
- protected identifyStateless(distinctId: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
446
- protected captureStateless(distinctId: string, event: string, properties?: {
447
- [key: string]: any;
448
- }, options?: PostHogCaptureOptions): void;
449
- protected aliasStateless(alias: string, distinctId: string, properties?: {
450
- [key: string]: any;
451
- }, options?: PostHogCaptureOptions): void;
452
- /***
453
- *** GROUPS
454
- ***/
455
- protected groupIdentifyStateless(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PostHogCaptureOptions, distinctId?: string, eventProperties?: PostHogEventProperties): void;
456
- protected getRemoteConfig(): Promise<PostHogRemoteConfig | undefined>;
457
- /***
458
- *** FEATURE FLAGS
459
- ***/
460
- protected getDecide(distinctId: string, groups?: Record<string, string | number>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, extraPayload?: Record<string, any>): Promise<PostHogDecideResponse | undefined>;
461
- protected getFeatureFlagStateless(key: string, distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, disableGeoip?: boolean): Promise<{
462
- response: FeatureFlagValue | undefined;
463
- requestId: string | undefined;
464
- }>;
465
- protected getFeatureFlagDetailStateless(key: string, distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, disableGeoip?: boolean): Promise<{
466
- response: FeatureFlagDetail | undefined;
467
- requestId: string | undefined;
468
- } | undefined>;
469
- protected getFeatureFlagPayloadStateless(key: string, distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, disableGeoip?: boolean): Promise<JsonType | undefined>;
470
- protected getFeatureFlagPayloadsStateless(distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, disableGeoip?: boolean, flagKeysToEvaluate?: string[]): Promise<PostHogDecideResponse['featureFlagPayloads'] | undefined>;
471
- protected getFeatureFlagsStateless(distinctId: string, groups?: Record<string, string | number>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, disableGeoip?: boolean, flagKeysToEvaluate?: string[]): Promise<{
472
- flags: PostHogDecideResponse['featureFlags'] | undefined;
473
- payloads: PostHogDecideResponse['featureFlagPayloads'] | undefined;
474
- requestId: PostHogDecideResponse['requestId'] | undefined;
475
- }>;
476
- protected getFeatureFlagsAndPayloadsStateless(distinctId: string, groups?: Record<string, string | number>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, disableGeoip?: boolean, flagKeysToEvaluate?: string[]): Promise<{
477
- flags: PostHogDecideResponse['featureFlags'] | undefined;
478
- payloads: PostHogDecideResponse['featureFlagPayloads'] | undefined;
479
- requestId: PostHogDecideResponse['requestId'] | undefined;
480
- }>;
481
- protected getFeatureFlagDetailsStateless(distinctId: string, groups?: Record<string, string | number>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, disableGeoip?: boolean, flagKeysToEvaluate?: string[]): Promise<PostHogFeatureFlagDetails | undefined>;
482
- /***
483
- *** SURVEYS
484
- ***/
485
- getSurveysStateless(): Promise<SurveyResponse['surveys']>;
486
- /***
487
- *** QUEUEING AND FLUSHING
488
- ***/
489
- protected enqueue(type: string, _message: any, options?: PostHogCaptureOptions): void;
490
- private clearFlushTimer;
491
- /**
492
- * Helper for flushing the queue in the background
493
- * Avoids unnecessary promise errors
494
- */
495
- private flushBackground;
496
- flush(): Promise<any[]>;
497
- protected getCustomHeaders(): {
498
- [key: string]: string;
499
- };
500
- private _flush;
501
- private fetchWithRetry;
502
- shutdown(shutdownTimeoutMs?: number): Promise<void>;
503
- }
504
- declare abstract class PostHogCore extends PostHogCoreStateless {
505
- private sendFeatureFlagEvent;
506
- private flagCallReported;
507
- protected _decideResponsePromise?: Promise<PostHogDecideResponse | undefined>;
508
- protected _sessionExpirationTimeSeconds: number;
509
- protected sessionProps: PostHogEventProperties;
510
- constructor(apiKey: string, options?: PostHogCoreOptions);
511
- protected setupBootstrap(options?: Partial<PostHogCoreOptions>): void;
512
- private get props();
513
- private set props(value);
514
- private clearProps;
515
- private _props;
516
- on(event: string, cb: (...args: any[]) => void): () => void;
517
- reset(propertiesToKeep?: PostHogPersistedProperty[]): void;
518
- protected getCommonEventProperties(): any;
519
- private enrichProperties;
520
- /**
521
- * * @returns {string} The stored session ID for the current session. This may be an empty string if the client is not yet fully initialized.
522
- */
523
- getSessionId(): string;
524
- resetSessionId(): void;
525
- /**
526
- * * @returns {string} The stored anonymous ID. This may be an empty string if the client is not yet fully initialized.
527
- */
528
- getAnonymousId(): string;
529
- /**
530
- * * @returns {string} The stored distinct ID. This may be an empty string if the client is not yet fully initialized.
531
- */
532
- getDistinctId(): string;
533
- unregister(property: string): Promise<void>;
534
- register(properties: {
535
- [key: string]: any;
536
- }): Promise<void>;
537
- registerForSession(properties: {
538
- [key: string]: any;
539
- }): void;
540
- unregisterForSession(property: string): void;
541
- /***
542
- *** TRACKING
543
- ***/
544
- identify(distinctId?: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
545
- capture(event: string, properties?: {
546
- [key: string]: any;
547
- }, options?: PostHogCaptureOptions): void;
548
- alias(alias: string): void;
549
- autocapture(eventType: string, elements: PostHogAutocaptureElement[], properties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
550
- /***
551
- *** GROUPS
552
- ***/
553
- groups(groups: {
554
- [type: string]: string | number;
555
- }): void;
556
- group(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
557
- groupIdentify(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
558
- /***
559
- * PROPERTIES
560
- ***/
561
- setPersonPropertiesForFlags(properties: {
562
- [type: string]: string;
563
- }): void;
564
- resetPersonPropertiesForFlags(): void;
565
- /** @deprecated - Renamed to setPersonPropertiesForFlags */
566
- personProperties(properties: {
567
- [type: string]: string;
568
- }): void;
569
- setGroupPropertiesForFlags(properties: {
570
- [type: string]: Record<string, string>;
571
- }): void;
572
- resetGroupPropertiesForFlags(): void;
573
- /** @deprecated - Renamed to setGroupPropertiesForFlags */
574
- groupProperties(properties: {
575
- [type: string]: Record<string, string>;
576
- }): void;
577
- private remoteConfigAsync;
578
- /***
579
- *** FEATURE FLAGS
580
- ***/
581
- private decideAsync;
582
- private cacheSessionReplay;
583
- private _remoteConfigAsync;
584
- private _decideAsync;
585
- private setKnownFeatureFlagDetails;
586
- private getKnownFeatureFlagDetails;
587
- private getKnownFeatureFlags;
588
- private getKnownFeatureFlagPayloads;
589
- private getBootstrappedFeatureFlagDetails;
590
- private setBootstrappedFeatureFlagDetails;
591
- private getBootstrappedFeatureFlags;
592
- private getBootstrappedFeatureFlagPayloads;
593
- getFeatureFlag(key: string): FeatureFlagValue | undefined;
594
- getFeatureFlagPayload(key: string): JsonType | undefined;
595
- getFeatureFlagPayloads(): PostHogDecideResponse['featureFlagPayloads'] | undefined;
596
- getFeatureFlags(): PostHogDecideResponse['featureFlags'] | undefined;
597
- getFeatureFlagDetails(): PostHogFeatureFlagDetails | undefined;
598
- getFeatureFlagsAndPayloads(): {
599
- flags: PostHogDecideResponse['featureFlags'] | undefined;
600
- payloads: PostHogDecideResponse['featureFlagPayloads'] | undefined;
601
- };
602
- isFeatureEnabled(key: string): boolean | undefined;
603
- reloadFeatureFlags(cb?: (err?: Error, flags?: PostHogDecideResponse['featureFlags']) => void): void;
604
- reloadRemoteConfigAsync(): Promise<PostHogRemoteConfig | undefined>;
605
- reloadFeatureFlagsAsync(sendAnonDistinctId?: boolean): Promise<PostHogDecideResponse['featureFlags'] | undefined>;
606
- onFeatureFlags(cb: (flags: PostHogDecideResponse['featureFlags']) => void): () => void;
607
- onFeatureFlag(key: string, cb: (value: FeatureFlagValue) => void): () => void;
608
- overrideFeatureFlag(flags: PostHogDecideResponse['featureFlags'] | null): Promise<void>;
609
- /***
610
- *** ERROR TRACKING
611
- ***/
612
- captureException(error: unknown, additionalProperties?: {
613
- [key: string]: any;
614
- }): void;
615
- /**
616
- * Capture written user feedback for a LLM trace. Numeric values are converted to strings.
617
- * @param traceId The trace ID to capture feedback for.
618
- * @param userFeedback The feedback to capture.
619
- */
620
- captureTraceFeedback(traceId: string | number, userFeedback: string): void;
621
- /**
622
- * Capture a metric for a LLM trace. Numeric values are converted to strings.
623
- * @param traceId The trace ID to capture the metric for.
624
- * @param metricName The name of the metric to capture.
625
- * @param metricValue The value of the metric to capture.
626
- */
627
- captureTraceMetric(traceId: string | number, metricName: string, metricValue: string | number | boolean): void;
397
+ declare abstract class PostHogCoreStateless {
398
+ readonly apiKey: string;
399
+ readonly host: string;
400
+ readonly flushAt: number;
401
+ readonly preloadFeatureFlags: boolean;
402
+ readonly disableSurveys: boolean;
403
+ private maxBatchSize;
404
+ private maxQueueSize;
405
+ private flushInterval;
406
+ private flushPromise;
407
+ private shutdownPromise;
408
+ private requestTimeout;
409
+ private featureFlagsRequestTimeoutMs;
410
+ private remoteConfigRequestTimeoutMs;
411
+ private captureMode;
412
+ private removeDebugCallback?;
413
+ private disableGeoip;
414
+ private historicalMigration;
415
+ protected disabled: boolean;
416
+ private defaultOptIn;
417
+ private pendingPromises;
418
+ protected _events: SimpleEventEmitter;
419
+ protected _flushTimer?: any;
420
+ protected _retryOptions: RetriableOptions;
421
+ protected _initPromise: Promise<void>;
422
+ protected _isInitialized: boolean;
423
+ protected _remoteConfigResponsePromise?: Promise<PostHogRemoteConfig | undefined>;
424
+ abstract fetch(url: string, options: PostHogFetchOptions): Promise<PostHogFetchResponse>;
425
+ abstract getLibraryId(): string;
426
+ abstract getLibraryVersion(): string;
427
+ abstract getCustomUserAgent(): string | void;
428
+ abstract getPersistedProperty<T>(key: PostHogPersistedProperty): T | undefined;
429
+ abstract setPersistedProperty<T>(key: PostHogPersistedProperty, value: T | null): void;
430
+ constructor(apiKey: string, options?: PostHogCoreOptions);
431
+ protected logMsgIfDebug(fn: () => void): void;
432
+ protected wrap(fn: () => void): void;
433
+ protected getCommonEventProperties(): any;
434
+ get optedOut(): boolean;
435
+ optIn(): Promise<void>;
436
+ optOut(): Promise<void>;
437
+ on(event: string, cb: (...args: any[]) => void): () => void;
438
+ debug(enabled?: boolean): void;
439
+ get isDebug(): boolean;
440
+ get isDisabled(): boolean;
441
+ private buildPayload;
442
+ protected addPendingPromise<T>(promise: Promise<T>): Promise<T>;
443
+ /***
444
+ *** TRACKING
445
+ ***/
446
+ protected identifyStateless(distinctId: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
447
+ protected identifyStatelessImmediate(distinctId: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions): Promise<void>;
448
+ protected captureStateless(distinctId: string, event: string, properties?: {
449
+ [key: string]: any;
450
+ }, options?: PostHogCaptureOptions): void;
451
+ protected captureStatelessImmediate(distinctId: string, event: string, properties?: {
452
+ [key: string]: any;
453
+ }, options?: PostHogCaptureOptions): Promise<void>;
454
+ protected aliasStateless(alias: string, distinctId: string, properties?: {
455
+ [key: string]: any;
456
+ }, options?: PostHogCaptureOptions): void;
457
+ protected aliasStatelessImmediate(alias: string, distinctId: string, properties?: {
458
+ [key: string]: any;
459
+ }, options?: PostHogCaptureOptions): Promise<void>;
460
+ /***
461
+ *** GROUPS
462
+ ***/
463
+ protected groupIdentifyStateless(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PostHogCaptureOptions, distinctId?: string, eventProperties?: PostHogEventProperties): void;
464
+ protected getRemoteConfig(): Promise<PostHogRemoteConfig | undefined>;
465
+ /***
466
+ *** FEATURE FLAGS
467
+ ***/
468
+ protected getDecide(distinctId: string, groups?: Record<string, string | number>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, extraPayload?: Record<string, any>): Promise<PostHogDecideResponse | undefined>;
469
+ protected getFeatureFlagStateless(key: string, distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, disableGeoip?: boolean): Promise<{
470
+ response: FeatureFlagValue | undefined;
471
+ requestId: string | undefined;
472
+ }>;
473
+ protected getFeatureFlagDetailStateless(key: string, distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, disableGeoip?: boolean): Promise<{
474
+ response: FeatureFlagDetail | undefined;
475
+ requestId: string | undefined;
476
+ } | undefined>;
477
+ protected getFeatureFlagPayloadStateless(key: string, distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, disableGeoip?: boolean): Promise<JsonType | undefined>;
478
+ protected getFeatureFlagPayloadsStateless(distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, disableGeoip?: boolean, flagKeysToEvaluate?: string[]): Promise<PostHogDecideResponse['featureFlagPayloads'] | undefined>;
479
+ protected getFeatureFlagsStateless(distinctId: string, groups?: Record<string, string | number>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, disableGeoip?: boolean, flagKeysToEvaluate?: string[]): Promise<{
480
+ flags: PostHogDecideResponse['featureFlags'] | undefined;
481
+ payloads: PostHogDecideResponse['featureFlagPayloads'] | undefined;
482
+ requestId: PostHogDecideResponse['requestId'] | undefined;
483
+ }>;
484
+ protected getFeatureFlagsAndPayloadsStateless(distinctId: string, groups?: Record<string, string | number>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, disableGeoip?: boolean, flagKeysToEvaluate?: string[]): Promise<{
485
+ flags: PostHogDecideResponse['featureFlags'] | undefined;
486
+ payloads: PostHogDecideResponse['featureFlagPayloads'] | undefined;
487
+ requestId: PostHogDecideResponse['requestId'] | undefined;
488
+ }>;
489
+ protected getFeatureFlagDetailsStateless(distinctId: string, groups?: Record<string, string | number>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, disableGeoip?: boolean, flagKeysToEvaluate?: string[]): Promise<PostHogFeatureFlagDetails | undefined>;
490
+ /***
491
+ *** SURVEYS
492
+ ***/
493
+ getSurveysStateless(): Promise<SurveyResponse['surveys']>;
494
+ /***
495
+ *** SUPER PROPERTIES
496
+ ***/
497
+ private _props;
498
+ protected get props(): PostHogEventProperties;
499
+ protected set props(val: PostHogEventProperties | undefined);
500
+ register(properties: {
501
+ [key: string]: any;
502
+ }): Promise<void>;
503
+ unregister(property: string): Promise<void>;
504
+ /***
505
+ *** QUEUEING AND FLUSHING
506
+ ***/
507
+ protected enqueue(type: string, _message: any, options?: PostHogCaptureOptions): void;
508
+ protected sendImmediate(type: string, _message: any, options?: PostHogCaptureOptions): Promise<void>;
509
+ private prepareMessage;
510
+ private clearFlushTimer;
511
+ /**
512
+ * Helper for flushing the queue in the background
513
+ * Avoids unnecessary promise errors
514
+ */
515
+ private flushBackground;
516
+ flush(): Promise<any[]>;
517
+ protected getCustomHeaders(): {
518
+ [key: string]: string;
519
+ };
520
+ private _flush;
521
+ private fetchWithRetry;
522
+ _shutdown(shutdownTimeoutMs?: number): Promise<void>;
523
+ /**
524
+ * Call shutdown() once before the node process exits, so ensure that all events have been sent and all promises
525
+ * have resolved. Do not use this function if you intend to keep using this PostHog instance after calling it.
526
+ * @param shutdownTimeoutMs
527
+ */
528
+ shutdown(shutdownTimeoutMs?: number): Promise<void>;
529
+ }
530
+ declare abstract class PostHogCore extends PostHogCoreStateless {
531
+ private sendFeatureFlagEvent;
532
+ private flagCallReported;
533
+ protected _decideResponsePromise?: Promise<PostHogDecideResponse | undefined>;
534
+ protected _sessionExpirationTimeSeconds: number;
535
+ protected sessionProps: PostHogEventProperties;
536
+ constructor(apiKey: string, options?: PostHogCoreOptions);
537
+ protected setupBootstrap(options?: Partial<PostHogCoreOptions>): void;
538
+ private clearProps;
539
+ on(event: string, cb: (...args: any[]) => void): () => void;
540
+ reset(propertiesToKeep?: PostHogPersistedProperty[]): void;
541
+ protected getCommonEventProperties(): any;
542
+ private enrichProperties;
543
+ /**
544
+ * * @returns {string} The stored session ID for the current session. This may be an empty string if the client is not yet fully initialized.
545
+ */
546
+ getSessionId(): string;
547
+ resetSessionId(): void;
548
+ /**
549
+ * * @returns {string} The stored anonymous ID. This may be an empty string if the client is not yet fully initialized.
550
+ */
551
+ getAnonymousId(): string;
552
+ /**
553
+ * * @returns {string} The stored distinct ID. This may be an empty string if the client is not yet fully initialized.
554
+ */
555
+ getDistinctId(): string;
556
+ registerForSession(properties: {
557
+ [key: string]: any;
558
+ }): void;
559
+ unregisterForSession(property: string): void;
560
+ /***
561
+ *** TRACKING
562
+ ***/
563
+ identify(distinctId?: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
564
+ capture(event: string, properties?: {
565
+ [key: string]: any;
566
+ }, options?: PostHogCaptureOptions): void;
567
+ alias(alias: string): void;
568
+ autocapture(eventType: string, elements: PostHogAutocaptureElement[], properties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
569
+ /***
570
+ *** GROUPS
571
+ ***/
572
+ groups(groups: {
573
+ [type: string]: string | number;
574
+ }): void;
575
+ group(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
576
+ groupIdentify(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
577
+ /***
578
+ * PROPERTIES
579
+ ***/
580
+ setPersonPropertiesForFlags(properties: {
581
+ [type: string]: string;
582
+ }): void;
583
+ resetPersonPropertiesForFlags(): void;
584
+ /** @deprecated - Renamed to setPersonPropertiesForFlags */
585
+ personProperties(properties: {
586
+ [type: string]: string;
587
+ }): void;
588
+ setGroupPropertiesForFlags(properties: {
589
+ [type: string]: Record<string, string>;
590
+ }): void;
591
+ resetGroupPropertiesForFlags(): void;
592
+ /** @deprecated - Renamed to setGroupPropertiesForFlags */
593
+ groupProperties(properties: {
594
+ [type: string]: Record<string, string>;
595
+ }): void;
596
+ private remoteConfigAsync;
597
+ /***
598
+ *** FEATURE FLAGS
599
+ ***/
600
+ private decideAsync;
601
+ private cacheSessionReplay;
602
+ private _remoteConfigAsync;
603
+ private _decideAsync;
604
+ private setKnownFeatureFlagDetails;
605
+ private getKnownFeatureFlagDetails;
606
+ private getKnownFeatureFlags;
607
+ private getKnownFeatureFlagPayloads;
608
+ private getBootstrappedFeatureFlagDetails;
609
+ private setBootstrappedFeatureFlagDetails;
610
+ private getBootstrappedFeatureFlags;
611
+ private getBootstrappedFeatureFlagPayloads;
612
+ getFeatureFlag(key: string): FeatureFlagValue | undefined;
613
+ getFeatureFlagPayload(key: string): JsonType | undefined;
614
+ getFeatureFlagPayloads(): PostHogDecideResponse['featureFlagPayloads'] | undefined;
615
+ getFeatureFlags(): PostHogDecideResponse['featureFlags'] | undefined;
616
+ getFeatureFlagDetails(): PostHogFeatureFlagDetails | undefined;
617
+ getFeatureFlagsAndPayloads(): {
618
+ flags: PostHogDecideResponse['featureFlags'] | undefined;
619
+ payloads: PostHogDecideResponse['featureFlagPayloads'] | undefined;
620
+ };
621
+ isFeatureEnabled(key: string): boolean | undefined;
622
+ reloadFeatureFlags(cb?: (err?: Error, flags?: PostHogDecideResponse['featureFlags']) => void): void;
623
+ reloadRemoteConfigAsync(): Promise<PostHogRemoteConfig | undefined>;
624
+ reloadFeatureFlagsAsync(sendAnonDistinctId?: boolean): Promise<PostHogDecideResponse['featureFlags'] | undefined>;
625
+ onFeatureFlags(cb: (flags: PostHogDecideResponse['featureFlags']) => void): () => void;
626
+ onFeatureFlag(key: string, cb: (value: FeatureFlagValue) => void): () => void;
627
+ overrideFeatureFlag(flags: PostHogDecideResponse['featureFlags'] | null): Promise<void>;
628
+ /***
629
+ *** ERROR TRACKING
630
+ ***/
631
+ captureException(error: unknown, additionalProperties?: {
632
+ [key: string]: any;
633
+ }): void;
634
+ /**
635
+ * Capture written user feedback for a LLM trace. Numeric values are converted to strings.
636
+ * @param traceId The trace ID to capture feedback for.
637
+ * @param userFeedback The feedback to capture.
638
+ */
639
+ captureTraceFeedback(traceId: string | number, userFeedback: string): void;
640
+ /**
641
+ * Capture a metric for a LLM trace. Numeric values are converted to strings.
642
+ * @param traceId The trace ID to capture the metric for.
643
+ * @param metricName The name of the metric to capture.
644
+ * @param metricValue The value of the metric to capture.
645
+ */
646
+ captureTraceMetric(traceId: string | number, metricName: string, metricValue: string | number | boolean): void;
628
647
  }
629
648
 
630
- type PostHogOptions = {
631
- autocapture?: boolean;
632
- persistence?: 'localStorage' | 'sessionStorage' | 'cookie' | 'memory';
633
- persistence_name?: string;
634
- captureHistoryEvents?: boolean;
649
+ type PostHogOptions = {
650
+ autocapture?: boolean;
651
+ persistence?: 'localStorage' | 'sessionStorage' | 'cookie' | 'memory';
652
+ persistence_name?: string;
653
+ captureHistoryEvents?: boolean;
635
654
  } & PostHogCoreOptions;
636
655
 
637
- declare class PostHog extends PostHogCore {
638
- private _storage;
639
- private _storageCache;
640
- private _storageKey;
641
- private _lastPathname;
642
- constructor(apiKey: string, options?: PostHogOptions);
643
- private getWindow;
644
- getPersistedProperty<T>(key: PostHogPersistedProperty): T | undefined;
645
- setPersistedProperty<T>(key: PostHogPersistedProperty, value: T | null): void;
646
- fetch(url: string, options: PostHogFetchOptions): Promise<PostHogFetchResponse>;
647
- getLibraryId(): string;
648
- getLibraryVersion(): string;
649
- getCustomUserAgent(): void;
650
- getCommonEventProperties(): any;
651
- private setupHistoryEventTracking;
652
- private captureNavigationEvent;
656
+ declare class PostHog extends PostHogCore {
657
+ private _storage;
658
+ private _storageCache;
659
+ private _storageKey;
660
+ private _lastPathname;
661
+ constructor(apiKey: string, options?: PostHogOptions);
662
+ private getWindow;
663
+ getPersistedProperty<T>(key: PostHogPersistedProperty): T | undefined;
664
+ setPersistedProperty<T>(key: PostHogPersistedProperty, value: T | null): void;
665
+ fetch(url: string, options: PostHogFetchOptions): Promise<PostHogFetchResponse>;
666
+ getLibraryId(): string;
667
+ getLibraryVersion(): string;
668
+ getCustomUserAgent(): void;
669
+ getCommonEventProperties(): any;
670
+ private setupHistoryEventTracking;
671
+ private captureNavigationEvent;
653
672
  }
654
673
 
655
674
  export { PostHog, PostHog as default };