posthog-js 1.76.0 → 1.77.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/dist/array.full.js +2 -2
  2. package/dist/array.full.js.map +1 -1
  3. package/dist/array.js +2 -2
  4. package/dist/array.js.map +1 -1
  5. package/dist/es.js +2 -2
  6. package/dist/es.js.map +1 -1
  7. package/dist/module.d.ts +38 -6
  8. package/dist/module.js +2 -2
  9. package/dist/module.js.map +1 -1
  10. package/lib/package.json +8 -6
  11. package/lib/src/autocapture-utils.d.ts +15 -0
  12. package/lib/src/autocapture-utils.js +303 -0
  13. package/lib/src/autocapture-utils.js.map +1 -0
  14. package/lib/src/autocapture.d.ts +27 -0
  15. package/lib/src/autocapture.js +290 -0
  16. package/lib/src/autocapture.js.map +1 -0
  17. package/lib/src/base-request-queue.d.ts +12 -0
  18. package/lib/src/base-request-queue.js +33 -0
  19. package/lib/src/base-request-queue.js.map +1 -0
  20. package/lib/src/compression.d.ts +3 -0
  21. package/lib/src/compression.js +35 -0
  22. package/lib/src/compression.js.map +1 -0
  23. package/lib/src/config.d.ts +5 -0
  24. package/lib/src/config.js +9 -0
  25. package/lib/src/config.js.map +1 -0
  26. package/lib/src/constants.d.ts +19 -0
  27. package/lib/src/constants.js +41 -0
  28. package/lib/src/constants.js.map +1 -0
  29. package/lib/src/decide.d.ts +8 -0
  30. package/lib/src/decide.js +118 -0
  31. package/lib/src/decide.js.map +1 -0
  32. package/lib/src/extensions/cloud.d.ts +1 -0
  33. package/lib/src/extensions/cloud.js +2 -0
  34. package/lib/src/extensions/cloud.js.map +1 -0
  35. package/lib/src/extensions/exceptions/error-conversion.d.ts +26 -0
  36. package/lib/src/extensions/exceptions/error-conversion.js +204 -0
  37. package/lib/src/extensions/exceptions/error-conversion.js.map +1 -0
  38. package/lib/src/extensions/exceptions/exception-autocapture.d.ts +24 -0
  39. package/lib/src/extensions/exceptions/exception-autocapture.js +164 -0
  40. package/lib/src/extensions/exceptions/exception-autocapture.js.map +1 -0
  41. package/lib/src/extensions/exceptions/stack-trace.d.ts +31 -0
  42. package/lib/src/extensions/exceptions/stack-trace.js +259 -0
  43. package/lib/src/extensions/exceptions/stack-trace.js.map +1 -0
  44. package/lib/src/extensions/exceptions/type-checking.d.ts +10 -0
  45. package/lib/src/extensions/exceptions/type-checking.js +43 -0
  46. package/lib/src/extensions/exceptions/type-checking.js.map +1 -0
  47. package/lib/src/extensions/rageclick.d.ts +10 -0
  48. package/lib/src/extensions/rageclick.js +33 -0
  49. package/lib/src/extensions/rageclick.js.map +1 -0
  50. package/lib/src/extensions/segment-integration.d.ts +44 -0
  51. package/lib/src/extensions/segment-integration.js +34 -0
  52. package/lib/src/extensions/segment-integration.js.map +1 -0
  53. package/lib/src/extensions/sentry-integration.d.ts +30 -0
  54. package/lib/src/extensions/sentry-integration.js +63 -0
  55. package/lib/src/extensions/sentry-integration.js.map +1 -0
  56. package/lib/src/extensions/sessionrecording-utils.d.ts +67 -0
  57. package/lib/src/extensions/sessionrecording-utils.js +192 -0
  58. package/lib/src/extensions/sessionrecording-utils.js.map +1 -0
  59. package/lib/src/extensions/sessionrecording.d.ts +45 -0
  60. package/lib/src/extensions/sessionrecording.js +430 -0
  61. package/lib/src/extensions/sessionrecording.js.map +1 -0
  62. package/lib/src/extensions/toolbar.d.ts +18 -0
  63. package/lib/src/extensions/toolbar.js +151 -0
  64. package/lib/src/extensions/toolbar.js.map +1 -0
  65. package/lib/src/extensions/web-performance.d.ts +20 -0
  66. package/lib/src/extensions/web-performance.js +245 -0
  67. package/lib/src/extensions/web-performance.js.map +1 -0
  68. package/lib/src/gdpr-utils.d.ts +80 -0
  69. package/lib/src/gdpr-utils.js +236 -0
  70. package/lib/src/gdpr-utils.js.map +1 -0
  71. package/lib/src/loader-globals-full.d.ts +1 -0
  72. package/lib/src/loader-globals-full.js +5 -0
  73. package/lib/src/loader-globals-full.js.map +1 -0
  74. package/lib/src/loader-globals.d.ts +1 -0
  75. package/lib/src/loader-globals.js +3 -0
  76. package/lib/src/loader-globals.js.map +1 -0
  77. package/lib/src/loader-module.d.ts +4 -0
  78. package/lib/src/loader-module.js +6 -0
  79. package/lib/src/loader-module.js.map +1 -0
  80. package/lib/src/loader-recorder-v2.d.ts +2 -0
  81. package/lib/src/loader-recorder-v2.js +15 -0
  82. package/lib/src/loader-recorder-v2.js.map +1 -0
  83. package/lib/src/loader-recorder.d.ts +2 -0
  84. package/lib/src/loader-recorder.js +15 -0
  85. package/lib/src/loader-recorder.js.map +1 -0
  86. package/lib/src/page-view.d.ts +38 -0
  87. package/lib/src/page-view.js +127 -0
  88. package/lib/src/page-view.js.map +1 -0
  89. package/lib/src/posthog-core.d.ts +701 -0
  90. package/lib/src/posthog-core.js +1916 -0
  91. package/lib/src/posthog-core.js.map +1 -0
  92. package/lib/src/posthog-featureflags.d.ts +70 -0
  93. package/lib/src/posthog-featureflags.js +438 -0
  94. package/lib/src/posthog-featureflags.js.map +1 -0
  95. package/lib/src/posthog-persistence.d.ts +57 -0
  96. package/lib/src/posthog-persistence.js +256 -0
  97. package/lib/src/posthog-persistence.js.map +1 -0
  98. package/lib/src/posthog-surveys.d.ts +57 -0
  99. package/lib/src/posthog-surveys.js +76 -0
  100. package/lib/src/posthog-surveys.js.map +1 -0
  101. package/lib/src/rate-limiter.d.ts +5 -0
  102. package/lib/src/rate-limiter.js +66 -0
  103. package/lib/src/rate-limiter.js.map +1 -0
  104. package/lib/src/request-queue.d.ts +10 -0
  105. package/lib/src/request-queue.js +146 -0
  106. package/lib/src/request-queue.js.map +1 -0
  107. package/lib/src/retry-queue.d.ts +28 -0
  108. package/lib/src/retry-queue.js +198 -0
  109. package/lib/src/retry-queue.js.map +1 -0
  110. package/lib/src/send-request.d.ts +6 -0
  111. package/lib/src/send-request.js +125 -0
  112. package/lib/src/send-request.js.map +1 -0
  113. package/lib/src/sessionid.d.ts +28 -0
  114. package/lib/src/sessionid.js +205 -0
  115. package/lib/src/sessionid.js.map +1 -0
  116. package/lib/src/storage.d.ts +7 -0
  117. package/lib/src/storage.js +291 -0
  118. package/lib/src/storage.js.map +1 -0
  119. package/lib/src/types.d.ts +294 -0
  120. package/lib/src/types.js +6 -0
  121. package/lib/src/types.js.map +1 -0
  122. package/lib/src/utils.d.ts +89 -0
  123. package/lib/src/utils.js +868 -0
  124. package/lib/src/utils.js.map +1 -0
  125. package/lib/src/uuidv7.d.ts +42 -0
  126. package/lib/src/uuidv7.js +228 -0
  127. package/lib/src/uuidv7.js.map +1 -0
  128. package/package.json +8 -6
  129. package/CHANGELOG.md +0 -1145
