posthog-js 1.25.2 → 1.27.0-alpha2

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/dist/module.d.ts CHANGED
@@ -1,9 +1,440 @@
1
- // Type definitions for exported methods
1
+ import { MaskInputOptions, SlimDOMOptions } from 'rrweb-snapshot';
2
+ import { record } from 'rrweb';
3
+ import { listenerHandler, eventWithTime } from 'rrweb/typings/types';
4
+ import { EventProcessor, Hub } from '@sentry/types';
5
+
6
+ declare class CaptureMetrics {
7
+ enabled: boolean;
8
+ metrics: Record<string, number>;
9
+ constructor(enabled: boolean);
10
+ incr(key: string, by?: number): void;
11
+ decr(key: string): void;
12
+ }
2
13
 
3
- import { EventProcessor, Hub, Integration } from '@sentry/types'
4
- import { MaskInputOptions, SlimDOMOptions } from 'rrweb-snapshot'
14
+ declare class RequestQueueScaffold {
15
+ isPolling: boolean;
16
+ _event_queue: any[];
17
+ _empty_queue_count: number;
18
+ _poller: number | undefined;
19
+ _pollInterval: number;
20
+ constructor(pollInterval?: number);
21
+ setPollInterval(interval: number): void;
22
+ poll(): void;
23
+ unload(): void;
24
+ getTime(): number;
25
+ }
5
26
 
