posthog-js-lite 3.5.0 → 3.6.0

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