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/lib/index.d.ts CHANGED
@@ -1,20 +1,36 @@
1
- declare type PosthogCoreOptions = {
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
- enable?: boolean;
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?: number;
97
- retryDelay?: number;
98
- retryCheck?: (err: any) => boolean;
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
- private _optoutOverride;
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?: PosthogCoreOptions);
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): this;
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): this;
167
+ }, options?: PostHogCaptureOptions): void;
147
168
  protected aliasStateless(alias: string, distinctId: string, properties?: {
148
169
  [key: string]: any;
149
- }, options?: PostHogCaptureOptions): this;
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): this;
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?: PosthogCoreOptions);
184
- protected setupBootstrap(options?: Partial<PosthogCoreOptions>): void;
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(properties?: PostHogEventProperties): any;
193
- getSessionId(): string | undefined;
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): this;
238
+ identify(distinctId?: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
209
239
  capture(event: string, properties?: {
210
240
  [key: string]: any;
211
- }, options?: PostHogCaptureOptions): this;
212
- alias(alias: string): this;
213
- autocapture(eventType: string, elements: PostHogAutocaptureElement[], properties?: PostHogEventProperties, options?: PostHogCaptureOptions): this;
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
- }): this;
220
- group(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PostHogCaptureOptions): this;
221
- groupIdentify(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PostHogCaptureOptions): this;
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
- }): this;
257
+ }): void;
228
258
  resetPersonPropertiesForFlags(): void;
229
259
  /** @deprecated - Renamed to setPersonPropertiesForFlags */
230
260
  personProperties(properties: {
231
261
  [type: string]: string;
232
- }): this;
262
+ }): void;
233
263
  setGroupPropertiesForFlags(properties: {
234
264
  [type: string]: Record<string, string>;
235
- }): this;
265
+ }): void;
236
266
  resetGroupPropertiesForFlags(): void;
237
267
  /** @deprecated - Renamed to setGroupPropertiesForFlags */
238
268
  groupProperties(properties: {
239
269
  [type: string]: Record<string, string>;
240
- }): this;
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
- } & PosthogCoreOptions;
298
+ } & PostHogCoreOptions;
269
299
 
270
300
  declare class PostHog extends PostHogCore {
271
301
  private _storage;