posthog-js-lite 4.1.0 → 4.1.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/LICENSE +245 -0
- package/README.md +2 -1
- package/dist/index.cjs +459 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.mjs +454 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +26 -9
- package/CHANGELOG.md +0 -187
- package/index.ts +0 -5
- package/lib/index.cjs +0 -2641
- package/lib/index.cjs.map +0 -1
- package/lib/index.d.ts +0 -681
- package/lib/index.mjs +0 -2636
- package/lib/index.mjs.map +0 -1
- package/src/context.ts +0 -170
- package/src/patch.ts +0 -50
- package/src/posthog-web.ts +0 -141
- package/src/storage.ts +0 -168
- package/src/types.ts +0 -8
- package/test/posthog-web.spec.ts +0 -289
- package/tsconfig.json +0 -7
package/lib/index.d.ts
DELETED
|
@@ -1,681 +0,0 @@
|
|
|
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 disable GZIP compression */
|
|
54
|
-
disableCompression?: boolean;
|
|
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
|
-
SurveyLastSeenDate = "survey_last_seen_date",
|
|
81
|
-
SurveysSeen = "surveys_seen",
|
|
82
|
-
Surveys = "surveys",
|
|
83
|
-
RemoteConfig = "remote_config",
|
|
84
|
-
FlagsEndpointWasHit = "flags_endpoint_was_hit"
|
|
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 | Blob;
|
|
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
|
-
declare enum Compression {
|
|
123
|
-
GZipJS = "gzip-js",
|
|
124
|
-
Base64 = "base64"
|
|
125
|
-
}
|
|
126
|
-
type PostHogRemoteConfig = {
|
|
127
|
-
sessionRecording?: boolean | {
|
|
128
|
-
[key: string]: JsonType;
|
|
129
|
-
};
|
|
130
|
-
/**
|
|
131
|
-
* Supported compression algorithms
|
|
132
|
-
*/
|
|
133
|
-
supportedCompression?: Compression[];
|
|
134
|
-
/**
|
|
135
|
-
* Whether surveys are enabled
|
|
136
|
-
*/
|
|
137
|
-
surveys?: boolean | Survey[];
|
|
138
|
-
/**
|
|
139
|
-
* Indicates if the team has any flags enabled (if not we don't need to load them)
|
|
140
|
-
*/
|
|
141
|
-
hasFeatureFlags?: boolean;
|
|
142
|
-
};
|
|
143
|
-
type FeatureFlagValue = string | boolean;
|
|
144
|
-
type PostHogFlagsResponse = Omit<PostHogRemoteConfig, 'surveys' | 'hasFeatureFlags'> & {
|
|
145
|
-
featureFlags: {
|
|
146
|
-
[key: string]: FeatureFlagValue;
|
|
147
|
-
};
|
|
148
|
-
featureFlagPayloads: {
|
|
149
|
-
[key: string]: JsonType;
|
|
150
|
-
};
|
|
151
|
-
flags: {
|
|
152
|
-
[key: string]: FeatureFlagDetail;
|
|
153
|
-
};
|
|
154
|
-
errorsWhileComputingFlags: boolean;
|
|
155
|
-
sessionRecording?: boolean | {
|
|
156
|
-
[key: string]: JsonType;
|
|
157
|
-
};
|
|
158
|
-
quotaLimited?: string[];
|
|
159
|
-
requestId?: string;
|
|
160
|
-
};
|
|
161
|
-
/**
|
|
162
|
-
* Creates a type with all properties of T, but makes only K properties required while the rest remain optional.
|
|
163
|
-
*
|
|
164
|
-
* @template T - The base type containing all properties
|
|
165
|
-
* @template K - Union type of keys from T that should be required
|
|
166
|
-
*
|
|
167
|
-
* @example
|
|
168
|
-
* interface User {
|
|
169
|
-
* id: number;
|
|
170
|
-
* name: string;
|
|
171
|
-
* email?: string;
|
|
172
|
-
* age?: number;
|
|
173
|
-
* }
|
|
174
|
-
*
|
|
175
|
-
* // Makes 'id' and 'name' required, but 'email' and 'age' optional
|
|
176
|
-
* type RequiredUser = PartialWithRequired<User, 'id' | 'name'>;
|
|
177
|
-
*
|
|
178
|
-
* const user: RequiredUser = {
|
|
179
|
-
* id: 1, // Must be provided
|
|
180
|
-
* name: "John" // Must be provided
|
|
181
|
-
* // email and age are optional
|
|
182
|
-
* };
|
|
183
|
-
*/
|
|
184
|
-
type PartialWithRequired<T, K extends keyof T> = {
|
|
185
|
-
[P in K]: T[P];
|
|
186
|
-
} & {
|
|
187
|
-
[P in Exclude<keyof T, K>]?: T[P];
|
|
188
|
-
};
|
|
189
|
-
/**
|
|
190
|
-
* These are the fields we care about from PostHogFlagsResponse for feature flags.
|
|
191
|
-
*/
|
|
192
|
-
type PostHogFeatureFlagDetails = PartialWithRequired<PostHogFlagsResponse, 'flags' | 'featureFlags' | 'featureFlagPayloads' | 'requestId'>;
|
|
193
|
-
type JsonType = string | number | boolean | null | {
|
|
194
|
-
[key: string]: JsonType;
|
|
195
|
-
} | Array<JsonType> | JsonType[];
|
|
196
|
-
type FeatureFlagDetail = {
|
|
197
|
-
key: string;
|
|
198
|
-
enabled: boolean;
|
|
199
|
-
variant: string | undefined;
|
|
200
|
-
reason: EvaluationReason | undefined;
|
|
201
|
-
metadata: FeatureFlagMetadata | undefined;
|
|
202
|
-
};
|
|
203
|
-
type FeatureFlagMetadata = {
|
|
204
|
-
id: number | undefined;
|
|
205
|
-
version: number | undefined;
|
|
206
|
-
description: string | undefined;
|
|
207
|
-
payload: string | undefined;
|
|
208
|
-
};
|
|
209
|
-
type EvaluationReason = {
|
|
210
|
-
code: string | undefined;
|
|
211
|
-
condition_index: number | undefined;
|
|
212
|
-
description: string | undefined;
|
|
213
|
-
};
|
|
214
|
-
type SurveyAppearance = {
|
|
215
|
-
backgroundColor?: string;
|
|
216
|
-
submitButtonColor?: string;
|
|
217
|
-
submitButtonText?: string;
|
|
218
|
-
submitButtonTextColor?: string;
|
|
219
|
-
ratingButtonColor?: string;
|
|
220
|
-
ratingButtonActiveColor?: string;
|
|
221
|
-
autoDisappear?: boolean;
|
|
222
|
-
displayThankYouMessage?: boolean;
|
|
223
|
-
thankYouMessageHeader?: string;
|
|
224
|
-
thankYouMessageDescription?: string;
|
|
225
|
-
thankYouMessageDescriptionContentType?: SurveyQuestionDescriptionContentType;
|
|
226
|
-
thankYouMessageCloseButtonText?: string;
|
|
227
|
-
borderColor?: string;
|
|
228
|
-
position?: SurveyPosition;
|
|
229
|
-
placeholder?: string;
|
|
230
|
-
shuffleQuestions?: boolean;
|
|
231
|
-
surveyPopupDelaySeconds?: number;
|
|
232
|
-
widgetType?: SurveyWidgetType;
|
|
233
|
-
widgetSelector?: string;
|
|
234
|
-
widgetLabel?: string;
|
|
235
|
-
widgetColor?: string;
|
|
236
|
-
};
|
|
237
|
-
declare enum SurveyPosition {
|
|
238
|
-
Left = "left",
|
|
239
|
-
Right = "right",
|
|
240
|
-
Center = "center"
|
|
241
|
-
}
|
|
242
|
-
declare enum SurveyWidgetType {
|
|
243
|
-
Button = "button",
|
|
244
|
-
Tab = "tab",
|
|
245
|
-
Selector = "selector"
|
|
246
|
-
}
|
|
247
|
-
declare enum SurveyType {
|
|
248
|
-
Popover = "popover",
|
|
249
|
-
API = "api",
|
|
250
|
-
Widget = "widget"
|
|
251
|
-
}
|
|
252
|
-
type SurveyQuestion = BasicSurveyQuestion | LinkSurveyQuestion | RatingSurveyQuestion | MultipleSurveyQuestion;
|
|
253
|
-
declare enum SurveyQuestionDescriptionContentType {
|
|
254
|
-
Html = "html",
|
|
255
|
-
Text = "text"
|
|
256
|
-
}
|
|
257
|
-
type SurveyQuestionBase = {
|
|
258
|
-
question: string;
|
|
259
|
-
id?: string;
|
|
260
|
-
description?: string;
|
|
261
|
-
descriptionContentType?: SurveyQuestionDescriptionContentType;
|
|
262
|
-
optional?: boolean;
|
|
263
|
-
buttonText?: string;
|
|
264
|
-
originalQuestionIndex: number;
|
|
265
|
-
branching?: NextQuestionBranching | EndBranching | ResponseBasedBranching | SpecificQuestionBranching;
|
|
266
|
-
};
|
|
267
|
-
type BasicSurveyQuestion = SurveyQuestionBase & {
|
|
268
|
-
type: SurveyQuestionType.Open;
|
|
269
|
-
};
|
|
270
|
-
type LinkSurveyQuestion = SurveyQuestionBase & {
|
|
271
|
-
type: SurveyQuestionType.Link;
|
|
272
|
-
link?: string;
|
|
273
|
-
};
|
|
274
|
-
type RatingSurveyQuestion = SurveyQuestionBase & {
|
|
275
|
-
type: SurveyQuestionType.Rating;
|
|
276
|
-
display: SurveyRatingDisplay;
|
|
277
|
-
scale: 3 | 5 | 7 | 10;
|
|
278
|
-
lowerBoundLabel: string;
|
|
279
|
-
upperBoundLabel: string;
|
|
280
|
-
};
|
|
281
|
-
declare enum SurveyRatingDisplay {
|
|
282
|
-
Number = "number",
|
|
283
|
-
Emoji = "emoji"
|
|
284
|
-
}
|
|
285
|
-
type MultipleSurveyQuestion = SurveyQuestionBase & {
|
|
286
|
-
type: SurveyQuestionType.SingleChoice | SurveyQuestionType.MultipleChoice;
|
|
287
|
-
choices: string[];
|
|
288
|
-
hasOpenChoice?: boolean;
|
|
289
|
-
shuffleOptions?: boolean;
|
|
290
|
-
};
|
|
291
|
-
declare enum SurveyQuestionType {
|
|
292
|
-
Open = "open",
|
|
293
|
-
MultipleChoice = "multiple_choice",
|
|
294
|
-
SingleChoice = "single_choice",
|
|
295
|
-
Rating = "rating",
|
|
296
|
-
Link = "link"
|
|
297
|
-
}
|
|
298
|
-
declare enum SurveyQuestionBranchingType {
|
|
299
|
-
NextQuestion = "next_question",
|
|
300
|
-
End = "end",
|
|
301
|
-
ResponseBased = "response_based",
|
|
302
|
-
SpecificQuestion = "specific_question"
|
|
303
|
-
}
|
|
304
|
-
type NextQuestionBranching = {
|
|
305
|
-
type: SurveyQuestionBranchingType.NextQuestion;
|
|
306
|
-
};
|
|
307
|
-
type EndBranching = {
|
|
308
|
-
type: SurveyQuestionBranchingType.End;
|
|
309
|
-
};
|
|
310
|
-
type ResponseBasedBranching = {
|
|
311
|
-
type: SurveyQuestionBranchingType.ResponseBased;
|
|
312
|
-
responseValues: Record<string, any>;
|
|
313
|
-
};
|
|
314
|
-
type SpecificQuestionBranching = {
|
|
315
|
-
type: SurveyQuestionBranchingType.SpecificQuestion;
|
|
316
|
-
index: number;
|
|
317
|
-
};
|
|
318
|
-
type SurveyResponse = {
|
|
319
|
-
surveys: Survey[];
|
|
320
|
-
};
|
|
321
|
-
declare enum SurveyMatchType {
|
|
322
|
-
Regex = "regex",
|
|
323
|
-
NotRegex = "not_regex",
|
|
324
|
-
Exact = "exact",
|
|
325
|
-
IsNot = "is_not",
|
|
326
|
-
Icontains = "icontains",
|
|
327
|
-
NotIcontains = "not_icontains"
|
|
328
|
-
}
|
|
329
|
-
type Survey = {
|
|
330
|
-
id: string;
|
|
331
|
-
name: string;
|
|
332
|
-
description?: string;
|
|
333
|
-
type: SurveyType;
|
|
334
|
-
feature_flag_keys?: {
|
|
335
|
-
key: string;
|
|
336
|
-
value?: string;
|
|
337
|
-
}[];
|
|
338
|
-
linked_flag_key?: string;
|
|
339
|
-
targeting_flag_key?: string;
|
|
340
|
-
internal_targeting_flag_key?: string;
|
|
341
|
-
questions: SurveyQuestion[];
|
|
342
|
-
appearance?: SurveyAppearance;
|
|
343
|
-
conditions?: {
|
|
344
|
-
url?: string;
|
|
345
|
-
selector?: string;
|
|
346
|
-
seenSurveyWaitPeriodInDays?: number;
|
|
347
|
-
urlMatchType?: SurveyMatchType;
|
|
348
|
-
events?: {
|
|
349
|
-
repeatedActivation?: boolean;
|
|
350
|
-
values?: {
|
|
351
|
-
name: string;
|
|
352
|
-
}[];
|
|
353
|
-
};
|
|
354
|
-
actions?: {
|
|
355
|
-
values: SurveyActionType[];
|
|
356
|
-
};
|
|
357
|
-
deviceTypes?: string[];
|
|
358
|
-
deviceTypesMatchType?: SurveyMatchType;
|
|
359
|
-
};
|
|
360
|
-
start_date?: string;
|
|
361
|
-
end_date?: string;
|
|
362
|
-
current_iteration?: number;
|
|
363
|
-
current_iteration_start_date?: string;
|
|
364
|
-
};
|
|
365
|
-
type SurveyActionType = {
|
|
366
|
-
id: number;
|
|
367
|
-
name?: string;
|
|
368
|
-
steps?: ActionStepType[];
|
|
369
|
-
};
|
|
370
|
-
/** Sync with plugin-server/src/types.ts */
|
|
371
|
-
declare enum ActionStepStringMatching {
|
|
372
|
-
Contains = "contains",
|
|
373
|
-
Exact = "exact",
|
|
374
|
-
Regex = "regex"
|
|
375
|
-
}
|
|
376
|
-
type ActionStepType = {
|
|
377
|
-
event?: string;
|
|
378
|
-
selector?: string;
|
|
379
|
-
text?: string;
|
|
380
|
-
/** @default StringMatching.Exact */
|
|
381
|
-
text_matching?: ActionStepStringMatching;
|
|
382
|
-
href?: string;
|
|
383
|
-
/** @default ActionStepStringMatching.Exact */
|
|
384
|
-
href_matching?: ActionStepStringMatching;
|
|
385
|
-
url?: string;
|
|
386
|
-
/** @default StringMatching.Contains */
|
|
387
|
-
url_matching?: ActionStepStringMatching;
|
|
388
|
-
};
|
|
389
|
-
|
|
390
|
-
interface RetriableOptions {
|
|
391
|
-
retryCount: number;
|
|
392
|
-
retryDelay: number;
|
|
393
|
-
retryCheck: (err: unknown) => boolean;
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
declare class SimpleEventEmitter {
|
|
397
|
-
events: {
|
|
398
|
-
[key: string]: ((...args: any[]) => void)[];
|
|
399
|
-
};
|
|
400
|
-
constructor();
|
|
401
|
-
on(event: string, listener: (...args: any[]) => void): () => void;
|
|
402
|
-
emit(event: string, payload: any): void;
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
declare abstract class PostHogCoreStateless {
|
|
406
|
-
readonly apiKey: string;
|
|
407
|
-
readonly host: string;
|
|
408
|
-
readonly flushAt: number;
|
|
409
|
-
readonly preloadFeatureFlags: boolean;
|
|
410
|
-
readonly disableSurveys: boolean;
|
|
411
|
-
private maxBatchSize;
|
|
412
|
-
private maxQueueSize;
|
|
413
|
-
private flushInterval;
|
|
414
|
-
private flushPromise;
|
|
415
|
-
private shutdownPromise;
|
|
416
|
-
private requestTimeout;
|
|
417
|
-
private featureFlagsRequestTimeoutMs;
|
|
418
|
-
private remoteConfigRequestTimeoutMs;
|
|
419
|
-
private removeDebugCallback?;
|
|
420
|
-
private disableGeoip;
|
|
421
|
-
private historicalMigration;
|
|
422
|
-
protected disabled: boolean;
|
|
423
|
-
protected disableCompression: boolean;
|
|
424
|
-
private defaultOptIn;
|
|
425
|
-
private pendingPromises;
|
|
426
|
-
protected _events: SimpleEventEmitter;
|
|
427
|
-
protected _flushTimer?: any;
|
|
428
|
-
protected _retryOptions: RetriableOptions;
|
|
429
|
-
protected _initPromise: Promise<void>;
|
|
430
|
-
protected _isInitialized: boolean;
|
|
431
|
-
protected _remoteConfigResponsePromise?: Promise<PostHogRemoteConfig | undefined>;
|
|
432
|
-
abstract fetch(url: string, options: PostHogFetchOptions): Promise<PostHogFetchResponse>;
|
|
433
|
-
abstract getLibraryId(): string;
|
|
434
|
-
abstract getLibraryVersion(): string;
|
|
435
|
-
abstract getCustomUserAgent(): string | void;
|
|
436
|
-
abstract getPersistedProperty<T>(key: PostHogPersistedProperty): T | undefined;
|
|
437
|
-
abstract setPersistedProperty<T>(key: PostHogPersistedProperty, value: T | null): void;
|
|
438
|
-
constructor(apiKey: string, options?: PostHogCoreOptions);
|
|
439
|
-
protected logMsgIfDebug(fn: () => void): void;
|
|
440
|
-
protected wrap(fn: () => void): void;
|
|
441
|
-
protected getCommonEventProperties(): PostHogEventProperties;
|
|
442
|
-
get optedOut(): boolean;
|
|
443
|
-
optIn(): Promise<void>;
|
|
444
|
-
optOut(): Promise<void>;
|
|
445
|
-
on(event: string, cb: (...args: any[]) => void): () => void;
|
|
446
|
-
debug(enabled?: boolean): void;
|
|
447
|
-
get isDebug(): boolean;
|
|
448
|
-
get isDisabled(): boolean;
|
|
449
|
-
private buildPayload;
|
|
450
|
-
protected addPendingPromise<T>(promise: Promise<T>): Promise<T>;
|
|
451
|
-
/***
|
|
452
|
-
*** TRACKING
|
|
453
|
-
***/
|
|
454
|
-
protected identifyStateless(distinctId: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
|
|
455
|
-
protected identifyStatelessImmediate(distinctId: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions): Promise<void>;
|
|
456
|
-
protected captureStateless(distinctId: string, event: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
|
|
457
|
-
protected captureStatelessImmediate(distinctId: string, event: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions): Promise<void>;
|
|
458
|
-
protected aliasStateless(alias: string, distinctId: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
|
|
459
|
-
protected aliasStatelessImmediate(alias: string, distinctId: string, properties?: PostHogEventProperties, 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 getFlags(distinctId: string, groups?: Record<string, string | number>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, extraPayload?: Record<string, any>): Promise<PostHogFlagsResponse | 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<PostHogFlagsResponse['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: PostHogFlagsResponse['featureFlags'] | undefined;
|
|
481
|
-
payloads: PostHogFlagsResponse['featureFlagPayloads'] | undefined;
|
|
482
|
-
requestId: PostHogFlagsResponse['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: PostHogFlagsResponse['featureFlags'] | undefined;
|
|
486
|
-
payloads: PostHogFlagsResponse['featureFlagPayloads'] | undefined;
|
|
487
|
-
requestId: PostHogFlagsResponse['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: PostHogEventProperties): Promise<void>;
|
|
501
|
-
unregister(property: string): Promise<void>;
|
|
502
|
-
/***
|
|
503
|
-
*** QUEUEING AND FLUSHING
|
|
504
|
-
***/
|
|
505
|
-
protected enqueue(type: string, _message: any, options?: PostHogCaptureOptions): void;
|
|
506
|
-
protected sendImmediate(type: string, _message: any, options?: PostHogCaptureOptions): Promise<void>;
|
|
507
|
-
private prepareMessage;
|
|
508
|
-
private clearFlushTimer;
|
|
509
|
-
/**
|
|
510
|
-
* Helper for flushing the queue in the background
|
|
511
|
-
* Avoids unnecessary promise errors
|
|
512
|
-
*/
|
|
513
|
-
private flushBackground;
|
|
514
|
-
/**
|
|
515
|
-
* Flushes the queue
|
|
516
|
-
*
|
|
517
|
-
* This function will return a promise that will resolve when the flush is complete,
|
|
518
|
-
* or reject if there was an error (for example if the server or network is down).
|
|
519
|
-
*
|
|
520
|
-
* If there is already a flush in progress, this function will wait for that flush to complete.
|
|
521
|
-
*
|
|
522
|
-
* It's recommended to do error handling in the callback of the promise.
|
|
523
|
-
*
|
|
524
|
-
* @example
|
|
525
|
-
* posthog.flush().then(() => {
|
|
526
|
-
* console.log('Flush complete')
|
|
527
|
-
* }).catch((err) => {
|
|
528
|
-
* console.error('Flush failed', err)
|
|
529
|
-
* })
|
|
530
|
-
*
|
|
531
|
-
*
|
|
532
|
-
* @throws PostHogFetchHttpError
|
|
533
|
-
* @throws PostHogFetchNetworkError
|
|
534
|
-
* @throws Error
|
|
535
|
-
*/
|
|
536
|
-
flush(): Promise<void>;
|
|
537
|
-
protected getCustomHeaders(): {
|
|
538
|
-
[key: string]: string;
|
|
539
|
-
};
|
|
540
|
-
private _flush;
|
|
541
|
-
private fetchWithRetry;
|
|
542
|
-
_shutdown(shutdownTimeoutMs?: number): Promise<void>;
|
|
543
|
-
/**
|
|
544
|
-
* Call shutdown() once before the node process exits, so ensure that all events have been sent and all promises
|
|
545
|
-
* have resolved. Do not use this function if you intend to keep using this PostHog instance after calling it.
|
|
546
|
-
* @param shutdownTimeoutMs
|
|
547
|
-
*/
|
|
548
|
-
shutdown(shutdownTimeoutMs?: number): Promise<void>;
|
|
549
|
-
}
|
|
550
|
-
declare abstract class PostHogCore extends PostHogCoreStateless {
|
|
551
|
-
private sendFeatureFlagEvent;
|
|
552
|
-
private flagCallReported;
|
|
553
|
-
protected _flagsResponsePromise?: Promise<PostHogFlagsResponse | undefined>;
|
|
554
|
-
protected _sessionExpirationTimeSeconds: number;
|
|
555
|
-
private _sessionMaxLengthSeconds;
|
|
556
|
-
protected sessionProps: PostHogEventProperties;
|
|
557
|
-
constructor(apiKey: string, options?: PostHogCoreOptions);
|
|
558
|
-
protected setupBootstrap(options?: Partial<PostHogCoreOptions>): void;
|
|
559
|
-
private clearProps;
|
|
560
|
-
on(event: string, cb: (...args: any[]) => void): () => void;
|
|
561
|
-
reset(propertiesToKeep?: PostHogPersistedProperty[]): void;
|
|
562
|
-
protected getCommonEventProperties(): PostHogEventProperties;
|
|
563
|
-
private enrichProperties;
|
|
564
|
-
/**
|
|
565
|
-
* * @returns {string} The stored session ID for the current session. This may be an empty string if the client is not yet fully initialized.
|
|
566
|
-
*/
|
|
567
|
-
getSessionId(): string;
|
|
568
|
-
resetSessionId(): void;
|
|
569
|
-
/**
|
|
570
|
-
* * @returns {string} The stored anonymous ID. This may be an empty string if the client is not yet fully initialized.
|
|
571
|
-
*/
|
|
572
|
-
getAnonymousId(): string;
|
|
573
|
-
/**
|
|
574
|
-
* * @returns {string} The stored distinct ID. This may be an empty string if the client is not yet fully initialized.
|
|
575
|
-
*/
|
|
576
|
-
getDistinctId(): string;
|
|
577
|
-
registerForSession(properties: PostHogEventProperties): void;
|
|
578
|
-
unregisterForSession(property: string): void;
|
|
579
|
-
/***
|
|
580
|
-
*** TRACKING
|
|
581
|
-
***/
|
|
582
|
-
identify(distinctId?: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
|
|
583
|
-
capture(event: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
|
|
584
|
-
alias(alias: string): void;
|
|
585
|
-
autocapture(eventType: string, elements: PostHogAutocaptureElement[], properties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
|
|
586
|
-
/***
|
|
587
|
-
*** GROUPS
|
|
588
|
-
***/
|
|
589
|
-
groups(groups: PostHogGroupProperties): void;
|
|
590
|
-
group(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
|
|
591
|
-
groupIdentify(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
|
|
592
|
-
/***
|
|
593
|
-
* PROPERTIES
|
|
594
|
-
***/
|
|
595
|
-
setPersonPropertiesForFlags(properties: {
|
|
596
|
-
[type: string]: string;
|
|
597
|
-
}): void;
|
|
598
|
-
resetPersonPropertiesForFlags(): void;
|
|
599
|
-
setGroupPropertiesForFlags(properties: {
|
|
600
|
-
[type: string]: Record<string, string>;
|
|
601
|
-
}): void;
|
|
602
|
-
resetGroupPropertiesForFlags(): void;
|
|
603
|
-
private remoteConfigAsync;
|
|
604
|
-
/***
|
|
605
|
-
*** FEATURE FLAGS
|
|
606
|
-
***/
|
|
607
|
-
private flagsAsync;
|
|
608
|
-
private cacheSessionReplay;
|
|
609
|
-
private _remoteConfigAsync;
|
|
610
|
-
private _flagsAsync;
|
|
611
|
-
private setKnownFeatureFlagDetails;
|
|
612
|
-
private getKnownFeatureFlagDetails;
|
|
613
|
-
protected getKnownFeatureFlags(): PostHogFlagsResponse['featureFlags'] | undefined;
|
|
614
|
-
private getKnownFeatureFlagPayloads;
|
|
615
|
-
private getBootstrappedFeatureFlagDetails;
|
|
616
|
-
private setBootstrappedFeatureFlagDetails;
|
|
617
|
-
private getBootstrappedFeatureFlags;
|
|
618
|
-
private getBootstrappedFeatureFlagPayloads;
|
|
619
|
-
getFeatureFlag(key: string): FeatureFlagValue | undefined;
|
|
620
|
-
getFeatureFlagPayload(key: string): JsonType | undefined;
|
|
621
|
-
getFeatureFlagPayloads(): PostHogFlagsResponse['featureFlagPayloads'] | undefined;
|
|
622
|
-
getFeatureFlags(): PostHogFlagsResponse['featureFlags'] | undefined;
|
|
623
|
-
getFeatureFlagDetails(): PostHogFeatureFlagDetails | undefined;
|
|
624
|
-
getFeatureFlagsAndPayloads(): {
|
|
625
|
-
flags: PostHogFlagsResponse['featureFlags'] | undefined;
|
|
626
|
-
payloads: PostHogFlagsResponse['featureFlagPayloads'] | undefined;
|
|
627
|
-
};
|
|
628
|
-
isFeatureEnabled(key: string): boolean | undefined;
|
|
629
|
-
reloadFeatureFlags(options?: {
|
|
630
|
-
cb?: (err?: Error, flags?: PostHogFlagsResponse['featureFlags']) => void;
|
|
631
|
-
}): void;
|
|
632
|
-
reloadRemoteConfigAsync(): Promise<PostHogRemoteConfig | undefined>;
|
|
633
|
-
reloadFeatureFlagsAsync(sendAnonDistinctId?: boolean): Promise<PostHogFlagsResponse['featureFlags'] | undefined>;
|
|
634
|
-
onFeatureFlags(cb: (flags: PostHogFlagsResponse['featureFlags']) => void): () => void;
|
|
635
|
-
onFeatureFlag(key: string, cb: (value: FeatureFlagValue) => void): () => void;
|
|
636
|
-
overrideFeatureFlag(flags: PostHogFlagsResponse['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;
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
type PostHogOptions = {
|
|
657
|
-
autocapture?: boolean;
|
|
658
|
-
persistence?: 'localStorage' | 'sessionStorage' | 'cookie' | 'memory';
|
|
659
|
-
persistence_name?: string;
|
|
660
|
-
captureHistoryEvents?: boolean;
|
|
661
|
-
} & PostHogCoreOptions;
|
|
662
|
-
|
|
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;
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
export { PostHog, PostHog as default };
|