@@ -0,0 +1,701 @@
1
+ import { PostHogFeatureFlags } from './posthog-featureflags';
2
+ import { PostHogPersistence } from './posthog-persistence';
3
+ import { SessionRecording } from './extensions/sessionrecording';
4
+ import { WebPerformanceObserver } from './extensions/web-performance';
5
+ import { Toolbar } from './extensions/toolbar';
6
+ import { RequestQueue } from './request-queue';
7
+ import { RetryQueue } from './retry-queue';
8
+ import { SessionIdManager } from './sessionid';
9
+ import { AutocaptureConfig, CaptureOptions, CaptureResult, Compression, EarlyAccessFeatureCallback, GDPROptions, isFeatureEnabledOptions, JSC, JsonType, OptInOutCapturingOptions, PostHogConfig, Properties, Property, RequestCallback, SessionIdChangedCallback, SnippetArrayItem, ToolbarParams, XHROptions } from './types';
10
+ import { SentryIntegration } from './extensions/sentry-integration';
11
+ import { PageViewManager } from './page-view';
12
+ import { ExceptionObserver } from './extensions/exceptions/exception-autocapture';
13
+ import { PostHogSurveys, SurveyCallback } from './posthog-surveys';
14
+ import { RateLimiter } from './rate-limiter';
15
+ /**
16
+ * PostHog Library Object
17
+ * @constructor
18
+ */
19
+ export declare class PostHog {
20
+ __loaded: boolean;
21
+ __loaded_recorder_version: 'v1' | 'v2' | undefined;
22
+ config: PostHogConfig;
23
+ persistence: PostHogPersistence;
24
+ rateLimiter: RateLimiter;
25
+ sessionPersistence: PostHogPersistence;
26
+ sessionManager: SessionIdManager;
27
+ pageViewManager: PageViewManager;
28
+ featureFlags: PostHogFeatureFlags;
29
+ surveys: PostHogSurveys;
30
+ toolbar: Toolbar;
31
+ sessionRecording: SessionRecording | undefined;
32
+ webPerformance: WebPerformanceObserver | undefined;
33
+ exceptionAutocapture: ExceptionObserver | undefined;
34
+ _requestQueue: RequestQueue;
35
+ _retryQueue: RetryQueue;
36
+ _triggered_notifs: any;
37
+ compression: Partial<Record<Compression, boolean>>;
38
+ _jsc: JSC;
39
+ __captureHooks: ((eventName: string) => void)[];
40
+ __request_queue: [url: string, data: Record<string, any>, options: XHROptions, callback?: RequestCallback][];
41
+ __autocapture: boolean | AutocaptureConfig | undefined;
42
+ decideEndpointWasHit: boolean;
43
+ SentryIntegration: typeof SentryIntegration;
44
+ segmentIntegration: () => any;
45
+ /** DEPRECATED: We keep this to support existing usage but now one should just call .setPersonProperties */
46
+ people: {
47
+ set: (prop: string | Properties, to?: string, callback?: RequestCallback) => void;
48
+ set_once: (prop: string | Properties, to?: string, callback?: RequestCallback) => void;
49
+ };
50
+ constructor();
51
+ /**
52
+ * This function initializes a new instance of the PostHog capturing object.
53
+ * All new instances are added to the main posthog object as sub properties (such as
54
+ * posthog.library_name) and also returned by this function. To define a
55
+ * second instance on the page, you would call:
56
+ *
57
+ * posthog.init('new token', { your: 'config' }, 'library_name');
58
+ *
59
+ * and use it like so:
60
+ *
61
+ * posthog.library_name.capture(...);
62
+ *
63
+ * @param {String} token Your PostHog API token
64
+ * @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>.
65
+ * @param {String} [name] The name for the new posthog instance that you want created
66
+ */
67
+ init(token: string, config?: Partial<PostHogConfig>, name?: string): PostHog | void;
68
+ _init(token: string, config?: Partial<PostHogConfig>, name?: string, initComplete?: (instance: PostHog) => void): void;
69
+ _loaded(): void;
70
+ _start_queue_if_opted_in(): void;
71
+ _dom_loaded(): void;
72
+ /**
73
+ * _prepare_callback() should be called by callers of _send_request for use
74
+ * as the callback argument.
75
+ *
76
+ * If there is no callback, this returns null.
77
+ * If we are going to make XHR/XDR requests, this returns a function.
78
+ * If we are going to use script tags, this returns a string to use as the
79
+ * callback GET param.
80
+ */
81
+ _prepare_callback(callback?: RequestCallback, data?: Properties): RequestCallback | null | string;
82
+ _handle_unload(): void;
83
+ _handle_queued_event(url: string, data: Record<string, any>, options?: XHROptions): void;
84
+ __compress_and_send_json_request(url: string, jsonData: string, options: XHROptions, callback?: RequestCallback): void;
85
+ _send_request(url: string, data: Record<string, any>, options: CaptureOptions, callback?: RequestCallback): void;
86
+ /**
87
+ * _execute_array() deals with processing any posthog function
88
+ * calls that were called before the PostHog library were loaded
89
+ * (and are thus stored in an array so they can be called later)
90
+ *
91
+ * Note: we fire off all the posthog function calls && user defined
92
+ * functions BEFORE we fire off posthog capturing calls. This is so
93
+ * identify/register/set_config calls can properly modify early
94
+ * capturing calls.
95
+ *
96
+ * @param {Array} array
97
+ */
98
+ _execute_array(array: SnippetArrayItem[]): void;
99
+ _hasBootstrappedFeatureFlags(): boolean;
100
+ /**
101
+ * push() keeps the standard async-array-push
102
+ * behavior around after the lib is loaded.
103
+ * This is only useful for external integrations that
104
+ * do not wish to rely on our convenience methods
105
+ * (created in the snippet).
106
+ *
107
+ * ### Usage:
108
+ * posthog.push(['register', { a: 'b' }]);
109
+ *
110
+ * @param {Array} item A [function_name, args...] array to be executed
111
+ */
112
+ push(item: SnippetArrayItem): void;
113
+ captureException(exception: Error, properties?: Properties): void;
114
+ /**
115
+ * Capture an event. This is the most important and
116
+ * frequently used PostHog function.
117
+ *
118
+ * ### Usage:
119
+ *
120
+ * // capture an event named 'Registered'
121
+ * posthog.capture('Registered', {'Gender': 'Male', 'Age': 21});
122
+ *
123
+ * // capture an event using navigator.sendBeacon
124
+ * posthog.capture('Left page', {'duration_seconds': 35}, {transport: 'sendBeacon'});
125
+ *
126
+ * @param {String} event_name The name of the event. This can be anything the user does - 'Button Click', 'Sign Up', 'Item Purchased', etc.
127
+ * @param {Object} [properties] A set of properties to include with the event you're sending. These describe the user who did the event or details about the event itself.
128
+ * @param {Object} [options] Optional configuration for this capture request.
129
+ * @param {String} [options.transport] Transport method for network request ('XHR' or 'sendBeacon').
130
+ * @param {Date} [options.timestamp] Timestamp is a Date object. If not set, it'll automatically be set to the current time.
131
+ */
132
+ capture(event_name: string, properties?: Properties | null, options?: CaptureOptions): CaptureResult | void;
133
+ _addCaptureHook(callback: (eventName: string) => void): void;
134
+ _invokeCaptureHooks(eventName: string, eventData: CaptureResult): void;
135
+ _calculate_event_properties(event_name: string, event_properties: Properties): Properties;
136
+ /**
137
+ * Register a set of super properties, which are included with all
138
+ * events. This will overwrite previous super property values, except
139
+ * for session properties (see `register_for_session(properties)`).
140
+ *
141
+ * ### Usage:
142
+ *
143
+ * // register 'Gender' as a super property
144
+ * posthog.register({'Gender': 'Female'});
145
+ *
146
+ * // register several super properties when a user signs up
147
+ * posthog.register({
148
+ * 'Email': 'jdoe@example.com',
149
+ * 'Account Type': 'Free'
150
+ * });
151
+ *
152
+ * // Display the properties
153
+ * console.log(posthog.persistence.properties())
154
+ *
155
+ * @param {Object} properties An associative array of properties to store about the user
156
+ * @param {Number} [days] How many days since the user's last visit to store the super properties
157
+ */
158
+ register(properties: Properties, days?: number): void;
159
+ /**
160
+ * Register a set of super properties only once. These will not
161
+ * overwrite previous super property values, unlike register().
162
+ *
163
+ * ### Usage:
164
+ *
165
+ * // register a super property for the first time only
166
+ * posthog.register_once({
167
+ * 'First Login Date': new Date().toISOString()
168
+ * });
169
+ *
170
+ * // Display the properties
171
+ * console.log(posthog.persistence.properties())
172
+ *
173
+ * ### Notes:
174
+ *
175
+ * If default_value is specified, current super properties
176
+ * with that value will be overwritten.
177
+ *
178
+ * @param {Object} properties An associative array of properties to store about the user
179
+ * @param {*} [default_value] Value to override if already set in super properties (ex: 'False') Default: 'None'
180
+ * @param {Number} [days] How many days since the users last visit to store the super properties
181
+ */
182
+ register_once(properties: Properties, default_value?: Property, days?: number): void;
183
+ /**
184
+ * Register a set of super properties, which are included with all events, but only
185
+ * for THIS SESSION. These will overwrite all other super property values.
186
+ *
187
+ * Unlike regular super properties, which last in LocalStorage for a long time,
188
+ * session super properties get cleared after a session ends.
189
+ *
190
+ * ### Usage:
191
+ *
192
+ * // register on all events this session
193
+ * posthog.register_for_session({'referer': customGetReferer()});
194
+ *
195
+ * // register several session super properties when a user signs up
196
+ * posthog.register_for_session({
197
+ * 'selectedPlan': 'pro',
198
+ * 'completedSteps': 4,
199
+ * });
200
+ *
201
+ * // Display the properties
202
+ * console.log(posthog.sessionPersistence.properties())
203
+ *
204
+ * @param {Object} properties An associative array of properties to store about the user
205
+ */
206
+ register_for_session(properties: Properties): void;
207
+ /**
208
+ * Delete a super property stored with the current user.
209
+ *
210
+ * @param {String} property The name of the super property to remove
211
+ */
212
+ unregister(property: string): void;
213
+ /**
214
+ * Delete a session super property stored with the current user.
215
+ *
216
+ * @param {String} property The name of the session super property to remove
217
+ */
218
+ unregister_for_session(property: string): void;
219
+ _register_single(prop: string, value: Property): void;
220
+ getFeatureFlag(key: string, options?: {
221
+ send_event?: boolean;
222
+ }): boolean | string | undefined;
223
+ getFeatureFlagPayload(key: string): JsonType;
224
+ isFeatureEnabled(key: string, options?: isFeatureEnabledOptions): boolean | undefined;
225
+ reloadFeatureFlags(): void;
226
+ /** Opt the user in or out of an early access feature. */
227
+ updateEarlyAccessFeatureEnrollment(key: string, isEnrolled: boolean): void;
228
+ /** Get the list of early access features. To check enrollment status, use `isFeatureEnabled`. */
229
+ getEarlyAccessFeatures(callback: EarlyAccessFeatureCallback, force_reload?: boolean): void;
230
+ onFeatureFlags(callback: (flags: string[], variants: Record<string, string | boolean>) => void): () => void;
231
+ onSessionId(callback: SessionIdChangedCallback): () => void;
232
+ /** Get list of all surveys. */
233
+ getSurveys(callback: SurveyCallback, forceReload?: boolean): void;
234
+ /** Get surveys that should be enabled for the current user. */
235
+ getActiveMatchingSurveys(callback: SurveyCallback, forceReload?: boolean): void;
236
+ /**
237
+ * Identify a user with a unique ID instead of a PostHog
238
+ * randomly generated distinct_id. If the method is never called,
239
+ * then unique visitors will be identified by a UUID that is generated
240
+ * the first time they visit the site.
241
+ *
242
+ * If user properties are passed, they are also sent to posthog.
243
+ *
244
+ * ### Usage:
245
+ *
246
+ * posthog.identify('[user unique id]')
247
+ * posthog.identify('[user unique id]', { email: 'john@example.com' })
248
+ * posthog.identify('[user unique id]', {}, { referral_code: '12345' })
249
+ *
250
+ * ### Notes:
251
+ *
252
+ * You can call this function to overwrite a previously set
253
+ * unique ID for the current user.
254
+ *
255
+ * If the user has been identified ($user_state in persistence is set to 'identified'),
256
+ * then capture of $identify is skipped to avoid merging users. For example,
257
+ * if your system allows an admin user to impersonate another user.
258
+ *
259
+ * Then a single browser instance can have:
260
+ *
261
+ * `identify('a') -> capture(1) -> identify('b') -> capture(2)`
262
+ *
263
+ * and capture 1 and capture 2 will have the correct distinct_id.
264
+ * but users a and b will NOT be merged in posthog.
265
+ *
266
+ * However, if reset is called then:
267
+ *
268
+ * `identify('a') -> capture(1) -> reset() -> capture(2) -> identify('b') -> capture(3)`
269
+ *
270
+ * users a and b are not merged.
271
+ * Capture 1 is associated with user a.
272
+ * A new distinct id is generated for capture 2.
273
+ * which is merged with user b.
274
+ * So, capture 2 and 3 are associated with user b.
275
+ *
276
+ * If you want to merge two identified users, you can call posthog.alias
277
+ *
278
+ * @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.
279
+ * @param {Object} [userPropertiesToSet] Optional: An associative array of properties to store about the user
280
+ * @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.
281
+ */
282
+ identify(new_distinct_id?: string, userPropertiesToSet?: Properties, userPropertiesToSetOnce?: Properties): void;
283
+ /**
284
+ * Sets properties for the Person associated with the current distinct_id.
285
+ *
286
+ *
287
+ * @param {Object} [userPropertiesToSet] Optional: An associative array of properties to store about the user
288
+ * @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.
289
+ */
290
+ setPersonProperties(userPropertiesToSet?: Properties, userPropertiesToSetOnce?: Properties): void;
291
+ /**
292
+ * Alpha feature: don't use unless you know what you're doing!
293
+ *
294
+ * Sets group analytics information for subsequent events and reloads feature flags.
295
+ *
296
+ * @param {String} groupType Group type (example: 'organization')
297
+ * @param {String} groupKey Group key (example: 'org::5')
298
+ * @param {Object} groupPropertiesToSet Optional properties to set for group
299
+ */
300
+ group(groupType: string, groupKey: string, groupPropertiesToSet?: Properties): void;
301
+ /**
302
+ * Resets only the group properties of the user currently logged in.
303
+ */
304
+ resetGroups(): void;
305
+ /**
306
+ * Set override person properties for feature flags.
307
+ * This is used when dealing with new persons / where you don't want to wait for ingestion
308
+ * to update user properties.
309
+ */
310
+ setPersonPropertiesForFlags(properties: Properties, reloadFeatureFlags?: boolean): void;
311
+ resetPersonPropertiesForFlags(): void;
312
+ /**
313
+ * Set override group properties for feature flags.
314
+ * This is used when dealing with new groups / where you don't want to wait for ingestion
315
+ * to update properties.
316
+ * Takes in an object, the key of which is the group type.
317
+ * For example:
318
+ * setGroupPropertiesForFlags({'organization': { name: 'CYZ', employees: '11' } })
319
+ */
320
+ setGroupPropertiesForFlags(properties: {
321
+ [type: string]: Properties;
322
+ }, reloadFeatureFlags?: boolean): void;
323
+ resetGroupPropertiesForFlags(group_type?: string): void;
324
+ /**
325
+ * Clears super properties and generates a new random distinct_id for this instance.
326
+ * Useful for clearing data when a user logs out.
327
+ */
328
+ reset(reset_device_id?: boolean): void;
329
+ /**
330
+ * Returns the current distinct id of the user. This is either the id automatically
331
+ * generated by the library or the id that has been passed by a call to identify().
332
+ *
333
+ * ### Notes:
334
+ *
335
+ * get_distinct_id() can only be called after the PostHog library has finished loading.
336
+ * init() has a loaded function available to handle this automatically. For example:
337
+ *
338
+ * // set distinct_id after the posthog library has loaded
339
+ * posthog.init('YOUR PROJECT TOKEN', {
340
+ * loaded: function(posthog) {
341
+ * distinct_id = posthog.get_distinct_id();
342
+ * }
343
+ * });
344
+ */
345
+ get_distinct_id(): string;
346
+ getGroups(): Record<string, any>;
347
+ /**
348
+ * Returns the current session_id.
349
+ *
350
+ * NOTE: This should only be used for informative purposes.
351
+ * Any actual internal use case for the session_id should be handled by the sessionManager.
352
+ */
353
+ get_session_id(): string;
354
+ /**
355
+ * Returns the Replay url for the current session.
356
+ *
357
+ * @param options Options for the url
358
+ * @param options.withTimestamp Whether to include the timestamp in the url (defaults to false)
359
+ * @param options.timestampLookBack How many seconds to look back for the timestamp (defaults to 10)
360
+ */
361
+ get_session_replay_url(options?: {
362
+ withTimestamp?: boolean;
363
+ timestampLookBack?: number;
364
+ }): string;
365
+ /**
366
+ * Create an alias, which PostHog will use to link two distinct_ids going forward (not retroactively).
367
+ * Multiple aliases can map to the same original ID, but not vice-versa. Aliases can also be chained - the
368
+ * following is a valid scenario:
369
+ *
370
+ * posthog.alias('new_id', 'existing_id');
371
+ * ...
372
+ * posthog.alias('newer_id', 'new_id');
373
+ *
374
+ * If the original ID is not passed in, we will use the current distinct_id - probably the auto-generated GUID.
375
+ *
376
+ * ### Notes:
377
+ *
378
+ * The best practice is to call alias() when a unique ID is first created for a user
379
+ * (e.g., when a user first registers for an account and provides an email address).
380
+ * alias() should never be called more than once for a given user, except to
381
+ * chain a newer ID to a previously new ID, as described above.
382
+ *
383
+ * @param {String} alias A unique identifier that you want to use for this user in the future.
384
+ * @param {String} [original] The current identifier being used for this user.
385
+ */
386
+ alias(alias: string, original?: string): CaptureResult | void | number;
387
+ /**
388
+ * Update the configuration of a posthog library instance.
389
+ *
390
+ * The default config is:
391
+ *
392
+ * {
393
+ * // PostHog API host
394
+ * api_host: 'https://app.posthog.com',
395
+ *
396
+ * // HTTP method for capturing requests
397
+ * api_method: 'POST'
398
+ *
399
+ * // PostHog web app host, currently only used by the Sentry integration.
400
+ * // This will only be different from api_host when using a reverse-proxied API host – in that case
401
+ * // the original web app host needs to be passed here so that links to the web app are still convenient.
402
+ * ui_host: 'https://app.posthog.com',
403
+ *
404
+ * // Automatically capture clicks, form submissions and change events
405
+ * autocapture: true
406
+ *
407
+ * // Capture rage clicks
408
+ * rageclick: true
409
+ *
410
+ * // transport for sending requests ('XHR' or 'sendBeacon')
411
+ * // NB: sendBeacon should only be used for scenarios such as
412
+ * // page unload where a "best-effort" attempt to send is
413
+ * // acceptable; the sendBeacon API does not support callbacks
414
+ * // or any way to know the result of the request. PostHog
415
+ * // capturing via sendBeacon will not support any event-
416
+ * // batching or retry mechanisms.
417
+ * api_transport: 'XHR'
418
+ *
419
+ * // super properties cookie expiration (in days)
420
+ * cookie_expiration: 365
421
+ *
422
+ * // super properties span subdomains
423
+ * cross_subdomain_cookie: true
424
+ *
425
+ * // debug mode
426
+ * debug: false
427
+ *
428
+ * // if this is true, the posthog cookie or localStorage entry
429
+ * // will be deleted, and no user persistence will take place
430
+ * disable_persistence: false
431
+ *
432
+ * // if this is true, PostHog will automatically determine
433
+ * // City, Region and Country data using the IP address of
434
+ * //the client
435
+ * ip: true
436
+ *
437
+ * // opt users out of capturing by this PostHog instance by default
438
+ * opt_out_capturing_by_default: false
439
+ *
440
+ * // opt users out of browser data storage by this PostHog instance by default
441
+ * opt_out_persistence_by_default: false
442
+ *
443
+ * // persistence mechanism used by opt-in/opt-out methods - cookie
444
+ * // or localStorage - falls back to cookie if localStorage is unavailable
445
+ * opt_out_capturing_persistence_type: 'localStorage'
446
+ *
447
+ * // customize the name of cookie/localStorage set by opt-in/opt-out methods
448
+ * opt_out_capturing_cookie_prefix: null
449
+ *
450
+ * // type of persistent store for super properties (cookie/
451
+ * // localStorage) if set to 'localStorage', any existing
452
+ * // posthog cookie value with the same persistence_name
453
+ * // will be transferred to localStorage and deleted
454
+ * persistence: 'cookie'
455
+ *
456
+ * // name for super properties persistent store
457
+ * persistence_name: ''
458
+ *
459
+ * // names of properties/superproperties which should never
460
+ * // be sent with capture() calls
461
+ * property_blacklist: []
462
+ *
463
+ * // if this is true, posthog cookies will be marked as
464
+ * // secure, meaning they will only be transmitted over https
465
+ * secure_cookie: false
466
+ *
467
+ * // should we capture a page view on page load
468
+ * capture_pageview: true
469
+ *
470
+ * // if you set upgrade to be true, the library will check for
471
+ * // a cookie from our old js library and import super
472
+ * // properties from it, then the old cookie is deleted
473
+ * // The upgrade config option only works in the initialization,
474
+ * // so make sure you set it when you create the library.
475
+ * upgrade: false
476
+ *
477
+ * // if this is true, session recording is always disabled.
478
+ * disable_session_recording: false,
479
+ *
480
+ * // extra HTTP request headers to set for each API request, in
481
+ * // the format {'Header-Name': value}
482
+ * xhr_headers: {}
483
+ *
484
+ * // protocol for fetching in-app message resources, e.g.
485
+ * // 'https://' or 'http://'; defaults to '//' (which defers to the
486
+ * // current page's protocol)
487
+ * inapp_protocol: '//'
488
+ *
489
+ * // whether to open in-app message link in new tab/window
490
+ * inapp_link_new_window: false
491
+ *
492
+ * // a set of rrweb config options that PostHog users can configure
493
+ * // see https://github.com/rrweb-io/rrweb/blob/master/guide.md
494
+ * session_recording: {
495
+ * blockClass: 'ph-no-capture',
496
+ * blockSelector: null,
497
+ * ignoreClass: 'ph-ignore-input',
498
+ * maskAllInputs: true,
499
+ * maskInputOptions: {},
500
+ * maskInputFn: null,
501
+ * slimDOMOptions: {},
502
+ * collectFonts: false
503
+ * }
504
+ *
505
+ * // prevent autocapture from capturing any attribute names on elements
506
+ * mask_all_element_attributes: false
507
+ *
508
+ * // prevent autocapture from capturing textContent on all elements
509
+ * mask_all_text: false
510
+ *
511
+ * // Anonymous users get a random UUID as their device by default.
512
+ * // This option allows overriding that option.
513
+ * get_device_id: (uuid) => uuid
514
+ * }
515
+ *
516
+ *
517
+ * @param {Object} config A dictionary of new configuration values to update
518
+ */
519
+ set_config(config: Partial<PostHogConfig>): void;
520
+ /**
521
+ * turns session recording on, and updates the config option
522
+ * disable_session_recording to false
523
+ */
524
+ startSessionRecording(): void;
525
+ /**
526
+ * turns session recording off, and updates the config option
527
+ * disable_session_recording to true
528
+ */
529
+ stopSessionRecording(): void;
530
+ /**
531
+ * returns a boolean indicating whether session recording
532
+ * is currently running
533
+ */
534
+ sessionRecordingStarted(): boolean;
535
+ /**
536
+ * returns a boolean indicating whether the toolbar loaded
537
+ * @param toolbarParams
538
+ */
539
+ loadToolbar(params: ToolbarParams): boolean;
540
+ /**
541
+ * returns the current config object for the library.
542
+ */
543
+ get_config<K extends keyof PostHogConfig>(prop_name: K): PostHogConfig[K];
544
+ /**
545
+ * Returns the value of the super property named property_name. If no such
546
+ * property is set, get_property() will return the undefined value.
547
+ *
548
+ * ### Notes:
549
+ *
550
+ * get_property() can only be called after the PostHog library has finished loading.
551
+ * init() has a loaded function available to handle this automatically. For example:
552
+ *
553
+ * // grab value for '$user_id' after the posthog library has loaded
554
+ * posthog.init('YOUR PROJECT TOKEN', {
555
+ * loaded: function(posthog) {
556
+ * user_id = posthog.get_property('$user_id');
557
+ * }
558
+ * });
559
+ *
560
+ * @param {String} property_name The name of the super property you want to retrieve
561
+ */
562
+ get_property(property_name: string): Property | undefined;
563
+ /**
564
+ * Returns the value of the session super property named property_name. If no such
565
+ * property is set, getSessionProperty() will return the undefined value.
566
+ *
567
+ * ### Notes:
568
+ *
569
+ * This is based on browser-level `sessionStorage`, NOT the PostHog session.
570
+ * getSessionProperty() can only be called after the PostHog library has finished loading.
571
+ * init() has a loaded function available to handle this automatically. For example:
572
+ *
573
+ * // grab value for 'user_id' after the posthog library has loaded
574
+ * posthog.init('YOUR PROJECT TOKEN', {
575
+ * loaded: function(posthog) {
576
+ * user_id = posthog.getSessionProperty('user_id');
577
+ * }
578
+ * });
579
+ *
580
+ * @param {String} property_name The name of the session super property you want to retrieve
581
+ */
582
+ getSessionProperty(property_name: string): Property | undefined;
583
+ toString(): string;
584
+ _gdpr_init(): void;
585
+ /**
586
+ * Enable or disable persistence based on options
587
+ * only enable/disable if persistence is not already in this state
588
+ * @param {boolean} [options.clear_persistence] If true, will delete all data stored by the sdk in persistence and disable it
589
+ * @param {boolean} [options.enable_persistence] If true, will re-enable sdk persistence
590
+ */
591
+ _gdpr_update_persistence(options: Partial<OptInOutCapturingOptions>): void;
592
+ _gdpr_call_func<R = any>(func: (token: string, options: GDPROptions) => R, options?: Partial<OptInOutCapturingOptions>): R;
593
+ /**
594
+ * Opt the user in to data capturing and cookies/localstorage for this PostHog instance
595
+ *
596
+ * ### Usage
597
+ *
598
+ * // opt user in
599
+ * posthog.opt_in_capturing();
600
+ *
601
+ * // opt user in with specific event name, properties, cookie configuration
602
+ * posthog.opt_in_capturing({
603
+ * capture_event_name: 'User opted in',
604
+ * capture_event_properties: {
605
+ * 'Email': 'jdoe@example.com'
606
+ * },
607
+ * cookie_expiration: 30,
608
+ * secure_cookie: true
609
+ * });
610
+ *
611
+ * @param {Object} [options] A dictionary of config options to override
612
+ * @param {function} [options.capture] Function used for capturing a PostHog event to record the opt-in action (default is this PostHog instance's capture method)
613
+ * @param {string} [options.capture_event_name=$opt_in] Event name to be used for capturing the opt-in action
614
+ * @param {Object} [options.capture_properties] Set of properties to be captured along with the opt-in action
615
+ * @param {boolean} [options.enable_persistence=true] If true, will re-enable sdk persistence
616
+ * @param {string} [options.persistence_type=localStorage] Persistence mechanism used - cookie or localStorage - falls back to cookie if localStorage is unavailable
617
+ * @param {string} [options.cookie_prefix=__ph_opt_in_out] Custom prefix to be used in the cookie/localstorage name
618
+ * @param {Number} [options.cookie_expiration] Number of days until the opt-in cookie expires (overrides value specified in this PostHog instance's config)
619
+ * @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)
620
+ * @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)
621
+ */
622
+ opt_in_capturing(options?: Partial<OptInOutCapturingOptions>): void;
623
+ /**
624
+ * Opt the user out of data capturing and cookies/localstorage for this PostHog instance
625
+ *
626
+ * ### Usage
627
+ *
628
+ * // opt user out
629
+ * posthog.opt_out_capturing();
630
+ *
631
+ * // opt user out with different cookie configuration from PostHog instance
632
+ * posthog.opt_out_capturing({
633
+ * cookie_expiration: 30,
634
+ * secure_cookie: true
635
+ * });
636
+ *
637
+ * @param {Object} [options] A dictionary of config options to override
638
+ * @param {boolean} [options.clear_persistence=true] If true, will delete all data stored by the sdk in persistence
639
+ * @param {string} [options.persistence_type=localStorage] Persistence mechanism used - cookie or localStorage - falls back to cookie if localStorage is unavailable
640
+ * @param {string} [options.cookie_prefix=__ph_opt_in_out] Custom prefix to be used in the cookie/localstorage name
641
+ * @param {Number} [options.cookie_expiration] Number of days until the opt-in cookie expires (overrides value specified in this PostHog instance's config)
642
+ * @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)
643
+ * @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)
644
+ */
645
+ opt_out_capturing(options?: Partial<OptInOutCapturingOptions>): void;
646
+ /**
647
+ * Check whether the user has opted in to data capturing and cookies/localstorage for this PostHog instance
648
+ *
649
+ * ### Usage
650
+ *
651
+ * const has_opted_in = posthog.has_opted_in_capturing();
652
+ * // use has_opted_in value
653
+ *
654
+ * @param {Object} [options] A dictionary of config options to override
655
+ * @param {string} [options.persistence_type=localStorage] Persistence mechanism used - cookie or localStorage - falls back to cookie if localStorage is unavailable
656
+ * @param {string} [options.cookie_prefix=__ph_opt_in_out] Custom prefix to be used in the cookie/localstorage name
657
+ * @returns {boolean} current opt-in status
658
+ */
659
+ has_opted_in_capturing(options?: Partial<OptInOutCapturingOptions>): boolean;
660
+ /**
661
+ * Check whether the user has opted out of data capturing and cookies/localstorage for this PostHog instance
662
+ *
663
+ * ### Usage
664
+ *
665
+ * const has_opted_out = posthog.has_opted_out_capturing();
666
+ * // use has_opted_out value
667
+ *
668
+ * @param {Object} [options] A dictionary of config options to override
669
+ * @param {string} [options.persistence_type=localStorage] Persistence mechanism used - cookie or localStorage - falls back to cookie if localStorage is unavailable
670
+ * @param {string} [options.cookie_prefix=__ph_opt_in_out] Custom prefix to be used in the cookie/localstorage name
671
+ * @returns {boolean} current opt-out status
672
+ */
673
+ has_opted_out_capturing(options?: Partial<OptInOutCapturingOptions>): boolean;
674
+ /**
675
+ * Clear the user's opt in/out status of data capturing and cookies/localstorage for this PostHog instance
676
+ *
677
+ * ### Usage
678
+ *
679
+ * // clear user's opt-in/out status
680
+ * posthog.clear_opt_in_out_capturing();
681
+ *
682
+ * // clear user's opt-in/out status with specific cookie configuration - should match
683
+ * // configuration used when opt_in_capturing/opt_out_capturing methods were called.
684
+ * posthog.clear_opt_in_out_capturing({
685
+ * cookie_expiration: 30,
686
+ * secure_cookie: true
687
+ * });
688
+ *
689
+ * @param {Object} [options] A dictionary of config options to override
690
+ * @param {boolean} [options.enable_persistence=true] If true, will re-enable sdk persistence
691
+ * @param {string} [options.persistence_type=localStorage] Persistence mechanism used - cookie or localStorage - falls back to cookie if localStorage is unavailable
692
+ * @param {string} [options.cookie_prefix=__ph_opt_in_out] Custom prefix to be used in the cookie/localstorage name
693
+ * @param {Number} [options.cookie_expiration] Number of days until the opt-in cookie expires (overrides value specified in this PostHog instance's config)
694
+ * @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)
695
+ * @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)
696
+ */
697
+ clear_opt_in_out_capturing(options?: Partial<OptInOutCapturingOptions>): void;
698
+ debug(debug?: boolean): void;
699
+ }
700
+ export declare function init_from_snippet(): void;
701
+ export declare function init_as_module(): PostHog;