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