@leanbase-giangnd/js 0.0.0

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 (49) hide show
  1. package/README.md +143 -0
  2. package/dist/index.cjs +6012 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.ts +1484 -0
  5. package/dist/index.mjs +6010 -0
  6. package/dist/index.mjs.map +1 -0
  7. package/dist/leanbase.iife.js +13431 -0
  8. package/dist/leanbase.iife.js.map +1 -0
  9. package/package.json +48 -0
  10. package/src/autocapture-utils.ts +550 -0
  11. package/src/autocapture.ts +415 -0
  12. package/src/config.ts +8 -0
  13. package/src/constants.ts +108 -0
  14. package/src/extensions/rageclick.ts +34 -0
  15. package/src/extensions/replay/external/config.ts +278 -0
  16. package/src/extensions/replay/external/denylist.ts +32 -0
  17. package/src/extensions/replay/external/lazy-loaded-session-recorder.ts +1376 -0
  18. package/src/extensions/replay/external/mutation-throttler.ts +109 -0
  19. package/src/extensions/replay/external/network-plugin.ts +701 -0
  20. package/src/extensions/replay/external/sessionrecording-utils.ts +141 -0
  21. package/src/extensions/replay/external/triggerMatching.ts +422 -0
  22. package/src/extensions/replay/rrweb-plugins/patch.ts +39 -0
  23. package/src/extensions/replay/session-recording.ts +285 -0
  24. package/src/extensions/replay/types/rrweb-types.ts +575 -0
  25. package/src/extensions/replay/types/rrweb.ts +114 -0
  26. package/src/extensions/sampling.ts +26 -0
  27. package/src/iife.ts +87 -0
  28. package/src/index.ts +2 -0
  29. package/src/leanbase-logger.ts +26 -0
  30. package/src/leanbase-persistence.ts +374 -0
  31. package/src/leanbase.ts +457 -0
  32. package/src/page-view.ts +124 -0
  33. package/src/scroll-manager.ts +103 -0
  34. package/src/session-props.ts +114 -0
  35. package/src/sessionid.ts +330 -0
  36. package/src/storage.ts +410 -0
  37. package/src/types/fflate.d.ts +5 -0
  38. package/src/types/rrweb-record.d.ts +8 -0
  39. package/src/types.ts +807 -0
  40. package/src/utils/blocked-uas.ts +162 -0
  41. package/src/utils/element-utils.ts +50 -0
  42. package/src/utils/event-utils.ts +304 -0
  43. package/src/utils/index.ts +222 -0
  44. package/src/utils/logger.ts +26 -0
  45. package/src/utils/request-utils.ts +128 -0
  46. package/src/utils/simple-event-emitter.ts +27 -0
  47. package/src/utils/user-agent-utils.ts +357 -0
  48. package/src/uuidv7.ts +268 -0
  49. package/src/version.ts +1 -0
