posthog-js-lite 2.6.1 → 3.0.0-beta.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/CHANGELOG.md +13 -0
- package/lib/index.cjs.js +995 -1149
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +65 -35
- package/lib/index.esm.js +995 -1149
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-core/src/index.d.ts +44 -30
- package/lib/posthog-core/src/types.d.ts +19 -3
- package/lib/posthog-core/src/utils.d.ts +5 -4
- package/lib/posthog-core/src/vendor/uuidv7.d.ts +179 -0
- package/lib/posthog-web/src/types.d.ts +2 -2
- package/package.json +1 -1
- package/src/types.ts +2 -2
- package/test/posthog-web.spec.ts +6 -2
- package/tsconfig.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -1,20 +1,36 @@
|
|
|
1
|
-
declare type
|
|
1
|
+
declare type PostHogCoreOptions = {
|
|
2
|
+
/** PostHog API host, usually 'https://app.posthog.com' or 'https://eu.posthog.com' */
|
|
2
3
|
host?: string;
|
|
4
|
+
/** The number of events to queue before sending to PostHog (flushing) */
|
|
3
5
|
flushAt?: number;
|
|
6
|
+
/** The interval in milliseconds between periodic flushes */
|
|
4
7
|
flushInterval?: number;
|
|
5
|
-
|
|
8
|
+
/** If set to true the SDK is essentially disabled (useful for local environments where you don't want to track anything) */
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
/** If set to false the SDK will not track until the `optIn` function is called. */
|
|
11
|
+
defaultOptIn?: boolean;
|
|
12
|
+
/** Whether to track that `getFeatureFlag` was called (used by Experiments) */
|
|
6
13
|
sendFeatureFlagEvent?: boolean;
|
|
14
|
+
/** Whether to load feature flags when initialized or not */
|
|
7
15
|
preloadFeatureFlags?: boolean;
|
|
16
|
+
/** Option to bootstrap the library with given distinctId and feature flags */
|
|
8
17
|
bootstrap?: {
|
|
9
18
|
distinctId?: string;
|
|
10
19
|
isIdentifiedId?: boolean;
|
|
11
20
|
featureFlags?: Record<string, boolean | string>;
|
|
12
21
|
featureFlagPayloads?: Record<string, JsonType>;
|
|
13
22
|
};
|
|
23
|
+
/** How many times we will retry HTTP requests. Defaults to 3. */
|
|
14
24
|
fetchRetryCount?: number;
|
|
25
|
+
/** The delay between HTTP request retries, Defaults to 3 seconds. */
|
|
15
26
|
fetchRetryDelay?: number;
|
|
27
|
+
/** Timeout in milliseconds for any calls. Defaults to 10 seconds. */
|
|
16
28
|
requestTimeout?: number;
|
|
29
|
+
/** Timeout in milliseconds for feature flag calls. Defaults to 10 seconds for stateful clients, and 3 seconds for stateless. */
|
|
30
|
+
featureFlagsRequestTimeoutMs?: number;
|
|
31
|
+
/** For Session Analysis how long before we expire a session (defaults to 30 mins) */
|
|
17
32
|
sessionExpirationTimeSeconds?: number;
|
|
33
|
+
/** Whether to post events to PostHog in JSON or compressed format */
|
|
18
34
|
captureMode?: 'json' | 'form';
|
|
19
35
|
disableGeoip?: boolean;
|
|
20
36
|
};
|
|
@@ -93,9 +109,9 @@ declare type JsonType = string | number | boolean | null | {
|
|
|
93
109
|
} | Array<JsonType>;
|
|
94
110
|
|
|
95
111
|
interface RetriableOptions {
|
|
96
|
-
retryCount
|
|
97
|
-
retryDelay
|
|
98
|
-
retryCheck
|
|
112
|
+
retryCount: number;
|
|
113
|
+
retryDelay: number;
|
|
114
|
+
retryCheck: (err: any) => boolean;
|
|
99
115
|
}
|
|
100
116
|
|
|
101
117
|
declare class SimpleEventEmitter {
|
|
@@ -113,44 +129,49 @@ declare abstract class PostHogCoreStateless {
|
|
|
113
129
|
private flushAt;
|
|
114
130
|
private flushInterval;
|
|
115
131
|
private requestTimeout;
|
|
132
|
+
private featureFlagsRequestTimeoutMs;
|
|
116
133
|
private captureMode;
|
|
117
134
|
private removeDebugCallback?;
|
|
118
|
-
private debugMode;
|
|
119
135
|
private disableGeoip;
|
|
120
|
-
|
|
136
|
+
disabled: boolean;
|
|
137
|
+
private defaultOptIn;
|
|
121
138
|
private pendingPromises;
|
|
122
139
|
protected _events: SimpleEventEmitter;
|
|
123
140
|
protected _flushTimer?: any;
|
|
124
141
|
protected _retryOptions: RetriableOptions;
|
|
142
|
+
protected _initPromise: Promise<void>;
|
|
143
|
+
protected _isInitialized: boolean;
|
|
125
144
|
abstract fetch(url: string, options: PostHogFetchOptions): Promise<PostHogFetchResponse>;
|
|
126
145
|
abstract getLibraryId(): string;
|
|
127
146
|
abstract getLibraryVersion(): string;
|
|
128
147
|
abstract getCustomUserAgent(): string | void;
|
|
129
148
|
abstract getPersistedProperty<T>(key: PostHogPersistedProperty): T | undefined;
|
|
130
149
|
abstract setPersistedProperty<T>(key: PostHogPersistedProperty, value: T | null): void;
|
|
131
|
-
constructor(apiKey: string, options?:
|
|
150
|
+
constructor(apiKey: string, options?: PostHogCoreOptions);
|
|
151
|
+
protected wrap(fn: () => void): void;
|
|
132
152
|
protected getCommonEventProperties(): any;
|
|
133
153
|
get optedOut(): boolean;
|
|
134
|
-
optIn(): void
|
|
135
|
-
optOut(): void
|
|
154
|
+
optIn(): Promise<void>;
|
|
155
|
+
optOut(): Promise<void>;
|
|
136
156
|
on(event: string, cb: (...args: any[]) => void): () => void;
|
|
137
157
|
debug(enabled?: boolean): void;
|
|
158
|
+
get isDebug(): boolean;
|
|
138
159
|
private buildPayload;
|
|
139
160
|
protected addPendingPromise(promise: Promise<any>): void;
|
|
140
161
|
/***
|
|
141
162
|
*** TRACKING
|
|
142
163
|
***/
|
|
143
|
-
protected identifyStateless(distinctId: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions):
|
|
164
|
+
protected identifyStateless(distinctId: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
|
|
144
165
|
protected captureStateless(distinctId: string, event: string, properties?: {
|
|
145
166
|
[key: string]: any;
|
|
146
|
-
}, options?: PostHogCaptureOptions):
|
|
167
|
+
}, options?: PostHogCaptureOptions): void;
|
|
147
168
|
protected aliasStateless(alias: string, distinctId: string, properties?: {
|
|
148
169
|
[key: string]: any;
|
|
149
|
-
}, options?: PostHogCaptureOptions):
|
|
170
|
+
}, options?: PostHogCaptureOptions): void;
|
|
150
171
|
/***
|
|
151
172
|
*** GROUPS
|
|
152
173
|
***/
|
|
153
|
-
protected groupIdentifyStateless(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PostHogCaptureOptions, distinctId?: string, eventProperties?: PostHogEventProperties):
|
|
174
|
+
protected groupIdentifyStateless(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PostHogCaptureOptions, distinctId?: string, eventProperties?: PostHogEventProperties): void;
|
|
154
175
|
/***
|
|
155
176
|
*** FEATURE FLAGS
|
|
156
177
|
***/
|
|
@@ -171,8 +192,8 @@ declare abstract class PostHogCoreStateless {
|
|
|
171
192
|
flushAsync(): Promise<any>;
|
|
172
193
|
flush(callback?: (err?: any, data?: any) => void): void;
|
|
173
194
|
private fetchWithRetry;
|
|
174
|
-
shutdownAsync(): Promise<void>;
|
|
175
|
-
shutdown(): void;
|
|
195
|
+
shutdownAsync(shutdownTimeoutMs?: number): Promise<void>;
|
|
196
|
+
shutdown(shutdownTimeoutMs?: number): void;
|
|
176
197
|
}
|
|
177
198
|
declare abstract class PostHogCore extends PostHogCoreStateless {
|
|
178
199
|
private sendFeatureFlagEvent;
|
|
@@ -180,8 +201,8 @@ declare abstract class PostHogCore extends PostHogCoreStateless {
|
|
|
180
201
|
protected _decideResponsePromise?: Promise<PostHogDecideResponse | undefined>;
|
|
181
202
|
protected _sessionExpirationTimeSeconds: number;
|
|
182
203
|
protected sessionProps: PostHogEventProperties;
|
|
183
|
-
constructor(apiKey: string, options?:
|
|
184
|
-
protected setupBootstrap(options?: Partial<
|
|
204
|
+
constructor(apiKey: string, options?: PostHogCoreOptions);
|
|
205
|
+
protected setupBootstrap(options?: Partial<PostHogCoreOptions>): void;
|
|
185
206
|
private get props();
|
|
186
207
|
private set props(value);
|
|
187
208
|
private clearProps;
|
|
@@ -189,15 +210,24 @@ declare abstract class PostHogCore extends PostHogCoreStateless {
|
|
|
189
210
|
on(event: string, cb: (...args: any[]) => void): () => void;
|
|
190
211
|
reset(propertiesToKeep?: PostHogPersistedProperty[]): void;
|
|
191
212
|
protected getCommonEventProperties(): any;
|
|
192
|
-
enrichProperties
|
|
193
|
-
|
|
213
|
+
private enrichProperties;
|
|
214
|
+
/**
|
|
215
|
+
* * @returns {string} The stored session ID for the current session. This may be an empty string if the client is not yet fully initialized.
|
|
216
|
+
*/
|
|
217
|
+
getSessionId(): string;
|
|
194
218
|
resetSessionId(): void;
|
|
219
|
+
/**
|
|
220
|
+
* * @returns {string} The stored anonymous ID. This may be an empty string if the client is not yet fully initialized.
|
|
221
|
+
*/
|
|
195
222
|
getAnonymousId(): string;
|
|
223
|
+
/**
|
|
224
|
+
* * @returns {string} The stored distinct ID. This may be an empty string if the client is not yet fully initialized.
|
|
225
|
+
*/
|
|
196
226
|
getDistinctId(): string;
|
|
197
|
-
unregister(property: string): void
|
|
227
|
+
unregister(property: string): Promise<void>;
|
|
198
228
|
register(properties: {
|
|
199
229
|
[key: string]: any;
|
|
200
|
-
}): void
|
|
230
|
+
}): Promise<void>;
|
|
201
231
|
registerForSession(properties: {
|
|
202
232
|
[key: string]: any;
|
|
203
233
|
}): void;
|
|
@@ -205,39 +235,39 @@ declare abstract class PostHogCore extends PostHogCoreStateless {
|
|
|
205
235
|
/***
|
|
206
236
|
*** TRACKING
|
|
207
237
|
***/
|
|
208
|
-
identify(distinctId?: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions):
|
|
238
|
+
identify(distinctId?: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
|
|
209
239
|
capture(event: string, properties?: {
|
|
210
240
|
[key: string]: any;
|
|
211
|
-
}, options?: PostHogCaptureOptions):
|
|
212
|
-
alias(alias: string):
|
|
213
|
-
autocapture(eventType: string, elements: PostHogAutocaptureElement[], properties?: PostHogEventProperties, options?: PostHogCaptureOptions):
|
|
241
|
+
}, options?: PostHogCaptureOptions): void;
|
|
242
|
+
alias(alias: string): void;
|
|
243
|
+
autocapture(eventType: string, elements: PostHogAutocaptureElement[], properties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
|
|
214
244
|
/***
|
|
215
245
|
*** GROUPS
|
|
216
246
|
***/
|
|
217
247
|
groups(groups: {
|
|
218
248
|
[type: string]: string | number;
|
|
219
|
-
}):
|
|
220
|
-
group(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PostHogCaptureOptions):
|
|
221
|
-
groupIdentify(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PostHogCaptureOptions):
|
|
249
|
+
}): void;
|
|
250
|
+
group(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
|
|
251
|
+
groupIdentify(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
|
|
222
252
|
/***
|
|
223
253
|
* PROPERTIES
|
|
224
254
|
***/
|
|
225
255
|
setPersonPropertiesForFlags(properties: {
|
|
226
256
|
[type: string]: string;
|
|
227
|
-
}):
|
|
257
|
+
}): void;
|
|
228
258
|
resetPersonPropertiesForFlags(): void;
|
|
229
259
|
/** @deprecated - Renamed to setPersonPropertiesForFlags */
|
|
230
260
|
personProperties(properties: {
|
|
231
261
|
[type: string]: string;
|
|
232
|
-
}):
|
|
262
|
+
}): void;
|
|
233
263
|
setGroupPropertiesForFlags(properties: {
|
|
234
264
|
[type: string]: Record<string, string>;
|
|
235
|
-
}):
|
|
265
|
+
}): void;
|
|
236
266
|
resetGroupPropertiesForFlags(): void;
|
|
237
267
|
/** @deprecated - Renamed to setGroupPropertiesForFlags */
|
|
238
268
|
groupProperties(properties: {
|
|
239
269
|
[type: string]: Record<string, string>;
|
|
240
|
-
}):
|
|
270
|
+
}): void;
|
|
241
271
|
/***
|
|
242
272
|
*** FEATURE FLAGS
|
|
243
273
|
***/
|
|
@@ -258,14 +288,14 @@ declare abstract class PostHogCore extends PostHogCoreStateless {
|
|
|
258
288
|
reloadFeatureFlagsAsync(sendAnonDistinctId?: boolean): Promise<PostHogDecideResponse['featureFlags'] | undefined>;
|
|
259
289
|
onFeatureFlags(cb: (flags: PostHogDecideResponse['featureFlags']) => void): () => void;
|
|
260
290
|
onFeatureFlag(key: string, cb: (value: string | boolean) => void): () => void;
|
|
261
|
-
overrideFeatureFlag(flags: PostHogDecideResponse['featureFlags'] | null): void
|
|
291
|
+
overrideFeatureFlag(flags: PostHogDecideResponse['featureFlags'] | null): Promise<void>;
|
|
262
292
|
}
|
|
263
293
|
|
|
264
294
|
declare type PostHogOptions = {
|
|
265
295
|
autocapture?: boolean;
|
|
266
296
|
persistence?: 'localStorage' | 'sessionStorage' | 'cookie' | 'memory';
|
|
267
297
|
persistence_name?: string;
|
|
268
|
-
} &
|
|
298
|
+
} & PostHogCoreOptions;
|
|
269
299
|
|
|
270
300
|
declare class PostHog extends PostHogCore {
|
|
271
301
|
private _storage;
|