posthog-js 1.26.0 → 1.27.0-alpha3

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,457 @@
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 { Integration, 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
+ }
13
+
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
+ }
26
+
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
+ declare type CaptureCallback = (response: any, data: any) => void;
51
+ interface PostHogConfig {
52
+ api_host: string;
53
+ api_method: string;
54
+ api_transport: string;
55
+ token: string;
56
+ autocapture: boolean;
57
+ rageclick: boolean;
58
+ cross_subdomain_cookie: boolean;
59
+ persistence: 'localStorage' | 'cookie' | 'memory' | 'localStorage+cookie';
60
+ persistence_name: string;
61
+ cookie_name: string;
62
+ loaded: (posthog_instance: PostHog) => void;
63
+ store_google: boolean;
64
+ save_referrer: boolean;
65
+ test: boolean;
66
+ verbose: boolean;
67
+ img: boolean;
68
+ capture_pageview: boolean;
69
+ debug: boolean;
70
+ cookie_expiration: number;
71
+ upgrade: boolean;
72
+ disable_session_recording: boolean;
73
+ disable_persistence: boolean;
74
+ disable_cookie: boolean;
75
+ enable_recording_console_log: boolean;
76
+ secure_cookie: boolean;
77
+ ip: boolean;
78
+ opt_out_capturing_by_default: boolean;
79
+ opt_out_persistence_by_default: boolean;
80
+ opt_out_capturing_persistence_type: 'localStorage' | 'cookie';
81
+ opt_out_capturing_cookie_prefix: string | null;
82
+ respect_dnt: boolean;
83
+ property_blacklist: string[];
84
+ xhr_headers: {
85
+ [header_name: string]: string;
86
+ };
87
+ on_xhr_error: (failedRequest: XMLHttpRequest) => void;
88
+ inapp_protocol: string;
89
+ inapp_link_new_window: boolean;
90
+ request_batching: boolean;
91
+ sanitize_properties: ((properties: Properties, event_name: string) => Properties) | null;
92
+ properties_string_max_length: number;
93
+ session_recording: SessionRecordingOptions;
94
+ mask_all_element_attributes: boolean;
95
+ mask_all_text: boolean;
96
+ advanced_disable_decide: boolean;
97
+ advanced_disable_toolbar_metrics: boolean;
98
+ get_device_id: (uuid: string) => string;
99
+ name: string;
100
+ callback_fn: string;
101
+ _onCapture: (eventName: string, eventData: CaptureResult) => void;
102
+ _capture_metrics: boolean;
103
+ _capture_performance: boolean;
104
+ }
105
+ interface OptInOutCapturingOptions {
106
+ capture: (event: string, properties: Properties, options: CaptureOptions) => void;
107
+ capture_event_name: string;
108
+ capture_properties: Properties;
109
+ enable_persistence: boolean;
110
+ clear_persistence: boolean;
111
+ persistence_type: string;
112
+ cookie_prefix: string;
113
+ cookie_expiration: number;
114
+ cross_subdomain_cookie: boolean;
115
+ secure_cookie: boolean;
116
+ }
117
+ interface isFeatureEnabledOptions {
118
+ send_event: boolean;
119
+ }
120
+ interface SessionRecordingOptions {
121
+ blockClass?: string | RegExp;
122
+ blockSelector?: string | null;
123
+ ignoreClass?: string;
124
+ maskAllInputs?: boolean;
125
+ maskInputOptions?: MaskInputOptions;
126
+ maskInputFn?: ((text: string) => string) | null;
127
+ slimDOMOptions?: SlimDOMOptions | 'all' | true;
128
+ collectFonts?: boolean;
129
+ inlineStylesheet?: boolean;
130
+ }
131
+ declare enum Compression {
132
+ GZipJS = "gzip-js",
133
+ LZ64 = "lz64",
134
+ Base64 = "base64"
135
+ }
136
+ interface XHROptions {
137
+ transport?: 'XHR' | 'sendBeacon';
138
+ method?: 'POST' | 'GET';
139
+ urlQueryArgs?: {
140
+ compression: Compression;
141
+ };
142
+ verbose?: boolean;
143
+ blob?: boolean;
144
+ sendBeacon?: boolean;
145
+ }
146
+ interface CaptureOptions extends XHROptions {
147
+ $set?: Properties; /** used with $identify */
148
+ $set_once?: Properties; /** used with $identify */
149
+ _batchKey?: string; /** key of queue, e.g. 'sessionRecording' vs 'event' */
150
+ _metrics?: Properties;
151
+ _noTruncate?: boolean; /** if set, overrides and disables config.properties_string_max_length */
152
+ endpoint?: string; /** defaults to '/e/' */
153
+ send_instantly?: boolean; /** if set skips the batched queue */
154
+ }
155
+ interface RetryQueueElement {
156
+ retryAt: Date;
157
+ requestData: QueuedRequestData;
158
+ }
159
+ interface QueuedRequestData {
160
+ url: string;
161
+ data: Properties;
162
+ options: CaptureOptions;
163
+ headers?: Properties;
164
+ callback?: RequestCallback;
165
+ retriesPerformedSoFar?: number;
166
+ }
167
+ interface XHRParams extends QueuedRequestData {
168
+ captureMetrics: CaptureMetrics;
169
+ retryQueue: RetryQueue;
170
+ onXHRError: (req: XMLHttpRequest) => void;
171
+ }
172
+ interface DecideResponse {
173
+ status: number;
174
+ supportedCompression: Compression[];
175
+ config: {
176
+ enable_collect_everything: boolean;
177
+ };
178
+ custom_properties: AutoCaptureCustomProperty[];
179
+ featureFlags: Record<string, string | boolean>;
180
+ sessionRecording?: {
181
+ endpoint?: string;
182
+ };
183
+ editorParams: EditorParams;
184
+ toolbarVersion: 'toolbar'; /** deprecated, moved to editorParams */
185
+ isAuthenticated: boolean;
186
+ }
187
+ declare type FeatureFlagsCallback = (flags: string[], variants: Record<string, string | boolean>) => void;
188
+ interface AutoCaptureCustomProperty {
189
+ name: string;
190
+ css_selector: string;
191
+ event_selectors: string[];
192
+ }
193
+ interface CompressionData {
194
+ data: string;
195
+ compression?: Compression;
196
+ }
197
+ interface GDPROptions {
198
+ capture?: (event: string, properties: Properties, options: CaptureOptions) => void; /** function used for capturing a PostHog event to record the opt-in action */
199
+ captureEventName?: string; /** event name to be used for capturing the opt-in action */
200
+ captureProperties?: Properties; /** set of properties to be captured along with the opt-in action */
201
+ persistenceType?: string; /** persistence mechanism used - cookie or localStorage */
202
+ persistencePrefix?: string; /** [__ph_opt_in_out] - custom prefix to be used in the cookie/localstorage name */
203
+ cookieExpiration?: number; /** number of days until the opt-in cookie expires */
204
+ crossSubdomainCookie?: boolean; /** whether the opt-in cookie is set as cross-subdomain or not */
205
+ secureCookie?: boolean; /** whether the opt-in cookie is set as secure or not */
206
+ respectDnt?: boolean;
207
+ window?: Window;
208
+ }
209
+ declare type RequestCallback = (response: Record<string, any>, data?: Properties) => void;
210
+ interface PersistentStore {
211
+ is_supported: () => boolean;
212
+ error: (error: any) => void;
213
+ parse: (name: string) => any;
214
+ get: (name: string) => any;
215
+ set: (name: string, value: any, expire_days?: number | null, cross_subdomain?: boolean, secure?: boolean) => void;
216
+ remove: (name: string, cross_subdomain?: boolean) => void;
217
+ }
218
+ declare type Breaker = {};
219
+ declare type EventHandler = (event: Event) => boolean | void;
220
+ interface EditorParams {
221
+ jsURL?: string;
222
+ apiURL?: string;
223
+ toolbarVersion?: 'toolbar';
224
+ }
225
+ interface PostData {
226
+ buffer?: BlobPart;
227
+ compression?: Compression;
228
+ data?: string;
229
+ }
230
+ interface JSC {
231
+ (): void;
232
+ [key: string]: (response: any) => void;
233
+ }
234
+ declare type SnippetArrayItem = [method: string, ...args: any[]];
235
+
236
+ /**
237
+ * PostHog People Object
238
+ * @constructor
239
+ */
240
+ declare class PostHogPeople {
241
+ _posthog: PostHog;
242
+ set: (prop: string | Properties, to?: string, callback?: RequestCallback) => void;
243
+ set_once: (prop: string | Properties, to?: string, callback?: RequestCallback) => void;
244
+ constructor(posthog: PostHog);
245
+ toString(): string;
246
+ _send_request(data: Properties, callback?: RequestCallback): Properties;
247
+ _get_config<K extends keyof PostHogConfig>(conf_var: K): PostHogConfig[K];
248
+ _is_reserved_property(prop: string): boolean;
249
+ private set_action;
250
+ private set_once_action;
251
+ private apiActionParser;
252
+ }
253
+
254
+ /**
255
+ * PostHog Persistence Object
256
+ * @constructor
257
+ */
258
+ declare class PostHogPersistence {
259
+ props: Properties;
260
+ storage: PersistentStore;
261
+ campaign_params_saved: boolean;
262
+ name: string;
263
+ disabled: boolean | undefined;
264
+ secure: boolean | undefined;
265
+ expire_days: number | undefined;
266
+ default_expiry: number | undefined;
267
+ cross_subdomain: boolean | undefined;
268
+ constructor(config: PostHogConfig);
269
+ properties(): Properties;
270
+ load(): void;
271
+ save(): void;
272
+ remove(): void;
273
+ clear(): void;
274
+ /**
275
+ * @param {Object} props
276
+ * @param {*=} default_value
277
+ * @param {number=} days
278
+ */
279
+ register_once(props: Properties, default_value: any, days?: number): boolean;
280
+ /**
281
+ * @param {Object} props
282
+ * @param {number=} days
283
+ */
284
+ register(props: Properties, days?: number): boolean;
285
+ unregister(prop: string): void;
286
+ update_campaign_params(): void;
287
+ update_search_keyword(referrer: string): void;
288
+ update_referrer_info(referrer: string): void;
289
+ get_referrer_info(): Properties;
290
+ safe_merge(props: Properties): Properties;
291
+ update_config(config: PostHogConfig): void;
292
+ set_disabled(disabled: boolean): void;
293
+ set_cross_subdomain(cross_subdomain: boolean): void;
294
+ get_cross_subdomain(): boolean;
295
+ set_secure(secure: boolean): void;
296
+ set_event_timer(event_name: string, timestamp: number): void;
297
+ remove_event_timer(event_name: string): number;
298
+ }
299
+
300
+ declare class PostHogFeatureFlags {
301
+ instance: PostHog;
302
+ _override_warning: boolean;
303
+ flagCallReported: Record<string, boolean>;
304
+ featureFlagEventHandlers: FeatureFlagsCallback[];
305
+ reloadFeatureFlagsQueued: boolean;
306
+ reloadFeatureFlagsInAction: boolean;
307
+ $anon_distinct_id: string | undefined;
308
+ constructor(instance: PostHog);
309
+ getFlags(): string[];
310
+ getFlagVariants(): Record<string, string | boolean>;
311
+ /**
312
+ * Reloads feature flags asynchronously.
313
+ *
314
+ * Constraints:
315
+ *
316
+ * 1. Avoid parallel requests
317
+ * 2. Delay a few milliseconds after each reloadFeatureFlags call to batch subsequent changes together
318
+ * 3. Don't call this during initial load (as /decide will be called instead), see posthog-core.js
319
+ */
320
+ reloadFeatureFlags(): void;
321
+ setAnonymousDistinctId(anon_distinct_id: string): void;
322
+ setReloadingPaused(isPaused: boolean): void;
323
+ resetRequestQueue(): void;
324
+ _startReloadTimer(): void;
325
+ _reloadFeatureFlagsRequest(): void;
326
+ getFeatureFlag(key: string, options?: {
327
+ send_event?: boolean;
328
+ }): boolean | string;
329
+ isFeatureEnabled(key: string, options?: {
330
+ send_event?: boolean;
331
+ }): boolean;
332
+ addFeatureFlagsHandler(handler: FeatureFlagsCallback): void;
333
+ receivedFeatureFlags(response: DecideResponse): void;
334
+ override(flags: boolean | string[] | Record<string, string | boolean>): void;
335
+ onFeatureFlags(callback: FeatureFlagsCallback): void;
336
+ }
2
337
 