package/src/types.ts ADDED
@@ -0,0 +1,807 @@
1
+ import { FeatureFlagValue, JsonType, PostHogCoreOptions } from '@posthog/core'
2
+ import { KnownUnsafeEditableEvent } from '@posthog/core'
3
+ import type { recordOptions } from './extensions/replay/types/rrweb'
4
+ import { Leanbase } from './leanbase'
5
+
6
+ export const COPY_AUTOCAPTURE_EVENT = '$copy_autocapture'
7
+
8
+ export type Property = any
9
+ export type Properties = Record<string, Property>
10
+
11
+ export type AutocaptureCompatibleElement = 'a' | 'button' | 'form' | 'input' | 'select' | 'textarea' | 'label'
12
+
13
+ export type DomAutocaptureEvents = 'click' | 'change' | 'submit'
14
+
15
+ export interface BootstrapConfig {
16
+ distinctId?: string
17
+ isIdentifiedId?: boolean
18
+ featureFlags?: Record<string, FeatureFlagValue>
19
+ featureFlagPayloads?: Record<string, JsonType>
20
+
21
+ /**
22
+ * Optionally provide a sessionID, this is so that you can provide an existing sessionID here to continue a user's session across a domain or device. It MUST be:
23
+ * - unique to this user
24
+ * - a valid UUID v7
25
+ * - the timestamp part must be <= the timestamp of the first event in the session
26
+ * - the timestamp of the last event in the session must be < the timestamp part + 24 hours
27
+ * **/
28
+ sessionID?: string
29
+ }
30
+
31
+ /**
32
+ * If an array is passed for an allowlist, autocapture events will only be sent for elements matching
33
+ * at least one of the elements in the array. Multiple allowlists can be used
34
+ */
35
+ export interface AutocaptureConfig {
36
+ /**
37
+ * List of URLs to allow autocapture on, can be strings to match
38
+ * or regexes e.g. ['https://example.com', 'test.com/.*']
39
+ * this is useful when you want to autocapture on specific pages only
40
+ *
41
+ * if you set both url_allowlist and url_ignorelist,
42
+ * we check the allowlist first and then the ignorelist.
43
+ * the ignorelist can override the allowlist
44
+ */
45
+ url_allowlist?: (string | RegExp)[]
46
+
47
+ /**
48
+ * List of URLs to not allow autocapture on, can be strings to match
49
+ * or regexes e.g. ['https://example.com', 'test.com/.*']
50
+ * this is useful when you want to autocapture on most pages but not some specific ones
51
+ *
52
+ * if you set both url_allowlist and url_ignorelist,
53
+ * we check the allowlist first and then the ignorelist.
54
+ * the ignorelist can override the allowlist
55
+ */
56
+ url_ignorelist?: (string | RegExp)[]
57
+
58
+ /**
59
+ * List of DOM events to allow autocapture on e.g. ['click', 'change', 'submit']
60
+ */
61
+ dom_event_allowlist?: DomAutocaptureEvents[]
62
+
63
+ /**
64
+ * List of DOM elements to allow autocapture on
65
+ * e.g. ['a', 'button', 'form', 'input', 'select', 'textarea', 'label']
66
+ *
67
+ * We consider the tree of elements from the root to the target element of the click event
68
+ * so for the tree `div > div > button > svg`
69
+ * if the allowlist has `button` then we allow the capture when the `button` or the `svg` is the click target
70
+ * but not if either of the `div`s are detected as the click target
71
+ */
72
+ element_allowlist?: AutocaptureCompatibleElement[]
73
+
74
+ /**
75
+ * List of CSS selectors to allow autocapture on
76
+ * e.g. ['[ph-capture]']
77
+ * we consider the tree of elements from the root to the target element of the click event
78
+ * so for the tree div > div > button > svg
79
+ * and allow list config `['[id]']`
80
+ * we will capture the click if the click-target or its parents has any id
81
+ *
82
+ * Everything is allowed when there's no allowlist
83
+ */
84
+ css_selector_allowlist?: string[]
85
+
86
+ /**
87
+ * Exclude certain element attributes from autocapture
88
+ * E.g. ['aria-label'] or [data-attr-pii]
89
+ */
90
+ element_attribute_ignorelist?: string[]
91
+
92
+ /**
93
+ * When set to true, autocapture will capture the text of any element that is cut or copied.
94
+ */
95
+ capture_copied_text?: boolean
96
+ }
97
+
98
+ export interface LeanbaseConfig extends Partial<PostHogCoreOptions> {
99
+ /**
100
+ * API host for Leanbase
101
+ * @default 'https://i.leanbase.co'
102
+ */
103
+ host?: string
104
+
105
+ /**
106
+ * The token for your Leanbase project.
107
+ * It should NOT be provided manually in the config, but rather passed as the first parameter to `leanbase.init()`.
108
+ */
109
+ token: string
110
+
111
+ /**
112
+ * Enables debug mode, which provides more verbose logging for development purposes.
113
+ * @default false
114
+ */
115
+ debug?: boolean
116
+
117
+ /**
118
+ * Determines whether Leanbase should autocapture events.
119
+ * This setting does not affect capturing pageview events (see `capture_pageview`).
120
+ *
121
+ * by default autocapture is ignored on elements that match a `ph-no-capture` css class on the element or a parent
122
+ * @default true
123
+ */
124
+ autocapture: boolean | AutocaptureConfig
125
+
126
+ /**
127
+ * Enables or disables session recording. When true, session recording is disabled on the client.
128
+ * @default false
129
+ */
130
+ disable_session_recording?: boolean
131
+
132
+ /**
133
+ * Session recording configuration
134
+ */
135
+ session_recording?: SessionRecordingOptions
136
+
137
+ /**
138
+ * Enable console.log recording for session replay (can be controlled remotely). Undefined defers to server.
139
+ */
140
+ enable_recording_console_log?: boolean
141
+
142
+ /**
143
+ * Determines whether Leanbase should capture pageview events automatically.
144
+ * Can be:
145
+ * - `true`: Capture regular pageviews (default)
146
+ * - `false`: Don't capture any pageviews
147
+ * - `'history_change'`: Only capture pageviews on history API changes (pushState, replaceState, popstate)
148
+ *
149
+ * @default true
150
+ */
151
+ capture_pageview: boolean | 'history_change'
152
+
153
+ /**
154
+ * Enables performance capture. When true, network performance timing can be forwarded to replay when enabled.
155
+ */
156
+ capture_performance?: boolean | { network_timing?: boolean }
157
+
158
+ /**
159
+ * Determines the session idle timeout in seconds.
160
+ * Any new event that's happened after this timeout will create a new session.
161
+ *
162
+ * @default 30 * 60 -- 30 minutes
163
+ */
164
+ session_idle_timeout_seconds: number
165
+
166
+ /**
167
+ * An object containing the `distinctID`, `isIdentifiedID`, and `featureFlags` keys,
168
+ * where `distinctID` is a string, and `featureFlags` is an object of key-value pairs.
169
+ *
170
+ * Since there is a delay between initializing PostHog and fetching feature flags,
171
+ * feature flags are not always available immediately.
172
+ * This makes them unusable if you want to do something like redirecting a user
173
+ * to a different page based on a feature flag.
174
+ *
175
+ * You can, therefore, fetch the feature flags in your server and pre-fill them here,
176
+ * allowing PostHog to know the feature flag values immediately.
177
+ *
178
+ * After the SDK fetches feature flags from PostHog, it will use those flag values instead of bootstrapped ones.
179
+ *
180
+ * @default {}
181
+ */
182
+ bootstrap: BootstrapConfig
183
+
184
+ /**
185
+ * Determines whether Leanbase should capture pageleave events.
186
+ * If set to `true`, it will capture pageleave events for all pages.
187
+ * If set to `'if_capture_pageview'`, it will only capture pageleave events if `capture_pageview` is also set to `true` or `'history_change'`.
188
+ *
189
+ * @default 'if_capture_pageview'
190
+ */
191
+ capture_pageleave: boolean | 'if_capture_pageview'
192
+
193
+ /**
194
+ * Determines whether Leanbase should capture rage clicks.
195
+ *
196
+ * by default rageclicks are ignored on elements that match a `ph-no-capture` or `ph-no-rageclick` css class on the element or a parent
197
+ * @default true
198
+ */
199
+ rageclick: boolean | RageclickConfig
200
+
201
+ /**
202
+ * Determines where to store the Leanbase persistence information.
203
+ */
204
+ persistence: 'localStorage' | 'cookie' | 'memory' | 'localStorage+cookie' | 'sessionStorage'
205
+
206
+ /**
207
+ * The name for the super properties persistent store
208
+ *
209
+ * @default ''
210
+ */
211
+ persistence_name: string
212
+
213
+ /**
214
+ * Prevent autocapture from capturing any attribute names on elements.
215
+ *
216
+ * @default false
217
+ */
218
+ mask_all_element_attributes: boolean
219
+
220
+ /**
221
+ * Prevent autocapture from capturing `textContent` on elements.
222
+ *
223
+ * @default false
224
+ */
225
+ mask_all_text: boolean
226
+
227
+ /**
228
+ * Used to extend the list of campaign parameters that are saved by default.
229
+ *
230
+ * @see {CAMPAIGN_PARAMS} from './utils/event-utils' - Default campaign parameters like utm_source, utm_medium, etc.
231
+ * @default []
232
+ */
233
+ custom_campaign_params: string[]
234
+
235
+ /**
236
+ * Mask personal data properties from the current URL.
237
+ * This will mask personal data properties such as advertising IDs (gclid, fbclid, etc.), and you can also add
238
+ * custom properties to mask with `custom_personal_data_properties`.
239
+ * @default false
240
+ * @see {PERSONAL_DATA_CAMPAIGN_PARAMS} - Default campaign parameters that are masked by default.
241
+ * @see {LeanbaseConfig.custom_personal_data_properties} - Custom list of personal data properties to mask.
242
+ */
243
+ mask_personal_data_properties: boolean
244
+
245
+ /**
246
+ * Custom list of personal data properties to mask.
247
+ *
248
+ * E.g. if you added `email` to this list, then any `email` property in the URL will be masked.
249
+ * https://www.example.com/login?email=john.doe%40example.com => https://www.example.com/login?email=<MASKED>
250
+ *
251
+ * @default []
252
+ * @see {LeanbaseConfig.mask_personal_data_properties} - Must be enabled for this to take effect.
253
+ */
254
+ custom_personal_data_properties: string[]
255
+
256
+ /**
257
+ * Determines the number of days to store cookies for.
258
+ *
259
+ * @default 365
260
+ */
261
+ cookie_expiration: number
262
+
263
+ /**
264
+ * Determines whether Leanbase should use secure cookies.
265
+ * If this is `true`, Leanbase cookies will be marked as secure,
266
+ * meaning they will only be transmitted over HTTPS.
267
+ *
268
+ * @default window.location.protocol === 'https:'
269
+ */
270
+ secure_cookie: boolean
271
+
272
+ /**
273
+ * Determines if cookie should be set on the top level domain (example.com).
274
+ * If leanbase-js is loaded on a subdomain (test.example.com), and `cross_subdomain_cookie` is set to false,
275
+ * it'll set the cookie on the subdomain only (test.example.com).
276
+ *
277
+ * NOTE: It will be set to `false` if we detect that the domain is a subdomain of a platform that is excluded from cross-subdomain cookie setting.
278
+ * The current list of excluded platforms is `herokuapp.com`, `vercel.app`, and `netlify.app`.
279
+ *
280
+ * @see `isCrossDomainCookie`
281
+ * @default true
282
+ */
283
+ cross_subdomain_cookie: boolean
284
+
285
+ /**
286
+ * Determines whether Leanbase should disable persistence.
287
+ * If set to `true`, the library will not save any data to the browser. It will also delete any data previously saved to the browser.
288
+ *
289
+ * @default false
290
+ */
291
+ disable_persistence: boolean
292
+
293
+ /**
294
+ * Enables cookieless mode. In this mode, Leanbase will not set any cookies, or use session or local storage. User
295
+ * identity is handled by generating a privacy-preserving hash on Leanbase's servers.
296
+ * - 'always' - enable cookieless mode immediately on startup, use this if you do not intend to show a cookie banner
297
+ * - 'on_reject' - enable cookieless mode only if the user rejects cookies, use this if you want to show a cookie banner. If the user accepts cookies, cookieless mode will not be used, and PostHog will use cookies and local storage as usual.
298
+ *
299
+ * Note that you MUST enable cookieless mode in your Leanbase project's settings, otherwise all your cookieless events will be ignored. We plan to remove this requirement in the future.
300
+ * */
301
+ cookieless_mode?: 'always' | 'on_reject'
302
+
303
+ /**
304
+ * Determines whether PostHog should save referrer information.
305
+ *
306
+ * @default true
307
+ */
308
+ save_referrer: boolean
309
+
310
+ /**
311
+ * Determines whether PostHog should save marketing parameters.
312
+ * These are `utm_*` paramaters and friends.
313
+ *
314
+ * @see {CAMPAIGN_PARAMS} from './utils/event-utils' - Default campaign parameters like utm_source, utm_medium, etc.
315
+ * @default true
316
+ */
317
+ save_campaign_params: boolean
318
+
319
+ /**
320
+ * Determines whether to disable scroll properties.
321
+ * These allow you to keep track of how far down someone scrolled in your website.
322
+ *
323
+ * @default false
324
+ */
325
+ disable_scroll_properties?: boolean
326
+
327
+ /**
328
+ * Let the pageview scroll stats use a custom css selector for the root element, e.g. `main`
329
+ * It will use `window.document.documentElement` if not specified.
330
+ */
331
+ scroll_root_selector?: string | string[]
332
+
333
+ /**
334
+ * Determines if users should be opted out of user agent filtering such as googlebot or other bots.
335
+ * If this is set to `true`, PostHog will set `$browser_type` to either `bot` or `browser` for all events,
336
+ * but will process all events as if they were from a browser.
337
+ *
338
+ * @default false
339
+ */
340
+ opt_out_useragent_filter: boolean
341
+
342
+ /**
343
+ * Determines the maximum length of the properties string that can be sent with capture calls.
344
+ *
345
+ * @default 65535
346
+ */
347
+ properties_string_max_length: number
348
+
349
+ /**
350
+ * A function to be called once the Leanbase scripts have loaded successfully.
351
+ *
352
+ * @param instance - The Leanbase instance that has been loaded.
353
+ */
354
+ loaded: (instance: Leanbase) => void
355
+ }
356
+
357
+ export type SessionRecordingCanvasOptions = {
358
+ recordCanvas?: boolean | null
359
+ canvasFps?: number | null
360
+ canvasQuality?: string | null
361
+ }
362
+
363
+ export interface SessionRecordingOptions {
364
+ blockClass?: string | RegExp
365
+ blockSelector?: string | null
366
+ ignoreClass?: string | RegExp
367
+ maskTextClass?: string | RegExp
368
+ maskTextSelector?: string | null
369
+ maskTextFn?: ((text: string, element?: HTMLElement) => string) | null
370
+ maskAllInputs?: boolean
371
+ maskInputOptions?: recordOptions['maskInputOptions']
372
+ maskInputFn?: ((text: string, element?: HTMLElement) => string) | null
373
+ slimDOMOptions?: recordOptions['slimDOMOptions']
374
+ collectFonts?: boolean
375
+ inlineStylesheet?: boolean
376
+ recordCrossOriginIframes?: boolean
377
+ recordHeaders?: boolean
378
+ recordBody?: boolean
379
+ captureCanvas?: SessionRecordingCanvasOptions
380
+ maskCapturedNetworkRequestFn?: ((data: CapturedNetworkRequest) => CapturedNetworkRequest | null | undefined) | null
381
+ maskNetworkRequestFn?: ((data: NetworkRequest) => NetworkRequest | null | undefined) | null
382
+ full_snapshot_interval_millis?: number
383
+ compress_events?: boolean
384
+ session_idle_threshold_ms?: number
385
+ __mutationThrottlerRefillRate?: number
386
+ __mutationThrottlerBucketSize?: number
387
+ /**
388
+ * Force-enable session recording locally even if remote config disables it.
389
+ * Useful for dev/testing when the backend has sessionRecording set to false.
390
+ */
391
+ forceClientRecording?: boolean
392
+ }
393
+
394
+ export type SessionRecordingPersistedConfig = Omit<
395
+ SessionRecordingRemoteConfig,
396
+ | 'recordCanvas'
397
+ | 'canvasFps'
398
+ | 'canvasQuality'
399
+ | 'networkPayloadCapture'
400
+ | 'sampleRate'
401
+ | 'minimumDurationMilliseconds'
402
+ > & {
403
+ enabled: boolean
404
+ networkPayloadCapture: SessionRecordingRemoteConfig['networkPayloadCapture'] & {
405
+ capturePerformance: RemoteConfig['capturePerformance']
406
+ }
407
+ canvasRecording: {
408
+ enabled: SessionRecordingRemoteConfig['recordCanvas']
409
+ fps: SessionRecordingRemoteConfig['canvasFps']
410
+ quality: SessionRecordingRemoteConfig['canvasQuality']
411
+ }
412
+ sampleRate: number | null
413
+ minimumDurationMilliseconds: number | null | undefined
414
+ }
415
+
416
+ export type SessionRecordingRemoteConfig = SessionRecordingCanvasOptions & {
417
+ endpoint?: string
418
+ consoleLogRecordingEnabled?: boolean
419
+ sampleRate?: string | null
420
+ minimumDurationMilliseconds?: number
421
+ linkedFlag?: string | { flag: string; variant: string } | null
422
+ networkPayloadCapture?: Pick<NetworkRecordOptions, 'recordBody' | 'recordHeaders' | 'payloadHostDenyList'>
423
+ masking?: Pick<SessionRecordingOptions, 'maskAllInputs' | 'maskTextSelector' | 'blockSelector'>
424
+ urlTriggers?: SessionRecordingUrlTrigger[]
425
+ scriptConfig?: { script?: string | undefined }
426
+ urlBlocklist?: SessionRecordingUrlTrigger[]
427
+ eventTriggers?: string[]
428
+ triggerMatchType?: 'any' | 'all'
429
+ }
430
+
431
+ export interface RageclickConfig {
432
+ /**
433
+ * List of CSS selectors to ignore rageclicks on
434
+ * e.g. ['.my-calendar-button']
435
+ * we consider the tree of elements from the root to the target element of the click event
436
+ * so for the tree div > div > button > svg
437
+ * and ignore list config `['[id]']`
438
+ * we will ignore the rageclick if the click-target or its parents has any id
439
+ *
440
+ * Nothing is ignored when there's an empty ignorelist, e.g. []
441
+ * If no ignorelist is set, we default to ignoring .ph-no-rageclick
442
+ * If an element has .ph-no-capture, it will always be ignored by rageclick and autocapture
443
+ */
444
+ css_selector_ignorelist?: string[]
445
+ }
446
+
447
+ export type PropertyMatchType = 'regex' | 'not_regex' | 'exact' | 'is_not' | 'icontains' | 'not_icontains'
448
+
449
+ export interface ErrorTrackingSuppressionRule {
450
+ type: 'AND' | 'OR'
451
+ values: ErrorTrackingSuppressionRuleValue[]
452
+ }
453
+
454
+ export interface ErrorTrackingSuppressionRuleValue {
455
+ key: '$exception_types' | '$exception_values'
456
+ operator: PropertyMatchType
457
+ value: string | string[]
458
+ type: string
459
+ }
460
+
461
+ export enum Compression {
462
+ GZipJS = 'gzip-js',
463
+ Base64 = 'base64',
464
+ }
465
+
466
+ export type SupportedWebVitalsMetrics = 'LCP' | 'CLS' | 'FCP' | 'INP'
467
+
468
+ export interface PerformanceCaptureConfig {
469
+ /**
470
+ * Works with session replay to use the browser's native performance observer to capture performance metrics
471
+ */
472
+ network_timing?: boolean
473
+
474
+ /**
475
+ * Use chrome's web vitals library to wrap fetch and capture web vitals
476
+ */
477
+ web_vitals?: boolean
478
+
479
+ /**
480
+ * We observe very large values reported by the Chrome web vitals library
481
+ * These outliers are likely not real, useful values, and we exclude them
482
+ * You can set this to 0 in order to include all values, NB this is not recommended
483
+ *
484
+ * @default 15 * 60 * 1000 (15 minutes)
485
+ */
486
+ __web_vitals_max_value?: number
487
+
488
+ /**
489
+ * By default all 4 metrics are captured
490
+ * You can set this config to restrict which metrics are captured
491
+ * e.g. ['CLS', 'FCP'] to only capture those two metrics
492
+ * NB setting this does not override whether the capture is enabled
493
+ *
494
+ * @default ['LCP', 'CLS', 'FCP', 'INP']
495
+ */
496
+ web_vitals_allowed_metrics?: SupportedWebVitalsMetrics[]
497
+
498
+ /**
499
+ * We delay flushing web vitals metrics to reduce the number of events we send
500
+ * This is the maximum time we will wait before sending the metrics
501
+ *
502
+ * @default 5000
503
+ */
504
+ web_vitals_delayed_flush_ms?: number
505
+ }
506
+
507
+ /**
508
+ * Remote configuration for the Leanbase instance
509
+ *
510
+ * All of these settings can be configured directly in your Leanbase instance
511
+ * Any configuration set in the client overrides the information from the server
512
+ */
513
+ export interface RemoteConfig {
514
+ /**
515
+ * Supported compression algorithms
516
+ */
517
+ supportedCompression: Compression[]
518
+
519
+ /**
520
+ * If set, disables autocapture
521
+ */
522
+ autocapture_opt_out?: boolean
523
+
524
+ /**
525
+ * originally capturePerformance was replay only and so boolean true
526
+ * is equivalent to { network_timing: true }
527
+ * now capture performance can be separately enabled within replay
528
+ * and as a standalone web vitals tracker
529
+ * people can have them enabled separately
530
+ * they work standalone but enhance each other
531
+ * TODO: deprecate this so we make a new config that doesn't need this explanation
532
+ */
533
+ capturePerformance?: boolean | PerformanceCaptureConfig
534
+
535
+ /**
536
+ * Whether we should use a custom endpoint for analytics
537
+ *
538
+ * @default { endpoint: "/e" }
539
+ */
540
+ analytics?: {
541
+ endpoint?: string
542
+ }
543
+
544
+ /**
545
+ * Whether the `$elements_chain` property should be sent as a string or as an array
546
+ *
547
+ * @default false
548
+ */
549
+ elementsChainAsString?: boolean
550
+
551
+ /**
552
+ * Error tracking configuration options
553
+ */
554
+ errorTracking?: {
555
+ autocaptureExceptions?: boolean
556
+ captureExtensionExceptions?: boolean
557
+ suppressionRules?: ErrorTrackingSuppressionRule[]
558
+ }
559
+
560
+ /**
561
+ * This is currently in development and may have breaking changes without a major version bump
562
+ */
563
+ autocaptureExceptions?: boolean | { endpoint?: string }
564
+
565
+ /**
566
+ * Session recording configuration options
567
+ */
568
+ sessionRecording?: SessionRecordingRemoteConfig | false
569
+
570
+ /**
571
+ * @deprecated, moved to toolbarParams
572
+ */
573
+ toolbarVersion: 'toolbar'
574
+
575
+ /**
576
+ * Whether the user is authenticated
577
+ */
578
+ isAuthenticated: boolean
579
+
580
+ /**
581
+ * List of site apps with their IDs and URLs
582
+ */
583
+ siteApps: { id: string; url: string }[]
584
+
585
+ /**
586
+ * Whether heatmaps are enabled
587
+ */
588
+ heatmaps?: boolean
589
+
590
+ /**
591
+ * Whether to only capture identified users by default
592
+ */
593
+ defaultIdentifiedOnly?: boolean
594
+
595
+ /**
596
+ * Whether to capture dead clicks
597
+ */
598
+ captureDeadClicks?: boolean
599
+
600
+ /**
601
+ * Indicates if the team has any flags enabled (if not we don't need to load them)
602
+ */
603
+ hasFeatureFlags?: boolean
604
+ }
605
+
606
+ /**
607
+ * These are known events Leanbase events that can be processed by the `beforeCapture` function
608
+ * That means Leanbase functionality does not rely on receiving 100% of these for calculations
609
+ * So, it is safe to sample them to reduce the volume of events sent to Leanbase
610
+ */
611
+ export type KnownEventName =
612
+ | '$heatmaps_data'
613
+ | '$opt_in'
614
+ | '$exception'
615
+ | '$$heatmap'
616
+ | '$web_vitals'
617
+ | '$dead_click'
618
+ | '$autocapture'
619
+ | typeof COPY_AUTOCAPTURE_EVENT
620
+ | '$rageclick'
621
+
622
+ export type EventName = KnownUnsafeEditableEvent | KnownEventName | (string & {})
623
+
624
+ export interface PersistentStore {
625
+ _is_supported: () => boolean
626
+ _error: (error: any) => void
627
+ _parse: (name: string) => any
628
+ _get: (name: string) => any
629
+ _set: (
630
+ name: string,
631
+ value: any,
632
+ expire_days?: number | null,
633
+ cross_subdomain?: boolean,
634
+ secure?: boolean,
635
+ debug?: boolean
636
+ ) => void
637
+ _remove: (name: string, cross_subdomain?: boolean) => void
638
+ }
639
+
640
+ export interface RequestResponse {
641
+ statusCode: number
642
+ text?: string
643
+ json?: any
644
+ }
645
+
646
+ export type RequestCallback = (response: RequestResponse) => void
647
+
648
+ // See https://nextjs.org/docs/app/api-reference/functions/fetch#fetchurl-options
649
+ type NextOptions = { revalidate: false | 0 | number; tags: string[] }
650
+
651
+ export interface RequestWithOptions {
652
+ url: string
653
+ data?: Record<string, any> | Record<string, any>[]
654
+ headers?: Record<string, any>
655
+ transport?: 'XHR' | 'fetch' | 'sendBeacon'
656
+ method?: 'POST' | 'GET'
657
+ urlQueryArgs?: { compression: Compression }
658
+ callback?: RequestCallback
659
+ timeout?: number
660
+ noRetries?: boolean
661
+ disableTransport?: ('XHR' | 'fetch' | 'sendBeacon')[]
662
+ disableXHRCredentials?: boolean
663
+ compression?: Compression | 'best-available'
664
+ fetchOptions?: {
665
+ cache?: RequestInit['cache']
666
+ next?: NextOptions
667
+ }
668
+ }
669
+
670
+ export type InitiatorType =
671
+ | 'audio'
672
+ | 'beacon'
673
+ | 'body'
674
+ | 'css'
675
+ | 'early-hints'
676
+ | 'embed'
677
+ | 'fetch'
678
+ | 'frame'
679
+ | 'iframe'
680
+ | 'image'
681
+ | 'img'
682
+ | 'input'
683
+ | 'link'
684
+ | 'navigation'
685
+ | 'object'
686
+ | 'ping'
687
+ | 'script'
688
+ | 'track'
689
+ | 'video'
690
+ | 'xmlhttprequest'
691
+
692
+ export type NetworkRecordOptions = {
693
+ initiatorTypes?: InitiatorType[]
694
+ maskRequestFn?: (data: CapturedNetworkRequest) => CapturedNetworkRequest | undefined
695
+ recordHeaders?: boolean | { request: boolean; response: boolean }
696
+ recordBody?: boolean | string[] | { request: boolean | string[]; response: boolean | string[] }
697
+ recordInitialRequests?: boolean
698
+ recordPerformance?: boolean
699
+ performanceEntryTypeToObserve: string[]
700
+ payloadSizeLimitBytes: number
701
+ payloadHostDenyList?: string[]
702
+ }
703
+
704
+ export type NetworkRequest = {
705
+ url: string
706
+ }
707
+
708
+ export type Headers = Record<string, any>
709
+
710
+ type Writable<T> = { -readonly [P in keyof T]: T[P] }
711
+
712
+ export type CapturedNetworkRequest = Writable<Omit<PerformanceEntry, 'toJSON'>> & {
713
+ method?: string
714
+ initiatorType?: InitiatorType
715
+ status?: number
716
+ timeOrigin?: number
717
+ timestamp?: number
718
+ startTime?: number
719
+ endTime?: number
720
+ requestHeaders?: Headers
721
+ requestBody?: string | null
722
+ responseHeaders?: Headers
723
+ responseBody?: string | null
724
+ isInitial?: boolean
725
+ }
726
+
727
+ export interface SessionRecordingUrlTrigger {
728
+ url: string
729
+ matching: 'regex'
730
+ }
731
+
732
+ export type SessionStartReason =
733
+ | 'sampling_overridden'
734
+ | 'recording_initialized'
735
+ | 'linked_flag_matched'
736
+ | 'linked_flag_overridden'
737
+ | 'sampled'
738
+ | 'session_id_changed'
739
+ | 'url_trigger_matched'
740
+ | 'event_trigger_matched'
741
+
742
+ export type SessionIdChangedCallback = (
743
+ sessionId: string,
744
+ windowId: string | null | undefined,
745
+ changeReason?: { noSessionId: boolean; activityTimeout: boolean; sessionPastMaximumLength: boolean }
746
+ ) => void
747
+
748
+ export type LeanbasegCaptureOptions = {
749
+ /** If provided overrides the auto-generated event ID */
750
+ uuid?: string
751
+ disableGeoip?: boolean
752
+ /**
753
+ * Used when `$identify` is called
754
+ * Will set person properties overriding previous values
755
+ */
756
+ $set?: Properties
757
+
758
+ /**
759
+ * Used when `$identify` is called
760
+ * Will set person properties but only once, it will NOT override previous values
761
+ */
762
+ $set_once?: Properties
763
+
764
+ /**
765
+ * Used to override the desired endpoint for the captured event
766
+ */
767
+ _url?: string
768
+
769
+ /**
770
+ * key of queue, e.g. 'sessionRecording' vs 'event'
771
+ */
772
+ _batchKey?: string
773
+
774
+ /**
775
+ * If set, overrides and disables config.properties_string_max_length
776
+ */
777
+ _noTruncate?: boolean
778
+
779
+ /**
780
+ * If set, skips the batched queue
781
+ */
782
+ send_instantly?: boolean
783
+
784
+ /**
785
+ * If set, skips the client side rate limiting
786
+ */
787
+ skip_client_rate_limiting?: boolean
788
+
789
+ /**
790
+ * If set, overrides the desired transport method
791
+ */
792
+ transport?: RequestWithOptions['transport']
793
+
794
+ /**
795
+ * If set, overrides the current timestamp
796
+ */
797
+ timestamp?: Date
798
+ }
799
+
800
+ export interface CaptureResult {
801
+ uuid: string
802
+ event: EventName
803
+ properties: Properties
804
+ $set?: Properties
805
+ $set_once?: Properties
806
+ timestamp?: Date
807
+ }