6
- declare class posthog {
27
+ declare class RetryQueue extends RequestQueueScaffold {
28
+ captureMetrics: CaptureMetrics;
29
+ queue: RetryQueueElement[];
30
+ isPolling: boolean;
31
+ areWeOnline: boolean;
32
+ onXHRError: (failedRequest: XMLHttpRequest) => void;
33
+ constructor(captureMetrics: CaptureMetrics, onXHRError: (failedRequest: XMLHttpRequest) => void);
34
+ enqueue(requestData: QueuedRequestData): void;
35
+ poll(): void;
36
+ flush(): void;
37
+ unload(): void;
38
+ _executeXhrRequest({ url, data, options, headers, callback, retriesPerformedSoFar }: QueuedRequestData): void;
39
+ _handleWeAreNowOnline(): void;
40
+ }
41
+
42
+ declare type Property = any;
43
+ declare type Properties = Record<string, Property>;
44
+ interface CaptureResult {
45
+ event: string;
46
+ properties: Properties;
47
+ $set?: Properties;
48
+ timestamp?: Date;
49
+ }
50
+ interface PostHogConfig {
51
+ api_host: string;
52
+ api_method: string;
53
+ api_transport: string;
54
+ token: string;
55
+ autocapture: boolean;
56
+ rageclick: boolean;
57
+ cross_subdomain_cookie: boolean;
58
+ persistence: 'localStorage' | 'cookie' | 'memory' | 'localStorage+cookie';
59
+ persistence_name: string;
60
+ cookie_name: string;
61
+ loaded: (posthog_instance: PostHog) => void;
62
+ store_google: boolean;
63
+ save_referrer: boolean;
64
+ test: boolean;
65
+ verbose: boolean;
66
+ img: boolean;
67
+ capture_pageview: boolean;
68
+ debug: boolean;
69
+ cookie_expiration: number;
70
+ upgrade: boolean;
71
+ disable_session_recording: boolean;
72
+ disable_persistence: boolean;
73
+ disable_cookie: boolean;
74
+ enable_recording_console_log: boolean;
75
+ secure_cookie: boolean;
76
+ ip: boolean;
77
+ opt_out_capturing_by_default: boolean;
78
+ opt_out_persistence_by_default: boolean;
79
+ opt_out_capturing_persistence_type: 'localStorage' | 'cookie';
80
+ opt_out_capturing_cookie_prefix: string | null;
81
+ respect_dnt: boolean;
82
+ property_blacklist: string[];
83
+ xhr_headers: {
84
+ [header_name: string]: string;
85
+ };
86
+ on_xhr_error: (failedRequest: XMLHttpRequest) => void;
87
+ inapp_protocol: string;
88
+ inapp_link_new_window: boolean;
89
+ request_batching: boolean;
90
+ sanitize_properties: ((properties: Properties, event_name: string) => Properties) | null;
91
+ properties_string_max_length: number;
92
+ session_recording: SessionRecordingOptions;
93
+ mask_all_element_attributes: boolean;
94
+ mask_all_text: boolean;
95
+ advanced_disable_decide: boolean;
96
+ advanced_disable_toolbar_metrics: boolean;
97
+ get_device_id: (uuid: string) => string;
98
+ name: string;
99
+ callback_fn: string;
100
+ _onCapture: (eventName: string, eventData: CaptureResult) => void;
101
+ _capture_metrics: boolean;
102
+ _capture_performance: boolean;
103
+ }
104
+ interface OptInOutCapturingOptions {
105
+ capture: (event: string, properties: Properties, options: CaptureOptions) => void;
106
+ capture_event_name: string;
107
+ capture_properties: Properties;
108
+ enable_persistence: boolean;
109
+ clear_persistence: boolean;
110
+ persistence_type: string;
111
+ cookie_prefix: string;
112
+ cookie_expiration: number;
113
+ cross_subdomain_cookie: boolean;
114
+ secure_cookie: boolean;
115
+ }
116
+ interface isFeatureEnabledOptions {
117
+ send_event: boolean;
118
+ }
119
+ interface SessionRecordingOptions {
120
+ blockClass?: string | RegExp;
121
+ blockSelector?: string | null;
122
+ ignoreClass?: string;
123
+ maskAllInputs?: boolean;
124
+ maskInputOptions?: MaskInputOptions;
125
+ maskInputFn?: ((text: string) => string) | null;
126
+ slimDOMOptions?: SlimDOMOptions | 'all' | true;
127
+ collectFonts?: boolean;
128
+ inlineStylesheet?: boolean;
129
+ }
130
+ declare enum Compression {
131
+ GZipJS = "gzip-js",
132
+ LZ64 = "lz64",
133
+ Base64 = "base64"
134
+ }
135
+ interface XHROptions {
136
+ transport?: 'XHR' | 'sendBeacon';
137
+ method?: 'POST' | 'GET';
138
+ urlQueryArgs?: {
139
+ compression: Compression;
140
+ };
141
+ verbose?: boolean;
142
+ blob?: boolean;
143
+ sendBeacon?: boolean;
144
+ }
145
+ interface CaptureOptions extends XHROptions {
146
+ $set?: Properties; /** used with $identify */
147
+ $set_once?: Properties; /** used with $identify */
148
+ _batchKey?: string; /** key of queue, e.g. 'sessionRecording' vs 'event' */
149
+ _metrics?: Properties;
150
+ _noTruncate?: boolean; /** if set, overrides and disables config.properties_string_max_length */
151
+ endpoint?: string; /** defaults to '/e/' */
152
+ send_instantly?: boolean; /** if set skips the batched queue */
153
+ }
154
+ interface RetryQueueElement {
155
+ retryAt: Date;
156
+ requestData: QueuedRequestData;
157
+ }
158
+ interface QueuedRequestData {
159
+ url: string;
160
+ data: Properties;
161
+ options: CaptureOptions;
162
+ headers?: Properties;
163
+ callback?: RequestCallback;
164
+ retriesPerformedSoFar?: number;
165
+ }
166
+ interface DecideResponse {
167
+ status: number;
168
+ supportedCompression: Compression[];
169
+ config: {
170
+ enable_collect_everything: boolean;
171
+ };
172
+ custom_properties: AutoCaptureCustomProperty[];
173
+ featureFlags: Record<string, string | boolean>;
174
+ sessionRecording?: {
175
+ endpoint?: string;
176
+ };
177
+ editorParams: EditorParams;
178
+ toolbarVersion: 'toolbar'; /** deprecated, moved to editorParams */
179
+ isAuthenticated: boolean;
180
+ }
181
+ declare type FeatureFlagsCallback = (flags: string[], variants: Record<string, string | boolean>) => void;
182
+ interface AutoCaptureCustomProperty {
183
+ name: string;
184
+ css_selector: string;
185
+ event_selectors: string[];
186
+ }
187
+ interface GDPROptions {
188
+ capture?: (event: string, properties: Properties, options: CaptureOptions) => void; /** function used for capturing a PostHog event to record the opt-in action */
189
+ captureEventName?: string; /** event name to be used for capturing the opt-in action */
190
+ captureProperties?: Properties; /** set of properties to be captured along with the opt-in action */
191
+ persistenceType?: string; /** persistence mechanism used - cookie or localStorage */
192
+ persistencePrefix?: string; /** [__ph_opt_in_out] - custom prefix to be used in the cookie/localstorage name */
193
+ cookieExpiration?: number; /** number of days until the opt-in cookie expires */
194
+ crossSubdomainCookie?: boolean; /** whether the opt-in cookie is set as cross-subdomain or not */
195
+ secureCookie?: boolean; /** whether the opt-in cookie is set as secure or not */
196
+ respectDnt?: boolean;
197
+ window?: Window;
198
+ }
199
+ declare type RequestCallback = (response: Record<string, any>, data?: Properties) => void;
200
+ interface PersistentStore {
201
+ is_supported: () => boolean;
202
+ error: (error: any) => void;
203
+ parse: (name: string) => any;
204
+ get: (name: string) => any;
205
+ set: (name: string, value: any, expire_days?: number | null, cross_subdomain?: boolean, secure?: boolean) => void;
206
+ remove: (name: string, cross_subdomain?: boolean) => void;
207
+ }
208
+ interface EditorParams {
209
+ jsURL?: string;
210
+ apiURL?: string;
211
+ toolbarVersion?: 'toolbar';
212
+ }
213
+ interface JSC {
214
+ (): void;
215
+ [key: string]: (response: any) => void;
216
+ }
217
+ declare type SnippetArrayItem = [method: string, ...args: any[]];
218
+
219
+ /**
220
+ * PostHog People Object
221
+ * @constructor
222
+ */
223
+ declare class PostHogPeople {
224
+ _posthog: PostHog;
225
+ set: (prop: string | Properties, to?: string, callback?: RequestCallback) => void;
226
+ set_once: (prop: string | Properties, to?: string, callback?: RequestCallback) => void;
227
+ constructor(posthog: PostHog);
228
+ toString(): string;
229
+ _send_request(data: Properties, callback?: RequestCallback): Properties;
230
+ _get_config<K extends keyof PostHogConfig>(conf_var: K): PostHogConfig[K];
231
+ _is_reserved_property(prop: string): boolean;
232
+ private set_action;
233
+ private set_once_action;
234
+ private apiActionParser;
235
+ }
236
+
237
+ /**
238
+ * PostHog Persistence Object
239
+ * @constructor
240
+ */
241
+ declare class PostHogPersistence {
242
+ props: Properties;
243
+ storage: PersistentStore;
244
+ campaign_params_saved: boolean;
245
+ name: string;
246
+ disabled: boolean | undefined;
247
+ secure: boolean | undefined;
248
+ expire_days: number | undefined;
249
+ default_expiry: number | undefined;
250
+ cross_subdomain: boolean | undefined;
251
+ constructor(config: PostHogConfig);
252
+ properties(): Properties;
253
+ load(): void;
254
+ save(): void;
255
+ remove(): void;
256
+ clear(): void;
257
+ /**
258
+ * @param {Object} props
259
+ * @param {*=} default_value
260
+ * @param {number=} days
261
+ */
262
+ register_once(props: Properties, default_value: any, days?: number): boolean;
263
+ /**
264
+ * @param {Object} props
265
+ * @param {number=} days
266
+ */
267
+ register(props: Properties, days?: number): boolean;
268
+ unregister(prop: string): void;
269
+ update_campaign_params(): void;
270
+ update_search_keyword(referrer: string): void;
271
+ update_referrer_info(referrer: string): void;
272
+ get_referrer_info(): Properties;
273
+ safe_merge(props: Properties): Properties;
274
+ update_config(config: PostHogConfig): void;
275
+ set_disabled(disabled: boolean): void;
276
+ set_cross_subdomain(cross_subdomain: boolean): void;
277
+ get_cross_subdomain(): boolean;
278
+ set_secure(secure: boolean): void;
279
+ set_event_timer(event_name: string, timestamp: number): void;
280
+ remove_event_timer(event_name: string): number;
281
+ }
282
+
283
+ declare class PostHogFeatureFlags {
284
+ instance: PostHog;
285
+ _override_warning: boolean;
286
+ flagCallReported: Record<string, boolean>;
287
+ featureFlagEventHandlers: FeatureFlagsCallback[];
288
+ reloadFeatureFlagsQueued: boolean;
289
+ reloadFeatureFlagsInAction: boolean;
290
+ $anon_distinct_id: string | undefined;
291
+ constructor(instance: PostHog);
292
+ getFlags(): string[];
293
+ getFlagVariants(): Record<string, string | boolean>;
294
+ /**
295
+ * Reloads feature flags asynchronously.
296
+ *
297
+ * Constraints:
298
+ *
299
+ * 1. Avoid parallel requests
300
+ * 2. Delay a few milliseconds after each reloadFeatureFlags call to batch subsequent changes together
301
+ * 3. Don't call this during initial load (as /decide will be called instead), see posthog-core.js
302
+ */
303
+ reloadFeatureFlags(): void;
304
+ setAnonymousDistinctId(anon_distinct_id: string): void;
305
+ setReloadingPaused(isPaused: boolean): void;
306
+ resetRequestQueue(): void;
307
+ _startReloadTimer(): void;
308
+ _reloadFeatureFlagsRequest(): void;
309
+ getFeatureFlag(key: string, options?: {
310
+ send_event?: boolean;
311
+ }): boolean | string;
312
+ isFeatureEnabled(key: string, options?: {
313
+ send_event?: boolean;
314
+ }): boolean;
315
+ addFeatureFlagsHandler(handler: FeatureFlagsCallback): void;
316
+ receivedFeatureFlags(response: DecideResponse): void;
317
+ override(flags: boolean | string[] | Record<string, string | boolean>): void;
318
+ onFeatureFlags(callback: FeatureFlagsCallback): void;
319
+ }
320
+
321
+ declare class SessionRecording {
322
+ instance: PostHog;
323
+ captureStarted: boolean;
324
+ snapshots: any[];
325
+ emit: boolean;
326
+ endpoint: string;
327
+ stopRrweb: listenerHandler | undefined;
328
+ windowId: string | null;
329
+ sessionId: string | null;
330
+ receivedDecide: boolean;
331
+ rrwebRecord: typeof record | undefined;
332
+ constructor(instance: PostHog);
333
+ startRecordingIfEnabled(): void;
334
+ started(): boolean;
335
+ stopRecording(): void;
336
+ isRecordingEnabled(): boolean;
337
+ afterDecideResponse(response: DecideResponse): void;
338
+ startCaptureAndTrySendingQueuedSnapshots(): void;
339
+ _startCapture(): void;
340
+ _updateWindowAndSessionIds(event: eventWithTime): void;
341
+ _onScriptLoaded(): void;
342
+ _captureSnapshot(properties: Properties): void;
343
+ }
344
+
345
+ declare class Toolbar {
346
+ instance: PostHog;
347
+ constructor(instance: PostHog);
348
+ afterDecideResponse(response: DecideResponse): void;
349
+ /**
350
+ * To load the visual editor, we need an access token and other state. That state comes from one of three places:
351
+ * 1. In the URL hash params if the customer is using an old snippet
352
+ * 2. From session storage under the key `editorParams` if the editor was initialized on a previous page
353
+ */
354
+ maybeLoadEditor(location?: Location, localStorage?: Storage | undefined, history?: History): boolean;
355
+ _loadEditor(editorParams: EditorParams): boolean;
356
+ }
357
+
358
+ declare class RequestQueue extends RequestQueueScaffold {
359
+ captureMetrics: CaptureMetrics;
360
+ handlePollRequest: (url: string, data: Properties, options?: XHROptions) => void;
361
+ constructor(captureMetrics: CaptureMetrics, handlePollRequest: (url: string, data: Properties, options?: XHROptions) => void, pollInterval?: number);
362
+ enqueue(url: string, data: Properties, options: XHROptions): void;
363
+ poll(): void;
364
+ updateUnloadMetrics(): void;
365
+ unload(): void;
366
+ formatQueue(): Record<string, QueuedRequestData>;
367
+ }
368
+
369
+ declare class SessionIdManager {
370
+ persistence: PostHogPersistence;
371
+ _windowId: string | null | undefined;
372
+ _sessionId: string | null | undefined;
373
+ window_id_storage_key: string;
374
+ _sessionStartTimestamp: number | null;
375
+ _sessionActivityTimestamp: number | null;
376
+ constructor(config: Partial<PostHogConfig>, persistence: PostHogPersistence);
377
+ _setWindowId(windowId: string): void;
378
+ _getWindowId(): string | null;
379
+ _setSessionId(sessionId: string | null, sessionActivityTimestamp: number | null, sessionStartTimestamp: number | null): void;
380
+ _getSessionId(): [number, string, number];
381
+ resetSessionId(): void;
382
+ checkAndGetSessionAndWindowId(readOnly?: boolean, _timestamp?: number | null): {
383
+ sessionId: string;
384
+ windowId: string;
385
+ };
386
+ }
387
+
388
+ /**
389
+ * Integrate Sentry with PostHog. This will add a direct link to the person in Sentry, and an $exception event in PostHog
390
+ *
391
+ * ### Usage
392
+ *
393
+ * Sentry.init({
394
+ * dsn: 'https://example',
395
+ * integrations: [
396
+ * new posthog.SentryIntegration(posthog)
397
+ * ]
398
+ * })
399
+ *
400
+ * @param {Object} [posthog] The posthog object
401
+ * @param {string} [organization] Optional: The Sentry organization, used to send a direct link from PostHog to Sentry
402
+ * @param {Number} [projectId] Optional: The Sentry project id, used to send a direct link from PostHog to Sentry
403
+ * @param {string} [prefix] Optional: Url of a self-hosted sentry instance (default: https://sentry.io/organizations/)
404
+ */
405
+
406
+ declare class SentryIntegration {
407
+ name: string;
408
+ setupOnce: (addGlobalEventProcessor: (callback: EventProcessor) => void, getCurrentHub: () => Hub) => void;
409
+ constructor(_posthog: PostHog, organization?: string, projectId?: number, prefix?: string);
410
+ }
411
+
412
+ /**
413
+ * PostHog Library Object
414
+ * @constructor
415
+ */
416
+ declare class PostHog {
417
+ __loaded: boolean;
418
+ config: PostHogConfig;
419
+ persistence: PostHogPersistence;
420
+ sessionManager: SessionIdManager;
421
+ people: PostHogPeople;
422
+ featureFlags: PostHogFeatureFlags;
423
+ feature_flags: PostHogFeatureFlags;
424
+ toolbar: Toolbar;
425
+ sessionRecording: SessionRecording | undefined;
426
+ _captureMetrics: CaptureMetrics;
427
+ _requestQueue: RequestQueue;
428
+ _retryQueue: RetryQueue;
429
+ _triggered_notifs: any;
430
+ compression: Partial<Record<Compression, boolean>>;
431
+ _jsc: JSC;
432
+ __captureHooks: ((eventName: string) => void)[];
433
+ __request_queue: [url: string, data: Record<string, any>, options: XHROptions, callback?: RequestCallback][];
434
+ __autocapture_enabled: boolean | undefined;
435
+ decideEndpointWasHit: boolean;
436
+ SentryIntegration: typeof SentryIntegration;
437
+ constructor();
7
438
  /**
8
439
  * This function initializes a new instance of the PostHog capturing object.
9
440
  * All new instances are added to the main posthog object as sub properties (such as
@@ -20,14 +451,51 @@ declare class posthog {
20
451
  * @param {Object} [config] A dictionary of config options to override. <a href="https://github.com/posthog/posthog-js/blob/6e0e873/src/posthog-core.js#L57-L91">See a list of default config options</a>.
21
452
  * @param {String} [name] The name for the new posthog instance that you want created
22
453
  */
23
- static init(token: string, config?: posthog.Config, name?: string): posthog
24
-
454
+ init(token: string, config?: Partial<PostHogConfig>, name?: string): PostHog | void;
455
+ _init(token: string, config?: Partial<PostHogConfig>, name?: string): void;
456
+ _loaded(): void;
457
+ _start_queue_if_opted_in(): void;
458
+ _dom_loaded(): void;
25
459
  /**
26
- * Clears super properties and generates a new random distinct_id for this instance.
27
- * Useful for clearing data when a user logs out.
460
+ * _prepare_callback() should be called by callers of _send_request for use
461
+ * as the callback argument.
462
+ *
463
+ * If there is no callback, this returns null.
464
+ * If we are going to make XHR/XDR requests, this returns a function.
465
+ * If we are going to use script tags, this returns a string to use as the
466
+ * callback GET param.
28
467
  */
29
- static reset(reset_device_id?: boolean): void
30
-
468
+ _prepare_callback(callback?: RequestCallback, data?: Properties): RequestCallback | null | string;
469
+ _handle_unload(): void;
470
+ _handle_queued_event(url: string, data: Record<string, any>, options?: XHROptions): void;
471
+ __compress_and_send_json_request(url: string, jsonData: string, options: XHROptions, callback?: RequestCallback): void;
472
+ _send_request(url: string, data: Record<string, any>, options: XHROptions, callback?: RequestCallback): void;
473
+ /**
474
+ * _execute_array() deals with processing any posthog function
475
+ * calls that were called before the PostHog library were loaded
476
+ * (and are thus stored in an array so they can be called later)
477
+ *
478
+ * Note: we fire off all the posthog function calls && user defined
479
+ * functions BEFORE we fire off posthog capturing calls. This is so
480
+ * identify/register/set_config calls can properly modify early
481
+ * capturing calls.
482
+ *
483
+ * @param {Array} array
484
+ */
485
+ _execute_array(array: SnippetArrayItem[]): void;
486
+ /**
487
+ * push() keeps the standard async-array-push
488
+ * behavior around after the lib is loaded.
489
+ * This is only useful for external integrations that
490
+ * do not wish to rely on our convenience methods
491
+ * (created in the snippet).
492
+ *
493
+ * ### Usage:
494
+ * posthog.push(['register', { a: 'b' }]);
495
+ *
496
+ * @param {Array} item A [function_name, args...] array to be executed
497
+ */
498
+ push(item: SnippetArrayItem): void;
31
499
  /**
32
500
  * Capture an event. This is the most important and
33
501
  * frequently used PostHog function.
@@ -45,12 +513,10 @@ declare class posthog {
45
513
  * @param {Object} [options] Optional configuration for this capture request.
46
514
  * @param {String} [options.transport] Transport method for network request ('XHR' or 'sendBeacon').
47
515
  */
48
- static capture(
49
- event_name: string,
50
- properties?: posthog.Properties,
51
- options?: { transport: 'XHR' | 'sendBeacon' }
52
- ): posthog.CaptureResult
53
-
516
+ capture(event_name: string, properties?: Properties | null, options?: CaptureOptions): CaptureResult | void;
517
+ _addCaptureHook(callback: (eventName: string) => void): void;
518
+ _invokeCaptureHooks(eventName: string, eventData: CaptureResult): void;
519
+ _calculate_event_properties(event_name: string, event_properties: Properties, start_timestamp: number): Properties;
54
520
  /**
55
521
  * Register a set of super properties, which are included with all
56
522
  * events. This will overwrite previous super property values.
@@ -69,8 +535,7 @@ declare class posthog {
69
535
  * @param {Object} properties An associative array of properties to store about the user
70
536
  * @param {Number} [days] How many days since the user's last visit to store the super properties
71
537
  */
72
- static register(properties: posthog.Properties, days?: number): void
73
-
538
+ register(properties: Properties, days?: number): void;
74
539
  /**
75
540
  * Register a set of super properties only once. This will not
76
541
  * overwrite previous super property values, unlike register().
@@ -91,15 +556,20 @@ declare class posthog {
91
556
  * @param {*} [default_value] Value to override if already set in super properties (ex: 'False') Default: 'None'
92
557
  * @param {Number} [days] How many days since the users last visit to store the super properties
93
558
  */
94
- static register_once(properties: posthog.Properties, default_value?: posthog.Property, days?: number): void
95
-
559
+ register_once(properties: Properties, default_value?: Property, days?: number): void;
96
560
  /**
97
561
  * Delete a super property stored with the current user.
98
562
  *
99
563
  * @param {String} property The name of the super property to remove
100
564
  */
101
- static unregister(property: string): void
102
-
565
+ unregister(property: string): void;
566
+ _register_single(prop: string, value: Property): void;
567
+ getFeatureFlag(key: string, options?: {
568
+ send_event?: boolean;
569
+ }): boolean | string | undefined;
570
+ isFeatureEnabled(key: string, options?: isFeatureEnabledOptions): boolean;
571
+ reloadFeatureFlags(): void;
572
+ onFeatureFlags(callback: (flags: string[], variants: Record<string, boolean | string>) => void): void;
103
573
  /**
104
574
  * Identify a user with a unique ID instead of a PostHog
105
575
  * randomly generated distinct_id. If the method is never called,
@@ -133,16 +603,44 @@ declare class posthog {
133
603
  * practice to call identify on the original, anonymous ID
134
604
  * right after you've aliased it.
135
605
  *
136
- * @param {String} [unique_id] A string that uniquely identifies a user. If not provided, the distinct_id currently in the persistent store (cookie or localStorage) will be used.
137
- * @param {Object} [userProperties] Optional: An associative array of properties to store about the user
606
+ * @param {String} [new_distinct_id] A string that uniquely identifies a user. If not provided, the distinct_id currently in the persistent store (cookie or localStorage) will be used.
607
+ * @param {Object} [userPropertiesToSet] Optional: An associative array of properties to store about the user
138
608
  * @param {Object} [userPropertiesToSetOnce] Optional: An associative array of properties to store about the user. If property is previously set, this does not override that value.
139
609
  */
140
- static identify(
141
- unique_id?: string,
142
- userPropertiesToSet?: posthog.Properties,
143
- userPropertiesToSetOnce?: posthog.Properties
144
- ): void
145
-
610
+ identify(new_distinct_id?: string, userPropertiesToSet?: Properties, userPropertiesToSetOnce?: Properties): void;
611
+ /**
612
+ * Alpha feature: don't use unless you know what you're doing!
613
+ *
614
+ * Sets group analytics information for subsequent events and reloads feature flags.
615
+ *
616
+ * @param {String} groupType Group type (example: 'organization')
617
+ * @param {String} groupKey Group key (example: 'org::5')
618
+ * @param {Object} groupPropertiesToSet Optional properties to set for group
619
+ */
620
+ group(groupType: string, groupKey: string, groupPropertiesToSet?: Properties): void;
621
+ /**
622
+ * Clears super properties and generates a new random distinct_id for this instance.
623
+ * Useful for clearing data when a user logs out.
624
+ */
625
+ reset(reset_device_id?: boolean): void;
626
+ /**
627
+ * Returns the current distinct id of the user. This is either the id automatically
628
+ * generated by the library or the id that has been passed by a call to identify().
629
+ *
630
+ * ### Notes:
631
+ *
632
+ * get_distinct_id() can only be called after the PostHog library has finished loading.
633
+ * init() has a loaded function available to handle this automatically. For example:
634
+ *
635
+ * // set distinct_id after the posthog library has loaded
636
+ * posthog.init('YOUR PROJECT TOKEN', {
637
+ * loaded: function(posthog) {
638
+ * distinct_id = posthog.get_distinct_id();
639
+ * }
640
+ * });
641
+ */
642
+ get_distinct_id(): string;
643
+ getGroups(): Record<string, any>;
146
644
  /**
147
645
  * Create an alias, which PostHog will use to link two distinct_ids going forward (not retroactively).
148
646
  * Multiple aliases can map to the same original ID, but not vice-versa. Aliases can also be chained - the
@@ -164,35 +662,25 @@ declare class posthog {
164
662
  * @param {String} alias A unique identifier that you want to use for this user in the future.
165
663
  * @param {String} [original] The current identifier being used for this user.
166
664
  */
167
- static alias(alias: string, original?: string): posthog.CaptureResult | number
168
-
169
- /**
170
- * Alpha feature: don't use unless you know what you're doing!
171
- *
172
- * Sets group analytics information for subsequent events.
173
- *
174
- * @param {String} groupType Group type (example: 'organization')
175
- * @param {String} groupKey Group key (example: 'org::5')
176
- * @param {Object} groupPropertiesToSet Optional properties to set for group
177
- */
178
- static group(groupType: string, groupKey: string, groupPropertiesToSet?: posthog.Properties): void
179
-
180
- /**
181
- * Alpha feature: don't use unless you know what you're doing!
182
- *
183
- * Returns currently active groups
184
- */
185
- static getGroups(): Record<string, any> // eslint-disable-line @typescript-eslint/no-explicit-any
186
-
665
+ alias(alias: string, original?: string): CaptureResult | void | number;
187
666
  /**
188
667
  * Update the configuration of a posthog library instance.
189
668
  *
190
669
  * The default config is:
191
670
  *
192
671
  * {
672
+ * // Posthog host
673
+ * api_host: 'https://app.posthog.com',
674
+ *
193
675
  * // HTTP method for capturing requests
194
676
  * api_method: 'POST'
195
677
  *
678
+ * // Automatically capture clicks, form submissions and change events
679
+ * autocapture: true
680
+ *
681
+ * // Capture rage clicks (beta) - useful for session recording
682
+ * rageclick: false
683
+ *
196
684
  * // transport for sending requests ('XHR' or 'sendBeacon')
197
685
  * // NB: sendBeacon should only be used for scenarios such as
198
686
  * // page unload where a "best-effort" attempt to send is
@@ -202,12 +690,6 @@ declare class posthog {
202
690
  * // batching or retry mechanisms.
203
691
  * api_transport: 'XHR'
204
692
  *
205
- * // Automatically capture clicks, form submissions and change events
206
- * autocapture: true
207
- *
208
- * // Capture rage clicks (beta) - useful for session recording
209
- * rageclick: false
210
- *
211
693
  * // super properties cookie expiration (in days)
212
694
  * cookie_expiration: 365
213
695
  *
@@ -266,6 +748,9 @@ declare class posthog {
266
748
  * // so make sure you set it when you create the library.
267
749
  * upgrade: false
268
750
  *
751
+ * // if this is true, session recording is always disabled.
752
+ * disable_session_recording: false,
753
+ *
269
754
  * // extra HTTP request headers to set for each API request, in
270
755
  * // the format {'Header-Name': value}
271
756
  * xhr_headers: {}
@@ -289,7 +774,6 @@ declare class posthog {
289
774
  * maskInputFn: null,
290
775
  * slimDOMOptions: {},
291
776
  * collectFonts: false
292
- * inlineStylesheet: true
293
777
  * }
294
778
  *
295
779
  * // prevent autocapture from capturing any attribute names on elements
@@ -298,16 +782,6 @@ declare class posthog {
298
782
  * // prevent autocapture from capturing textContent on all elements
299
783
  * mask_all_text: false
300
784
  *
301
- * // will disable requests to the /decide endpoint (please review documentation for details)
302
- * // autocapture, feature flags, compression and session recording will be disabled when set to `true`
303
- * advanced_disable_decide: false
304
- *
305
- *
306
- * // disable capturing of metrics about toolbar usage
307
- * // only available to self-hosted users, changing this
308
- * // setting will not do anything if you use PostHog Cloud
309
- * advanced_disable_toolbar_metrics: false
310
- *
311
785
  * // Anonymous users get a random UUID as their device by default.
312
786
  * // This option allows overriding that option.
313
787
  * get_device_id: (uuid) => uuid
@@ -316,13 +790,26 @@ declare class posthog {
316
790
  *
317
791
  * @param {Object} config A dictionary of new configuration values to update
318
792
  */
319
- static set_config(config: posthog.Config): void
320
-
793
+ set_config(config: Partial<PostHogConfig>): void;
794
+ /**
795
+ * turns session recording on, and updates the config option
796
+ * disable_session_recording to false
797
+ */
798
+ startSessionRecording(): void;
799
+ /**
800
+ * turns session recording off, and updates the config option
801
+ * disable_session_recording to true
802
+ */
803
+ stopSessionRecording(): void;
804
+ /**
805
+ * returns a boolean indicating whether session recording
806
+ * is currently running
807
+ */
808
+ sessionRecordingStarted(): boolean;
321
809
  /**
322
810
  * returns the current config object for the library.
323
811
  */
324
- static get_config<T extends keyof posthog.Config>(prop_name: T): posthog.Config[T]
325
-
812
+ get_config<K extends keyof PostHogConfig>(prop_name: K): PostHogConfig[K];
326
813
  /**
327
814
  * Returns the value of the super property named property_name. If no such
328
815
  * property is set, get_property() will return the undefined value.
@@ -341,50 +828,17 @@ declare class posthog {
341
828
  *
342
829
  * @param {String} property_name The name of the super property you want to retrieve
343
830
  */
344
- static get_property(property_name: string): posthog.Property | undefined
345
-
346
- /**
347
- * Returns the current distinct id of the user. This is either the id automatically
348
- * generated by the library or the id that has been passed by a call to identify().
349
- *
350
- * ### Notes:
351
- *
352
- * get_distinct_id() can only be called after the PostHog library has finished loading.
353
- * init() has a loaded function available to handle this automatically. For example:
354
- *
355
- * // set distinct_id after the posthog library has loaded
356
- * posthog.init('YOUR PROJECT TOKEN', {
357
- * loaded: function(posthog) {
358
- * distinct_id = posthog.get_distinct_id();
359
- * }
360
- * });
361
- */
362
- static get_distinct_id(): string
363
-
831
+ get_property(property_name: string): Property | undefined;
832
+ toString(): string;
833
+ _gdpr_init(): void;
364
834
  /**
365
- * Opt the user out of data capturing and cookies/localstorage for this PostHog instance
366
- *
367
- * ### Usage
368
- *
369
- * // opt user out
370
- * posthog.opt_out_capturing();
371
- *
372
- * // opt user out with different cookie configuration from PostHog instance
373
- * posthog.opt_out_capturing({
374
- * cookie_expiration: 30,
375
- * secure_cookie: true
376
- * });
377
- *
378
- * @param {Object} [options] A dictionary of config options to override
379
- * @param {boolean} [options.clear_persistence=true] If true, will delete all data stored by the sdk in persistence
380
- * @param {string} [options.persistence_type=localStorage] Persistence mechanism used - cookie or localStorage - falls back to cookie if localStorage is unavailable
381
- * @param {string} [options.cookie_prefix=__ph_opt_in_out] Custom prefix to be used in the cookie/localstorage name
382
- * @param {Number} [options.cookie_expiration] Number of days until the opt-in cookie expires (overrides value specified in this PostHog instance's config)
383
- * @param {boolean} [options.cross_subdomain_cookie] Whether the opt-in cookie is set as cross-subdomain or not (overrides value specified in this PostHog instance's config)
384
- * @param {boolean} [options.secure_cookie] Whether the opt-in cookie is set as secure or not (overrides value specified in this PostHog instance's config)
835
+ * Enable or disable persistence based on options
836
+ * only enable/disable if persistence is not already in this state
837
+ * @param {boolean} [options.clear_persistence] If true, will delete all data stored by the sdk in persistence and disable it
838
+ * @param {boolean} [options.enable_persistence] If true, will re-enable sdk persistence
385
839
  */
386
- static opt_out_capturing(options?: posthog.OptInOutCapturingOptions): void
387
-
840
+ _gdpr_update_persistence(options: Partial<OptInOutCapturingOptions>): void;
841
+ _gdpr_call_func<R = any>(func: (token: string, options: GDPROptions) => R, options?: Partial<OptInOutCapturingOptions>): R;
388
842
  /**
389
843
  * Opt the user in to data capturing and cookies/localstorage for this PostHog instance
390
844
  *
@@ -414,23 +868,30 @@ declare class posthog {
414
868
  * @param {boolean} [options.cross_subdomain_cookie] Whether the opt-in cookie is set as cross-subdomain or not (overrides value specified in this PostHog instance's config)
415
869
  * @param {boolean} [options.secure_cookie] Whether the opt-in cookie is set as secure or not (overrides value specified in this PostHog instance's config)
416
870
  */
417
- static opt_in_capturing(options?: posthog.OptInOutCapturingOptions): void
418
-
871
+ opt_in_capturing(options?: Partial<OptInOutCapturingOptions>): void;
419
872
  /**
420
- * Check whether the user has opted out of data capturing and cookies/localstorage for this PostHog instance
873
+ * Opt the user out of data capturing and cookies/localstorage for this PostHog instance
421
874
  *
422
875
  * ### Usage
423
876
  *
424
- * const has_opted_out = posthog.has_opted_out_capturing();
425
- * // use has_opted_out value
877
+ * // opt user out
878
+ * posthog.opt_out_capturing();
879
+ *
880
+ * // opt user out with different cookie configuration from PostHog instance
881
+ * posthog.opt_out_capturing({
882
+ * cookie_expiration: 30,
883
+ * secure_cookie: true
884
+ * });
426
885
  *
427
886
  * @param {Object} [options] A dictionary of config options to override
887
+ * @param {boolean} [options.clear_persistence=true] If true, will delete all data stored by the sdk in persistence
428
888
  * @param {string} [options.persistence_type=localStorage] Persistence mechanism used - cookie or localStorage - falls back to cookie if localStorage is unavailable
429
889
  * @param {string} [options.cookie_prefix=__ph_opt_in_out] Custom prefix to be used in the cookie/localstorage name
430
- * @returns {boolean} current opt-out status
890
+ * @param {Number} [options.cookie_expiration] Number of days until the opt-in cookie expires (overrides value specified in this PostHog instance's config)
891
+ * @param {boolean} [options.cross_subdomain_cookie] Whether the opt-in cookie is set as cross-subdomain or not (overrides value specified in this PostHog instance's config)
892
+ * @param {boolean} [options.secure_cookie] Whether the opt-in cookie is set as secure or not (overrides value specified in this PostHog instance's config)
431
893
  */
432
- static has_opted_out_capturing(options?: posthog.HasOptedInOutCapturingOptions): boolean
433
-
894
+ opt_out_capturing(options?: Partial<OptInOutCapturingOptions>): void;
434
895
  /**
435
896
  * Check whether the user has opted in to data capturing and cookies/localstorage for this PostHog instance
436
897
  *
@@ -444,8 +905,21 @@ declare class posthog {
444
905
  * @param {string} [options.cookie_prefix=__ph_opt_in_out] Custom prefix to be used in the cookie/localstorage name
445
906
  * @returns {boolean} current opt-in status
446
907
  */
447
- static has_opted_in_capturing(options?: posthog.HasOptedInOutCapturingOptions): boolean
448
-
908
+ has_opted_in_capturing(options?: Partial<OptInOutCapturingOptions>): boolean;
909
+ /**
910
+ * Check whether the user has opted out of data capturing and cookies/localstorage for this PostHog instance
911
+ *
912
+ * ### Usage
913
+ *
914
+ * const has_opted_out = posthog.has_opted_out_capturing();
915
+ * // use has_opted_out value
916
+ *
917
+ * @param {Object} [options] A dictionary of config options to override
918
+ * @param {string} [options.persistence_type=localStorage] Persistence mechanism used - cookie or localStorage - falls back to cookie if localStorage is unavailable
919
+ * @param {string} [options.cookie_prefix=__ph_opt_in_out] Custom prefix to be used in the cookie/localstorage name
920
+ * @returns {boolean} current opt-out status
921
+ */
922
+ has_opted_out_capturing(options?: Partial<OptInOutCapturingOptions>): boolean;
449
923
  /**
450
924
  * Clear the user's opt in/out status of data capturing and cookies/localstorage for this PostHog instance
451
925
  *
@@ -469,391 +943,11 @@ declare class posthog {
469
943
  * @param {boolean} [options.cross_subdomain_cookie] Whether the opt-in cookie is set as cross-subdomain or not (overrides value specified in this PostHog instance's config)
470
944
  * @param {boolean} [options.secure_cookie] Whether the opt-in cookie is set as secure or not (overrides value specified in this PostHog instance's config)
471
945
  */
472
- static clear_opt_in_out_capturing(options?: posthog.ClearOptInOutCapturingOptions): void
473
-
474
- /*
475
- * Get feature flag value for user (supports multivariate flags).
476
- *
477
- * ### Usage:
478
- *
479
- * if(posthog.getFeatureFlag('beta-feature') === 'some-value') { // do something }
480
- *
481
- * @param {Object|String} prop Key of the feature flag.
482
- * @param {Object|String} options (optional) If {send_event: false}, we won't send an $feature_flag_call event to PostHog.
483
- */
484
- static getFeatureFlag(key: string, options?: { send_event?: boolean }): boolean | string | undefined
485
-
486
- /*
487
- * See if feature flag is enabled for user.
488
- *
489
- * ### Usage:
490
- *
491
- * if(posthog.isFeatureEnabled('beta-feature')) { // do something }
492
- *
493
- * @param {Object|String} prop Key of the feature flag.
494
- * @param {Object|String} options (optional) If {send_event: false}, we won't send an $feature_flag_call event to PostHog.
495
- */
496
- static isFeatureEnabled(key: string, options?: posthog.isFeatureEnabledOptions): boolean
497
-
498
- /*
499
- * See if feature flags are available.
500
- *
501
- * ### Usage:
502
- *
503
- * posthog.onFeatureFlags(function(flags, variants) { // do something })
504
- *
505
- * @param {Function} [callback] The callback function will be called once the feature flags are ready. It'll return a list of feature flags enabled for the user.
506
- */
507
- static onFeatureFlags(
508
- callback: (flags: string[], variants: Record<string, boolean | string>) => void
509
- ): false | undefined
510
-
511
- /*
512
- * Reload all feature flags for the user.
513
- *
514
- * ### Usage:
515
- *
516
- * posthog.reloadFeatureFlags()
517
- */
518
- static reloadFeatureFlags(): void
519
-
520
- /**
521
- * Integrate Sentry with PostHog. This will add a direct link to the person in Sentry, and an $exception event in PostHog
522
- *
523
- * ### Usage
524
- *
525
- * Sentry.init({
526
- * dsn: 'https://example',
527
- * integrations: [
528
- * new posthog.SentryIntegration(posthog)
529
- * ]
530
- * })
531
- *
532
- * @param {Object} [posthog] The posthog object
533
- * @param {string} [organization] Optional: The Sentry organization, used to send a direct link from PostHog to Sentry
534
- * @param {Number} [projectId] Optional: The Sentry project id, used to send a direct link from PostHog to Sentry
535
- * @param {string} [prefix] Optional: Url of a self-hosted sentry instance (default: https://sentry.io/organizations/)
536
- */
537
- static SentryIntegration: typeof SentryIntegration
538
-
539
- static toString(): string
540
-
541
- /* Will log all capture requests to the Javascript console, including event properties for easy debugging */
542
- static debug(): void
543
-
544
- /*
545
- * Starts session recording and updates disable_session_recording to false.
546
- * Used for manual session recording management. By default, session recording is enabled and
547
- * starts automatically.
548
- *
549
- * ### Usage:
550
- *
551
- * posthog.startSessionRecording()
552
- */
553
- static startSessionRecording(): void
554
-
555
- /*
556
- * Stops session recording and updates disable_session_recording to true.
557
- *
558
- * ### Usage:
559
- *
560
- * posthog.stopSessionRecording()
561
- */
562
- static stopSessionRecording(): void
563
-
564
- /*
565
- * Check if session recording is currently running.
566
- *
567
- * ### Usage:
568
- *
569
- * const isSessionRecordingOn = posthog.sessionRecordingStarted()
570
- */
571
- static sessionRecordingStarted(): boolean
572
- }
573
-
574
- declare namespace posthog {
575
- /* eslint-disable @typescript-eslint/no-explicit-any */
576
- type Property = any
577
- type Properties = Record<string, Property>
578
- type CaptureResult = { event: string; properties: Properties } | undefined
579
- type CaptureCallback = (response: any, data: any) => void
580
- /* eslint-enable @typescript-eslint/no-explicit-any */
581
-
582
- interface Config {
583
- api_host?: string
584
- api_method?: string
585
- api_transport?: string
586
- autocapture?: boolean
587
- rageclick?: boolean
588
- cdn?: string
589
- cross_subdomain_cookie?: boolean
590
- persistence?: 'localStorage' | 'cookie' | 'memory' | 'localStorage+cookie'
591
- persistence_name?: string
592
- cookie_name?: string
593
- loaded?: (posthog_instance: typeof posthog) => void
594
- store_google?: boolean
595
- save_referrer?: boolean
596
- test?: boolean
597
- verbose?: boolean
598
- img?: boolean
599
- capture_pageview?: boolean
600
- debug?: boolean
601
- cookie_expiration?: number
602
- upgrade?: boolean
603
- disable_session_recording?: boolean
604
- disable_persistence?: boolean
605
- disable_cookie?: boolean
606
- secure_cookie?: boolean
607
- ip?: boolean
608
- opt_out_capturing_by_default?: boolean
609
- opt_out_persistence_by_default?: boolean
610
- opt_out_capturing_persistence_type?: 'localStorage' | 'cookie'
611
- opt_out_capturing_cookie_prefix?: string | null
612
- respect_dnt?: boolean
613
- property_blacklist?: string[]
614
- xhr_headers?: { [header_name: string]: string }
615
- on_xhr_error?: (failedRequest: XMLHttpRequest) => void
616
- inapp_protocol?: string
617
- inapp_link_new_window?: boolean
618
- request_batching?: boolean
619
- sanitize_properties?: (properties: posthog.Properties, event_name: string) => posthog.Properties
620
- properties_string_max_length?: number
621
- session_recording?: SessionRecordingOptions
622
- mask_all_element_attributes?: boolean
623
- mask_all_text?: boolean
624
- advanced_disable_decide?: boolean
625
- advanced_disable_toolbar_metrics?: boolean
626
- get_device_id?: (uuid: string) => string
627
- _capture_performance?: boolean
628
- }
629
-
630
- interface OptInOutCapturingOptions {
631
- clear_persistence: boolean
632
- persistence_type: string
633
- cookie_prefix: string
634
- cookie_expiration: number
635
- cross_subdomain_cookie: boolean
636
- secure_cookie: boolean
637
- }
638
-
639
- interface HasOptedInOutCapturingOptions {
640
- persistence_type: string
641
- cookie_prefix: string
642
- }
643
-
644
- interface ClearOptInOutCapturingOptions {
645
- enable_persistence: boolean
646
- persistence_type: string
647
- cookie_prefix: string
648
- cookie_expiration: number
649
- cross_subdomain_cookie: boolean
650
- secure_cookie: boolean
651
- }
652
-
653
- interface isFeatureEnabledOptions {
654
- send_event: boolean
655
- }
656
-
657
- interface SessionRecordingOptions {
658
- blockClass?: string | RegExp
659
- blockSelector?: string
660
- ignoreClass?: string
661
- maskAllInputs?: boolean
662
- maskInputOptions?: MaskInputOptions
663
- maskInputFn?: (text: string) => string
664
- slimDOMOptions?: SlimDOMOptions | 'all' | true
665
- collectFonts?: boolean
666
- inlineStylesheet?: boolean
667
- }
668
-
669
- export class persistence {
670
- static properties(): posthog.Properties
671
-
672
- static load(): void
673
-
674
- static save(): void
675
-
676
- static remove(): void
677
-
678
- static clear(): void
679
-
680
- /**
681
- * @param {Object} props
682
- * @param {*=} default_value
683
- * @param {number=} days
684
- */
685
- static register_once(props: Properties, default_value?: Property, days?: number): boolean
686
-
687
- /**
688
- * @param {Object} props
689
- * @param {number=} days
690
- */
691
- static register(props: posthog.Properties, days?: number): boolean
692
-
693
- static unregister(prop: string): void
694
-
695
- static update_campaign_params(): void
696
-
697
- static update_search_keyword(referrer: string): void
698
-
699
- static update_referrer_info(referrer: string): void
700
-
701
- static get_referrer_info(): posthog.Properties
702
-
703
- static safe_merge(props: posthog.Properties): posthog.Properties
704
-
705
- static update_config(config: posthog.Config): void
706
-
707
- static set_disabled(disabled: boolean): void
708
-
709
- static set_cross_subdomain(cross_subdomain: boolean): void
710
-
711
- static get_cross_subdomain(): boolean
712
-
713
- static set_secure(secure: boolean): void
714
-
715
- static set_event_timer(event_name: string, timestamp: Date): void
716
-
717
- static remove_event_timer(event_name: string): Date | undefined
718
- }
719
-
720
- export class people {
721
- /*
722
- * Set properties on a user record.
723
- *
724
- * ### Usage:
725
- *
726
- * posthog.people.set('gender', 'm');
727
- *
728
- * // or set multiple properties at once
729
- * posthog.people.set({
730
- * 'Company': 'Acme',
731
- * 'Plan': 'Premium',
732
- * 'Upgrade date': new Date()
733
- * });
734
- * // properties can be strings, integers, dates, or lists
735
- *
736
- * @param {Object|String} prop If a string, this is the name of the property. If an object, this is an associative array of names and values.
737
- * @param {*} [to] A value to set on the given property name
738
- * @param {Function} [callback] If provided, the callback will be called after capturing the event.
739
- */
740
- static set(
741
- prop: posthog.Properties | string,
742
- to?: posthog.Property,
743
- callback?: posthog.CaptureCallback
744
- ): posthog.Properties
745
-
746
- /*
747
- * Set properties on a user record, only if they do not yet exist.
748
- * This will not overwrite previous people property values, unlike
749
- * people.set().
750
- *
751
- * ### Usage:
752
- *
753
- * posthog.people.set_once('First Login Date', new Date());
754
- *
755
- * // or set multiple properties at once
756
- * posthog.people.set_once({
757
- * 'First Login Date': new Date(),
758
- * 'Starting Plan': 'Premium'
759
- * });
760
- *
761
- * // properties can be strings, integers or dates
762
- *
763
- * @param {Object|String} prop If a string, this is the name of the property. If an object, this is an associative array of names and values.
764
- * @param {*} [to] A value to set on the given property name
765
- * @param {Function} [callback] If provided, the callback will be called after capturing the event.
766
- */
767
- static set_once(
768
- prop: posthog.Properties | string,
769
- to?: posthog.Property,
770
- callback?: posthog.CaptureCallback
771
- ): posthog.Properties
772
-
773
- static toString(): string
774
- }
775
-
776
- export class sessionManager {
777
- /*
778
- * Allows you to manually reset the current session id. By default, the session id is reset after 30 minutes
779
- * of inactivity, but with this function, you can reset it earlier. This will also result in a new session recording.
780
- *
781
- *
782
- * ### Usage:
783
- *
784
- * posthog.sessionManager.resetSessionId()
785
- *
786
- */
787
- static resetSessionId(): void
788
- }
789
-
790
- export class featureFlags {
791
- static getFlags(): string[]
792
- static getFlagVariants(): Record<string, boolean | string>
793
-
794
- static reloadFeatureFlags(): void
795
-
796
- /*
797
- * Get feature flag variant for user
798
- *
799
- * ### Usage:
800
- *
801
- * if(posthog.getFeatureFlag('beta-feature')) { // do something }
802
- * if(posthog.getFeatureFlag('feature-with-variant') === 'some-value') { // do something }
803
- *
804
- * @param {Object|String} prop Key of the feature flag.
805
- * @param {Object|String} options (optional) If {send_event: false}, we won't send an $feature_flag_call event to PostHog.
806
- */
807
- static getFeatureFlag(key: string, options?: { send_event?: boolean }): boolean | string | undefined
808
-
809
- /*
810
- * See if feature flag is enabled for user.
811
- *
812
- * ### Usage:
813
- *
814
- * if(posthog.isFeatureEnabled('beta-feature')) { // do something }
815
- *
816
- * @param {Object|String} prop Key of the feature flag.
817
- * @param {Object|String} options (optional) If {send_event: false}, we won't send an $feature_flag_call event to PostHog.
818
- */
819
- static isFeatureEnabled(key: string, options?: { send_event?: boolean }): boolean
820
-
821
- /*
822
- * See if feature flags are available.
823
- *
824
- * ### Usage:
825
- *
826
- * posthog.onFeatureFlags(function(featureFlags) { // do something })
827
- *
828
- * @param {Function} [callback] The callback function will be called once the feature flags are ready. It'll return a list of feature flags enabled for the user.
829
- */
830
- static onFeatureFlags(
831
- callback: (flags: string[], variants: Record<string, boolean | string>) => void
832
- ): false | undefined
833
-
834
- /*
835
- * Override flags locally.
836
- *
837
- * ### Usage:
838
- *
839
- * - posthog.feature_flags.override(false)
840
- * - posthog.feature_flags.override(['beta-feature'])
841
- * - posthog.feature_flags.override({'beta-feature': 'variant', 'other-feature': True})
842
- *
843
- * @param {Function} [callback] The callback function will be called once the feature flags are ready. It'll return a list of feature flags enabled for the user.
844
- */
845
- static override(flags: false | string[] | Record<string, boolean | string>): void
846
- }
847
-
848
- export class feature_flags extends featureFlags {}
849
- }
850
-
851
- export class SentryIntegration implements Integration {
852
- constructor(posthog: posthog, organization?: string, projectId?: number, prefix?: string)
853
- name: string
854
- setupOnce(addGlobalEventProcessor: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void
946
+ clear_opt_in_out_capturing(options?: Partial<OptInOutCapturingOptions>): void;
947
+ debug(debug?: boolean): void;
948
+ decodeLZ64(input: string | null | undefined): string | null;
855
949
  }
856
950
 
857
- export type PostHog = typeof posthog
951
+ declare const posthog: PostHog;
858
952
 
859
- export default posthog
953
+ export { PostHog, posthog as default, posthog };