3
- import { EventProcessor, Hub, Integration } from '@sentry/types'
4
- import { MaskInputOptions, SlimDOMOptions } from 'rrweb-snapshot'
338
+ declare class SessionRecording {
339
+ instance: PostHog;
340
+ captureStarted: boolean;
341
+ snapshots: any[];
342
+ emit: boolean;
343
+ endpoint: string;
344
+ stopRrweb: listenerHandler | undefined;
345
+ windowId: string | null;
346
+ sessionId: string | null;
347
+ receivedDecide: boolean;
348
+ rrwebRecord: typeof record | undefined;
349
+ constructor(instance: PostHog);
350
+ startRecordingIfEnabled(): void;
351
+ started(): boolean;
352
+ stopRecording(): void;
353
+ isRecordingEnabled(): boolean;
354
+ afterDecideResponse(response: DecideResponse): void;
355
+ startCaptureAndTrySendingQueuedSnapshots(): void;
356
+ _startCapture(): void;
357
+ _updateWindowAndSessionIds(event: eventWithTime): void;
358
+ _onScriptLoaded(): void;
359
+ _captureSnapshot(properties: Properties): void;
360
+ }
5
361
 
6
- declare class posthog {
362
+ declare class Toolbar {
363
+ instance: PostHog;
364
+ constructor(instance: PostHog);
365
+ afterDecideResponse(response: DecideResponse): void;
366
+ /**
367
+ * To load the visual editor, we need an access token and other state. That state comes from one of three places:
368
+ * 1. In the URL hash params if the customer is using an old snippet
369
+ * 2. From session storage under the key `editorParams` if the editor was initialized on a previous page
370
+ */
371
+ maybeLoadEditor(location?: Location, localStorage?: Storage | undefined, history?: History): boolean;
372
+ _loadEditor(editorParams: EditorParams): boolean;
373
+ }
374
+
375
+ declare class RequestQueue extends RequestQueueScaffold {
376
+ captureMetrics: CaptureMetrics;
377
+ handlePollRequest: (url: string, data: Properties, options?: XHROptions) => void;
378
+ constructor(captureMetrics: CaptureMetrics, handlePollRequest: (url: string, data: Properties, options?: XHROptions) => void, pollInterval?: number);
379
+ enqueue(url: string, data: Properties, options: XHROptions): void;
380
+ poll(): void;
381
+ updateUnloadMetrics(): void;
382
+ unload(): void;
383
+ formatQueue(): Record<string, QueuedRequestData>;
384
+ }
385
+
386
+ declare class SessionIdManager {
387
+ persistence: PostHogPersistence;
388
+ _windowId: string | null | undefined;
389
+ _sessionId: string | null | undefined;
390
+ window_id_storage_key: string;
391
+ _sessionStartTimestamp: number | null;
392
+ _sessionActivityTimestamp: number | null;
393
+ constructor(config: Partial<PostHogConfig>, persistence: PostHogPersistence);
394
+ _setWindowId(windowId: string): void;
395
+ _getWindowId(): string | null;
396
+ _setSessionId(sessionId: string | null, sessionActivityTimestamp: number | null, sessionStartTimestamp: number | null): void;
397
+ _getSessionId(): [number, string, number];
398
+ resetSessionId(): void;
399
+ checkAndGetSessionAndWindowId(readOnly?: boolean, _timestamp?: number | null): {
400
+ sessionId: string;
401
+ windowId: string;
402
+ };
403
+ }
404
+
405
+ /**
406
+ * Integrate Sentry with PostHog. This will add a direct link to the person in Sentry, and an $exception event in PostHog
407
+ *
408
+ * ### Usage
409
+ *
410
+ * Sentry.init({
411
+ * dsn: 'https://example',
412
+ * integrations: [
413
+ * new posthog.SentryIntegration(posthog)
414
+ * ]
415
+ * })
416
+ *
417
+ * @param {Object} [posthog] The posthog object
418
+ * @param {string} [organization] Optional: The Sentry organization, used to send a direct link from PostHog to Sentry
419
+ * @param {Number} [projectId] Optional: The Sentry project id, used to send a direct link from PostHog to Sentry
420
+ * @param {string} [prefix] Optional: Url of a self-hosted sentry instance (default: https://sentry.io/organizations/)
421
+ */
422
+
423
+ declare class SentryIntegration implements Integration {
424
+ name: string;
425
+ setupOnce: (addGlobalEventProcessor: (callback: EventProcessor) => void, getCurrentHub: () => Hub) => void;
426
+ constructor(_posthog: PostHog, organization?: string, projectId?: number, prefix?: string);
427
+ }
428
+
429
+ /**
430
+ * PostHog Library Object
431
+ * @constructor
432
+ */
433
+ declare class PostHog {
434
+ __loaded: boolean;
435
+ config: PostHogConfig;
436
+ persistence: PostHogPersistence;
437
+ sessionManager: SessionIdManager;
438
+ people: PostHogPeople;
439
+ featureFlags: PostHogFeatureFlags;
440
+ feature_flags: PostHogFeatureFlags;
441
+ toolbar: Toolbar;
442
+ sessionRecording: SessionRecording | undefined;
443
+ _captureMetrics: CaptureMetrics;
444
+ _requestQueue: RequestQueue;
445
+ _retryQueue: RetryQueue;
446
+ _triggered_notifs: any;
447
+ compression: Partial<Record<Compression, boolean>>;
448
+ _jsc: JSC;
449
+ __captureHooks: ((eventName: string) => void)[];
450
+ __request_queue: [url: string, data: Record<string, any>, options: XHROptions, callback?: RequestCallback][];
451
+ __autocapture_enabled: boolean | undefined;
452
+ decideEndpointWasHit: boolean;
453
+ SentryIntegration: typeof SentryIntegration;
454
+ constructor();
7
455
  /**
8
456
  * This function initializes a new instance of the PostHog capturing object.
9
457
  * All new instances are added to the main posthog object as sub properties (such as
@@ -20,14 +468,51 @@ declare class posthog {
20
468
  * @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
469
  * @param {String} [name] The name for the new posthog instance that you want created
22
470
  */
23
- static init(token: string, config?: posthog.Config, name?: string): posthog
24
-
471
+ init(token: string, config?: Partial<PostHogConfig>, name?: string): PostHog | void;
472
+ _init(token: string, config?: Partial<PostHogConfig>, name?: string): void;
473
+ _loaded(): void;
474
+ _start_queue_if_opted_in(): void;
475
+ _dom_loaded(): void;
25
476
  /**
26
- * Clears super properties and generates a new random distinct_id for this instance.
27
- * Useful for clearing data when a user logs out.
477
+ * _prepare_callback() should be called by callers of _send_request for use
478
+ * as the callback argument.
479
+ *
480
+ * If there is no callback, this returns null.
481
+ * If we are going to make XHR/XDR requests, this returns a function.
482
+ * If we are going to use script tags, this returns a string to use as the
483
+ * callback GET param.
28
484
  */
29
- static reset(reset_device_id?: boolean): void
30
-
485
+ _prepare_callback(callback?: RequestCallback, data?: Properties): RequestCallback | null | string;
486
+ _handle_unload(): void;
487
+ _handle_queued_event(url: string, data: Record<string, any>, options?: XHROptions): void;
488
+ __compress_and_send_json_request(url: string, jsonData: string, options: XHROptions, callback?: RequestCallback): void;
489
+ _send_request(url: string, data: Record<string, any>, options: XHROptions, callback?: RequestCallback): void;
490
+ /**
491
+ * _execute_array() deals with processing any posthog function
492
+ * calls that were called before the PostHog library were loaded
493
+ * (and are thus stored in an array so they can be called later)
494
+ *
495
+ * Note: we fire off all the posthog function calls && user defined
496
+ * functions BEFORE we fire off posthog capturing calls. This is so
497
+ * identify/register/set_config calls can properly modify early
498
+ * capturing calls.
499
+ *
500
+ * @param {Array} array
501
+ */
502
+ _execute_array(array: SnippetArrayItem[]): void;
503
+ /**
504
+ * push() keeps the standard async-array-push
505
+ * behavior around after the lib is loaded.
506
+ * This is only useful for external integrations that
507
+ * do not wish to rely on our convenience methods
508
+ * (created in the snippet).
509
+ *
510
+ * ### Usage:
511
+ * posthog.push(['register', { a: 'b' }]);
512
+ *
513
+ * @param {Array} item A [function_name, args...] array to be executed
514
+ */
515
+ push(item: SnippetArrayItem): void;
31
516
  /**
32
517
  * Capture an event. This is the most important and
33
518
  * frequently used PostHog function.
@@ -45,12 +530,10 @@ declare class posthog {
45
530
  * @param {Object} [options] Optional configuration for this capture request.
46
531
  * @param {String} [options.transport] Transport method for network request ('XHR' or 'sendBeacon').
47
532
  */
48
- static capture(
49
- event_name: string,
50
- properties?: posthog.Properties,
51
- options?: { transport: 'XHR' | 'sendBeacon' }
52
- ): posthog.CaptureResult
53
-
533
+ capture(event_name: string, properties?: Properties | null, options?: CaptureOptions): CaptureResult | void;
534
+ _addCaptureHook(callback: (eventName: string) => void): void;
535
+ _invokeCaptureHooks(eventName: string, eventData: CaptureResult): void;
536
+ _calculate_event_properties(event_name: string, event_properties: Properties, start_timestamp: number): Properties;
54
537
  /**
55
538
  * Register a set of super properties, which are included with all
56
539
  * events. This will overwrite previous super property values.
@@ -69,8 +552,7 @@ declare class posthog {
69
552
  * @param {Object} properties An associative array of properties to store about the user
70
553
  * @param {Number} [days] How many days since the user's last visit to store the super properties
71
554
  */
72
- static register(properties: posthog.Properties, days?: number): void
73
-
555
+ register(properties: Properties, days?: number): void;
74
556
  /**
75
557
  * Register a set of super properties only once. This will not
76
558
  * overwrite previous super property values, unlike register().
@@ -91,15 +573,20 @@ declare class posthog {
91
573
  * @param {*} [default_value] Value to override if already set in super properties (ex: 'False') Default: 'None'
92
574
  * @param {Number} [days] How many days since the users last visit to store the super properties
93
575
  */
94
- static register_once(properties: posthog.Properties, default_value?: posthog.Property, days?: number): void
95
-
576
+ register_once(properties: Properties, default_value?: Property, days?: number): void;
96
577
  /**
97
578
  * Delete a super property stored with the current user.
98
579
  *
99
580
  * @param {String} property The name of the super property to remove
100
581
  */
101
- static unregister(property: string): void
102
-
582
+ unregister(property: string): void;
583
+ _register_single(prop: string, value: Property): void;
584
+ getFeatureFlag(key: string, options?: {
585
+ send_event?: boolean;
586
+ }): boolean | string | undefined;
587
+ isFeatureEnabled(key: string, options?: isFeatureEnabledOptions): boolean;
588
+ reloadFeatureFlags(): void;
589
+ onFeatureFlags(callback: (flags: string[], variants: Record<string, boolean | string>) => void): void;
103
590
  /**
104
591
  * Identify a user with a unique ID instead of a PostHog
105
592
  * randomly generated distinct_id. If the method is never called,
@@ -133,16 +620,44 @@ declare class posthog {
133
620
  * practice to call identify on the original, anonymous ID
134
621
  * right after you've aliased it.
135
622
  *
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
623
+ * @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.
624
+ * @param {Object} [userPropertiesToSet] Optional: An associative array of properties to store about the user
138
625
  * @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
626
  */
140
- static identify(
141
- unique_id?: string,
142
- userPropertiesToSet?: posthog.Properties,
143
- userPropertiesToSetOnce?: posthog.Properties
144
- ): void
145
-
627
+ identify(new_distinct_id?: string, userPropertiesToSet?: Properties, userPropertiesToSetOnce?: Properties): void;
628
+ /**
629
+ * Alpha feature: don't use unless you know what you're doing!
630
+ *
631
+ * Sets group analytics information for subsequent events and reloads feature flags.
632
+ *
633
+ * @param {String} groupType Group type (example: 'organization')
634
+ * @param {String} groupKey Group key (example: 'org::5')
635
+ * @param {Object} groupPropertiesToSet Optional properties to set for group
636
+ */
637
+ group(groupType: string, groupKey: string, groupPropertiesToSet?: Properties): void;
638
+ /**
639
+ * Clears super properties and generates a new random distinct_id for this instance.
640
+ * Useful for clearing data when a user logs out.
641
+ */
642
+ reset(reset_device_id?: boolean): void;
643
+ /**
644
+ * Returns the current distinct id of the user. This is either the id automatically
645
+ * generated by the library or the id that has been passed by a call to identify().
646
+ *
647
+ * ### Notes:
648
+ *
649
+ * get_distinct_id() can only be called after the PostHog library has finished loading.
650
+ * init() has a loaded function available to handle this automatically. For example:
651
+ *
652
+ * // set distinct_id after the posthog library has loaded
653
+ * posthog.init('YOUR PROJECT TOKEN', {
654
+ * loaded: function(posthog) {
655
+ * distinct_id = posthog.get_distinct_id();
656
+ * }
657
+ * });
658
+ */
659
+ get_distinct_id(): string;
660
+ getGroups(): Record<string, any>;
146
661
  /**
147
662
  * Create an alias, which PostHog will use to link two distinct_ids going forward (not retroactively).
148
663
  * Multiple aliases can map to the same original ID, but not vice-versa. Aliases can also be chained - the
@@ -164,35 +679,25 @@ declare class posthog {
164
679
  * @param {String} alias A unique identifier that you want to use for this user in the future.
165
680
  * @param {String} [original] The current identifier being used for this user.
166
681
  */
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
-
682
+ alias(alias: string, original?: string): CaptureResult | void | number;
187
683
  /**
188
684
  * Update the configuration of a posthog library instance.
189
685
  *
190
686
  * The default config is:
191
687
  *
192
688
  * {
689
+ * // Posthog host
690
+ * api_host: 'https://app.posthog.com',
691
+ *
193
692
  * // HTTP method for capturing requests
194
693
  * api_method: 'POST'
195
694
  *
695
+ * // Automatically capture clicks, form submissions and change events
696
+ * autocapture: true
697
+ *
698
+ * // Capture rage clicks (beta) - useful for session recording
699
+ * rageclick: false
700
+ *
196
701
  * // transport for sending requests ('XHR' or 'sendBeacon')
197
702
  * // NB: sendBeacon should only be used for scenarios such as
198
703
  * // page unload where a "best-effort" attempt to send is
@@ -202,12 +707,6 @@ declare class posthog {
202
707
  * // batching or retry mechanisms.
203
708
  * api_transport: 'XHR'
204
709
  *
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
710
  * // super properties cookie expiration (in days)
212
711
  * cookie_expiration: 365
213
712
  *
@@ -266,6 +765,9 @@ declare class posthog {
266
765
  * // so make sure you set it when you create the library.
267
766
  * upgrade: false
268
767
  *
768
+ * // if this is true, session recording is always disabled.
769
+ * disable_session_recording: false,
770
+ *
269
771
  * // extra HTTP request headers to set for each API request, in
270
772
  * // the format {'Header-Name': value}
271
773
  * xhr_headers: {}
@@ -289,7 +791,6 @@ declare class posthog {
289
791
  * maskInputFn: null,
290
792
  * slimDOMOptions: {},
291
793
  * collectFonts: false
292
- * inlineStylesheet: true
293
794
  * }
294
795
  *
295
796
  * // prevent autocapture from capturing any attribute names on elements
@@ -298,16 +799,6 @@ declare class posthog {
298
799
  * // prevent autocapture from capturing textContent on all elements
299
800
  * mask_all_text: false
300
801
  *
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
802
  * // Anonymous users get a random UUID as their device by default.
312
803
  * // This option allows overriding that option.
313
804
  * get_device_id: (uuid) => uuid
@@ -316,13 +807,26 @@ declare class posthog {
316
807
  *
317
808
  * @param {Object} config A dictionary of new configuration values to update
318
809
  */
319
- static set_config(config: posthog.Config): void
320
-
810
+ set_config(config: Partial<PostHogConfig>): void;
811
+ /**
812
+ * turns session recording on, and updates the config option
813
+ * disable_session_recording to false
814
+ */
815
+ startSessionRecording(): void;
816
+ /**
817
+ * turns session recording off, and updates the config option
818
+ * disable_session_recording to true
819
+ */
820
+ stopSessionRecording(): void;
821
+ /**
822
+ * returns a boolean indicating whether session recording
823
+ * is currently running
824
+ */
825
+ sessionRecordingStarted(): boolean;
321
826
  /**
322
827
  * returns the current config object for the library.
323
828
  */
324
- static get_config<T extends keyof posthog.Config>(prop_name: T): posthog.Config[T]
325
-
829
+ get_config<K extends keyof PostHogConfig>(prop_name: K): PostHogConfig[K];
326
830
  /**
327
831
  * Returns the value of the super property named property_name. If no such
328
832
  * property is set, get_property() will return the undefined value.
@@ -341,50 +845,17 @@ declare class posthog {
341
845
  *
342
846
  * @param {String} property_name The name of the super property you want to retrieve
343
847
  */
344
- static get_property(property_name: string): posthog.Property | undefined
345
-
848
+ get_property(property_name: string): Property | undefined;
849
+ toString(): string;
850
+ _gdpr_init(): void;
346
851
  /**
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
- * });
852
+ * Enable or disable persistence based on options
853
+ * only enable/disable if persistence is not already in this state
854
+ * @param {boolean} [options.clear_persistence] If true, will delete all data stored by the sdk in persistence and disable it
855
+ * @param {boolean} [options.enable_persistence] If true, will re-enable sdk persistence
361
856
  */
362
- static get_distinct_id(): string
363
-
364
- /**
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)
385
- */
386
- static opt_out_capturing(options?: posthog.OptInOutCapturingOptions): void
387
-
857
+ _gdpr_update_persistence(options: Partial<OptInOutCapturingOptions>): void;
858
+ _gdpr_call_func<R = any>(func: (token: string, options: GDPROptions) => R, options?: Partial<OptInOutCapturingOptions>): R;
388
859
  /**
389
860
  * Opt the user in to data capturing and cookies/localstorage for this PostHog instance
390
861
  *
@@ -414,23 +885,30 @@ declare class posthog {
414
885
  * @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
886
  * @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
887
  */
417
- static opt_in_capturing(options?: posthog.OptInOutCapturingOptions): void
418
-
888
+ opt_in_capturing(options?: Partial<OptInOutCapturingOptions>): void;
419
889
  /**
420
- * Check whether the user has opted out of data capturing and cookies/localstorage for this PostHog instance
890
+ * Opt the user out of data capturing and cookies/localstorage for this PostHog instance
421
891
  *
422
892
  * ### Usage
423
893
  *
424
- * const has_opted_out = posthog.has_opted_out_capturing();
425
- * // use has_opted_out value
894
+ * // opt user out
895
+ * posthog.opt_out_capturing();
896
+ *
897
+ * // opt user out with different cookie configuration from PostHog instance
898
+ * posthog.opt_out_capturing({
899
+ * cookie_expiration: 30,
900
+ * secure_cookie: true
901
+ * });
426
902
  *
427
903
  * @param {Object} [options] A dictionary of config options to override
904
+ * @param {boolean} [options.clear_persistence=true] If true, will delete all data stored by the sdk in persistence
428
905
  * @param {string} [options.persistence_type=localStorage] Persistence mechanism used - cookie or localStorage - falls back to cookie if localStorage is unavailable
429
906
  * @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
907
+ * @param {Number} [options.cookie_expiration] Number of days until the opt-in cookie expires (overrides value specified in this PostHog instance's config)
908
+ * @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)
909
+ * @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
910
  */
432
- static has_opted_out_capturing(options?: posthog.HasOptedInOutCapturingOptions): boolean
433
-
911
+ opt_out_capturing(options?: Partial<OptInOutCapturingOptions>): void;
434
912
  /**
435
913
  * Check whether the user has opted in to data capturing and cookies/localstorage for this PostHog instance
436
914
  *
@@ -444,8 +922,21 @@ declare class posthog {
444
922
  * @param {string} [options.cookie_prefix=__ph_opt_in_out] Custom prefix to be used in the cookie/localstorage name
445
923
  * @returns {boolean} current opt-in status
446
924
  */
447
- static has_opted_in_capturing(options?: posthog.HasOptedInOutCapturingOptions): boolean
448
-
925
+ has_opted_in_capturing(options?: Partial<OptInOutCapturingOptions>): boolean;
926
+ /**
927
+ * Check whether the user has opted out of data capturing and cookies/localstorage for this PostHog instance
928
+ *
929
+ * ### Usage
930
+ *
931
+ * const has_opted_out = posthog.has_opted_out_capturing();
932
+ * // use has_opted_out value
933
+ *
934
+ * @param {Object} [options] A dictionary of config options to override
935
+ * @param {string} [options.persistence_type=localStorage] Persistence mechanism used - cookie or localStorage - falls back to cookie if localStorage is unavailable
936
+ * @param {string} [options.cookie_prefix=__ph_opt_in_out] Custom prefix to be used in the cookie/localstorage name
937
+ * @returns {boolean} current opt-out status
938
+ */
939
+ has_opted_out_capturing(options?: Partial<OptInOutCapturingOptions>): boolean;
449
940
  /**
450
941
  * Clear the user's opt in/out status of data capturing and cookies/localstorage for this PostHog instance
451
942
  *
@@ -469,391 +960,11 @@ declare class posthog {
469
960
  * @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
961
  * @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
962
  */
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
963
+ clear_opt_in_out_capturing(options?: Partial<OptInOutCapturingOptions>): void;
964
+ debug(debug?: boolean): void;
965
+ decodeLZ64(input: string | null | undefined): string | null;
855
966
  }
856
967
 
857
- export type PostHog = typeof posthog
968
+ declare const posthog: PostHog;
858
969
 
859
- export default posthog
970
+ export { AutoCaptureCustomProperty, Breaker, CaptureCallback, CaptureOptions, CaptureResult, Compression, CompressionData, DecideResponse, EditorParams, EventHandler, FeatureFlagsCallback, GDPROptions, JSC, OptInOutCapturingOptions, PersistentStore, PostData, PostHog, PostHogConfig, Properties, Property, QueuedRequestData, RequestCallback, RetryQueueElement, SessionRecordingOptions, SnippetArrayItem, XHROptions, XHRParams, posthog as default, isFeatureEnabledOptions, posthog };