@leanbase.com/js 0.1.3 → 0.2.0-alpha.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 (141) hide show
  1. package/LICENSE +37 -0
  2. package/dist/autocapture-utils.d.ts +17 -0
  3. package/dist/autocapture.d.ts +35 -0
  4. package/dist/config.d.ts +5 -0
  5. package/dist/consent.d.ts +25 -0
  6. package/dist/constants.d.ts +54 -0
  7. package/dist/entrypoints/main.cjs.d.ts +4 -0
  8. package/dist/entrypoints/module.es.d.ts +4 -0
  9. package/dist/extensions/rageclick.d.ts +9 -0
  10. package/dist/iife.d.ts +19 -0
  11. package/dist/index.d.ts +2 -779
  12. package/dist/leanbase-logger.d.ts +6 -0
  13. package/dist/leanbase-persistence.d.ts +64 -0
  14. package/dist/leanbase.d.ts +53 -0
  15. package/dist/leanbase.iife.js +1 -4747
  16. package/dist/leanbase.iife.js.map +1 -1
  17. package/dist/main.js +2 -0
  18. package/dist/main.js.map +1 -0
  19. package/dist/module.d.ts +856 -0
  20. package/dist/module.js +2 -0
  21. package/dist/module.js.map +1 -0
  22. package/dist/page-view.d.ts +29 -0
  23. package/dist/scroll-manager.d.ts +21 -0
  24. package/dist/session-props.d.ts +32 -0
  25. package/dist/sessionid.d.ts +50 -0
  26. package/dist/storage.d.ts +24 -0
  27. package/{src/types.ts → dist/types.d.ts} +200 -242
  28. package/dist/utils/blocked-uas.d.ts +17 -0
  29. package/dist/utils/element-utils.d.ts +5 -0
  30. package/dist/utils/event-utils.d.ts +22 -0
  31. package/dist/utils/index.d.ts +46 -0
  32. package/dist/utils/request-utils.d.ts +12 -0
  33. package/dist/utils/simple-event-emitter.d.ts +6 -0
  34. package/dist/utils/user-agent-utils.d.ts +18 -0
  35. package/dist/uuidv7.d.ts +43 -0
  36. package/dist/version.d.ts +1 -0
  37. package/lib/autocapture-utils.d.ts +17 -0
  38. package/{src/autocapture-utils.ts → lib/autocapture-utils.js} +196 -280
  39. package/lib/autocapture-utils.js.map +1 -0
  40. package/lib/autocapture.d.ts +35 -0
  41. package/lib/autocapture.js +311 -0
  42. package/lib/autocapture.js.map +1 -0
  43. package/lib/config.d.ts +5 -0
  44. package/lib/config.js +7 -0
  45. package/lib/config.js.map +1 -0
  46. package/lib/consent.d.ts +25 -0
  47. package/lib/consent.js +101 -0
  48. package/lib/consent.js.map +1 -0
  49. package/lib/constants.d.ts +54 -0
  50. package/{src/constants.ts → lib/constants.js} +50 -57
  51. package/lib/constants.js.map +1 -0
  52. package/lib/entrypoints/main.cjs.d.ts +4 -0
  53. package/lib/entrypoints/main.cjs.js +3 -0
  54. package/lib/entrypoints/main.cjs.js.map +1 -0
  55. package/lib/entrypoints/module.es.d.ts +4 -0
  56. package/lib/entrypoints/module.es.js +3 -0
  57. package/lib/entrypoints/module.es.js.map +1 -0
  58. package/lib/extensions/rageclick.d.ts +9 -0
  59. package/lib/extensions/rageclick.js +27 -0
  60. package/lib/extensions/rageclick.js.map +1 -0
  61. package/lib/iife.d.ts +19 -0
  62. package/lib/iife.js +67 -0
  63. package/lib/iife.js.map +1 -0
  64. package/{src/index.ts → lib/index.d.ts} +2 -2
  65. package/lib/index.js +2 -0
  66. package/lib/index.js.map +1 -0
  67. package/lib/leanbase-logger.d.ts +6 -0
  68. package/lib/leanbase-logger.js +25 -0
  69. package/lib/leanbase-logger.js.map +1 -0
  70. package/lib/leanbase-persistence.d.ts +64 -0
  71. package/lib/leanbase-persistence.js +287 -0
  72. package/lib/leanbase-persistence.js.map +1 -0
  73. package/lib/leanbase.d.ts +53 -0
  74. package/lib/leanbase.js +359 -0
  75. package/lib/leanbase.js.map +1 -0
  76. package/lib/page-view.d.ts +29 -0
  77. package/lib/page-view.js +81 -0
  78. package/lib/page-view.js.map +1 -0
  79. package/lib/scroll-manager.d.ts +21 -0
  80. package/lib/scroll-manager.js +79 -0
  81. package/lib/scroll-manager.js.map +1 -0
  82. package/lib/session-props.d.ts +32 -0
  83. package/lib/session-props.js +73 -0
  84. package/lib/session-props.js.map +1 -0
  85. package/lib/sessionid.d.ts +50 -0
  86. package/{src/sessionid.ts → lib/sessionid.js} +128 -204
  87. package/lib/sessionid.js.map +1 -0
  88. package/lib/storage.d.ts +24 -0
  89. package/{src/storage.ts → lib/storage.js} +182 -225
  90. package/lib/storage.js.map +1 -0
  91. package/lib/types.d.ts +592 -0
  92. package/lib/types.js +7 -0
  93. package/lib/types.js.map +1 -0
  94. package/lib/utils/blocked-uas.d.ts +17 -0
  95. package/{src/utils/blocked-uas.ts → lib/utils/blocked-uas.js} +19 -48
  96. package/lib/utils/blocked-uas.js.map +1 -0
  97. package/lib/utils/element-utils.d.ts +5 -0
  98. package/{src/utils/element-utils.ts → lib/utils/element-utils.js} +13 -17
  99. package/lib/utils/element-utils.js.map +1 -0
  100. package/lib/utils/event-utils.d.ts +22 -0
  101. package/lib/utils/event-utils.js +258 -0
  102. package/lib/utils/event-utils.js.map +1 -0
  103. package/lib/utils/index.d.ts +46 -0
  104. package/lib/utils/index.js +192 -0
  105. package/lib/utils/index.js.map +1 -0
  106. package/lib/utils/request-utils.d.ts +12 -0
  107. package/lib/utils/request-utils.js +107 -0
  108. package/lib/utils/request-utils.js.map +1 -0
  109. package/lib/utils/simple-event-emitter.d.ts +6 -0
  110. package/lib/utils/simple-event-emitter.js +24 -0
  111. package/lib/utils/simple-event-emitter.js.map +1 -0
  112. package/lib/utils/user-agent-utils.d.ts +18 -0
  113. package/lib/utils/user-agent-utils.js +369 -0
  114. package/lib/utils/user-agent-utils.js.map +1 -0
  115. package/lib/uuidv7.d.ts +43 -0
  116. package/{src/uuidv7.ts → lib/uuidv7.js} +103 -131
  117. package/lib/uuidv7.js.map +1 -0
  118. package/lib/version.d.ts +1 -0
  119. package/lib/version.js +2 -0
  120. package/lib/version.js.map +1 -0
  121. package/package.json +56 -45
  122. package/dist/index.cjs +0 -3034
  123. package/dist/index.cjs.map +0 -1
  124. package/dist/index.mjs +0 -3032
  125. package/dist/index.mjs.map +0 -1
  126. package/src/autocapture.ts +0 -415
  127. package/src/config.ts +0 -8
  128. package/src/extensions/rageclick.ts +0 -34
  129. package/src/iife.ts +0 -87
  130. package/src/leanbase-logger.ts +0 -26
  131. package/src/leanbase-persistence.ts +0 -374
  132. package/src/leanbase.ts +0 -424
  133. package/src/page-view.ts +0 -124
  134. package/src/scroll-manager.ts +0 -103
  135. package/src/session-props.ts +0 -114
  136. package/src/utils/event-utils.ts +0 -304
  137. package/src/utils/index.ts +0 -222
  138. package/src/utils/request-utils.ts +0 -128
  139. package/src/utils/simple-event-emitter.ts +0 -27
  140. package/src/utils/user-agent-utils.ts +0 -357
  141. package/src/version.ts +0 -1
package/lib/types.d.ts ADDED
@@ -0,0 +1,592 @@
1
+ import { FeatureFlagValue, JsonType, PostHogCoreOptions } from '@posthog/core';
2
+ import { KnownUnsafeEditableEvent } from '@posthog/core';
3
+ import { Leanbase } from './leanbase';
4
+ export declare const COPY_AUTOCAPTURE_EVENT = "$copy_autocapture";
5
+ export type Property = any;
6
+ export type Properties = Record<string, Property>;
7
+ export type AutocaptureCompatibleElement = 'a' | 'button' | 'form' | 'input' | 'select' | 'textarea' | 'label';
8
+ export type DomAutocaptureEvents = 'click' | 'change' | 'submit';
9
+ export interface BootstrapConfig {
10
+ distinctId?: string;
11
+ isIdentifiedId?: boolean;
12
+ featureFlags?: Record<string, FeatureFlagValue>;
13
+ featureFlagPayloads?: Record<string, JsonType>;
14
+ /**
15
+ * 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:
16
+ * - unique to this user
17
+ * - a valid UUID v7
18
+ * - the timestamp part must be <= the timestamp of the first event in the session
19
+ * - the timestamp of the last event in the session must be < the timestamp part + 24 hours
20
+ * **/
21
+ sessionID?: string;
22
+ }
23
+ /**
24
+ * If an array is passed for an allowlist, autocapture events will only be sent for elements matching
25
+ * at least one of the elements in the array. Multiple allowlists can be used
26
+ */
27
+ export interface AutocaptureConfig {
28
+ /**
29
+ * List of URLs to allow autocapture on, can be strings to match
30
+ * or regexes e.g. ['https://example.com', 'test.com/.*']
31
+ * this is useful when you want to autocapture on specific pages only
32
+ *
33
+ * if you set both url_allowlist and url_ignorelist,
34
+ * we check the allowlist first and then the ignorelist.
35
+ * the ignorelist can override the allowlist
36
+ */
37
+ url_allowlist?: (string | RegExp)[];
38
+ /**
39
+ * List of URLs to not allow autocapture on, can be strings to match
40
+ * or regexes e.g. ['https://example.com', 'test.com/.*']
41
+ * this is useful when you want to autocapture on most pages but not some specific ones
42
+ *
43
+ * if you set both url_allowlist and url_ignorelist,
44
+ * we check the allowlist first and then the ignorelist.
45
+ * the ignorelist can override the allowlist
46
+ */
47
+ url_ignorelist?: (string | RegExp)[];
48
+ /**
49
+ * List of DOM events to allow autocapture on e.g. ['click', 'change', 'submit']
50
+ */
51
+ dom_event_allowlist?: DomAutocaptureEvents[];
52
+ /**
53
+ * List of DOM elements to allow autocapture on
54
+ * e.g. ['a', 'button', 'form', 'input', 'select', 'textarea', 'label']
55
+ *
56
+ * We consider the tree of elements from the root to the target element of the click event
57
+ * so for the tree `div > div > button > svg`
58
+ * if the allowlist has `button` then we allow the capture when the `button` or the `svg` is the click target
59
+ * but not if either of the `div`s are detected as the click target
60
+ */
61
+ element_allowlist?: AutocaptureCompatibleElement[];
62
+ /**
63
+ * List of CSS selectors to allow autocapture on
64
+ * e.g. ['[ph-capture]']
65
+ * we consider the tree of elements from the root to the target element of the click event
66
+ * so for the tree div > div > button > svg
67
+ * and allow list config `['[id]']`
68
+ * we will capture the click if the click-target or its parents has any id
69
+ *
70
+ * Everything is allowed when there's no allowlist
71
+ */
72
+ css_selector_allowlist?: string[];
73
+ /**
74
+ * Exclude certain element attributes from autocapture
75
+ * E.g. ['aria-label'] or [data-attr-pii]
76
+ */
77
+ element_attribute_ignorelist?: string[];
78
+ /**
79
+ * When set to true, autocapture will capture the text of any element that is cut or copied.
80
+ */
81
+ capture_copied_text?: boolean;
82
+ }
83
+ export interface LeanbaseConfig extends Partial<PostHogCoreOptions> {
84
+ /**
85
+ * API host for Leanbase
86
+ * @default 'https://i.leanbase.co'
87
+ */
88
+ host?: string;
89
+ /**
90
+ * The token for your Leanbase project.
91
+ * It should NOT be provided manually in the config, but rather passed as the first parameter to `leanbase.init()`.
92
+ */
93
+ token: string;
94
+ /**
95
+ * Enables debug mode, which provides more verbose logging for development purposes.
96
+ * @default false
97
+ */
98
+ debug?: boolean;
99
+ /**
100
+ * Determines whether Leanbase should autocapture events.
101
+ * This setting does not affect capturing pageview events (see `capture_pageview`).
102
+ *
103
+ * by default autocapture is ignored on elements that match a `ph-no-capture` css class on the element or a parent
104
+ * @default true
105
+ */
106
+ autocapture: boolean | AutocaptureConfig;
107
+ /**
108
+ * Determines whether Leanbase should capture pageview events automatically.
109
+ * Can be:
110
+ * - `true`: Capture regular pageviews (default)
111
+ * - `false`: Don't capture any pageviews
112
+ * - `'history_change'`: Only capture pageviews on history API changes (pushState, replaceState, popstate)
113
+ *
114
+ * @default true
115
+ */
116
+ capture_pageview: boolean | 'history_change';
117
+ /**
118
+ * Determines the session idle timeout in seconds.
119
+ * Any new event that's happened after this timeout will create a new session.
120
+ *
121
+ * @default 30 * 60 -- 30 minutes
122
+ */
123
+ session_idle_timeout_seconds: number;
124
+ /**
125
+ * An object containing the `distinctID`, `isIdentifiedID`, and `featureFlags` keys,
126
+ * where `distinctID` is a string, and `featureFlags` is an object of key-value pairs.
127
+ *
128
+ * Since there is a delay between initializing Leanbase and fetching feature flags,
129
+ * feature flags are not always available immediately.
130
+ * This makes them unusable if you want to do something like redirecting a user
131
+ * to a different page based on a feature flag.
132
+ *
133
+ * You can, therefore, fetch the feature flags in your server and pre-fill them here,
134
+ * allowing Leanbase to know the feature flag values immediately.
135
+ *
136
+ * After the SDK fetches feature flags from Leanbase, it will use those flag values instead of bootstrapped ones.
137
+ *
138
+ * @default {}
139
+ */
140
+ bootstrap: BootstrapConfig;
141
+ /**
142
+ * Determines whether Leanbase should capture pageleave events.
143
+ * If set to `true`, it will capture pageleave events for all pages.
144
+ * If set to `'if_capture_pageview'`, it will only capture pageleave events if `capture_pageview` is also set to `true` or `'history_change'`.
145
+ *
146
+ * @default 'if_capture_pageview'
147
+ */
148
+ capture_pageleave: boolean | 'if_capture_pageview';
149
+ /**
150
+ * Determines whether Leanbase should capture rage clicks.
151
+ *
152
+ * 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
153
+ * @default true
154
+ */
155
+ rageclick: boolean | RageclickConfig;
156
+ /**
157
+ * Determines where to store the Leanbase persistence information.
158
+ */
159
+ persistence: 'localStorage' | 'cookie' | 'memory' | 'localStorage+cookie' | 'sessionStorage';
160
+ /**
161
+ * The name for the super properties persistent store
162
+ *
163
+ * @default ''
164
+ */
165
+ persistence_name: string;
166
+ /**
167
+ * Prevent autocapture from capturing any attribute names on elements.
168
+ *
169
+ * @default false
170
+ */
171
+ mask_all_element_attributes: boolean;
172
+ /**
173
+ * Prevent autocapture from capturing `textContent` on elements.
174
+ *
175
+ * @default false
176
+ */
177
+ mask_all_text: boolean;
178
+ /**
179
+ * Used to extend the list of campaign parameters that are saved by default.
180
+ *
181
+ * @see {CAMPAIGN_PARAMS} from './utils/event-utils' - Default campaign parameters like utm_source, utm_medium, etc.
182
+ * @default []
183
+ */
184
+ custom_campaign_params: string[];
185
+ /**
186
+ * Mask personal data properties from the current URL.
187
+ * This will mask personal data properties such as advertising IDs (gclid, fbclid, etc.), and you can also add
188
+ * custom properties to mask with `custom_personal_data_properties`.
189
+ * @default false
190
+ * @see {PERSONAL_DATA_CAMPAIGN_PARAMS} - Default campaign parameters that are masked by default.
191
+ * @see {LeanbaseConfig.custom_personal_data_properties} - Custom list of personal data properties to mask.
192
+ */
193
+ mask_personal_data_properties: boolean;
194
+ /**
195
+ * Custom list of personal data properties to mask.
196
+ *
197
+ * E.g. if you added `email` to this list, then any `email` property in the URL will be masked.
198
+ * https://www.example.com/login?email=john.doe%40example.com => https://www.example.com/login?email=<MASKED>
199
+ *
200
+ * @default []
201
+ * @see {LeanbaseConfig.mask_personal_data_properties} - Must be enabled for this to take effect.
202
+ */
203
+ custom_personal_data_properties: string[];
204
+ /**
205
+ * Determines the number of days to store cookies for.
206
+ *
207
+ * @default 365
208
+ */
209
+ cookie_expiration: number;
210
+ /**
211
+ * Determines whether Leanbase should use secure cookies.
212
+ * If this is `true`, Leanbase cookies will be marked as secure,
213
+ * meaning they will only be transmitted over HTTPS.
214
+ *
215
+ * @default window.location.protocol === 'https:'
216
+ */
217
+ secure_cookie: boolean;
218
+ /**
219
+ * Determines if cookie should be set on the top level domain (example.com).
220
+ * If leanbase-js is loaded on a subdomain (test.example.com), and `cross_subdomain_cookie` is set to false,
221
+ * it'll set the cookie on the subdomain only (test.example.com).
222
+ *
223
+ * 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.
224
+ * The current list of excluded platforms is `herokuapp.com`, `vercel.app`, and `netlify.app`.
225
+ *
226
+ * @see `isCrossDomainCookie`
227
+ * @default true
228
+ */
229
+ cross_subdomain_cookie: boolean;
230
+ /**
231
+ * Determines whether Leanbase should disable persistence.
232
+ * 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.
233
+ *
234
+ * @default false
235
+ */
236
+ disable_persistence: boolean;
237
+ /**
238
+ * Enables cookieless mode. In this mode, Leanbase will not set any cookies, or use session or local storage. User
239
+ * identity is handled by generating a privacy-preserving hash on Leanbase's servers.
240
+ * - 'always' - enable cookieless mode immediately on startup, use this if you do not intend to show a cookie banner
241
+ * - '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 Leanbase will use cookies and local storage as usual.
242
+ *
243
+ * 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.
244
+ * */
245
+ cookieless_mode?: 'always' | 'on_reject';
246
+ /**
247
+ * Determines whether Leanbase should save referrer information.
248
+ *
249
+ * @default true
250
+ */
251
+ save_referrer: boolean;
252
+ /**
253
+ * Determines whether Leanbase should save marketing parameters.
254
+ * These are `utm_*` paramaters and friends.
255
+ *
256
+ * @see {CAMPAIGN_PARAMS} from './utils/event-utils' - Default campaign parameters like utm_source, utm_medium, etc.
257
+ * @default true
258
+ */
259
+ save_campaign_params: boolean;
260
+ /**
261
+ * Determines whether to disable scroll properties.
262
+ * These allow you to keep track of how far down someone scrolled in your website.
263
+ *
264
+ * @default false
265
+ */
266
+ disable_scroll_properties?: boolean;
267
+ /**
268
+ * Let the pageview scroll stats use a custom css selector for the root element, e.g. `main`
269
+ * It will use `window.document.documentElement` if not specified.
270
+ */
271
+ scroll_root_selector?: string | string[];
272
+ /**
273
+ * Determines if users should be opted out of user agent filtering such as googlebot or other bots.
274
+ * If this is set to `true`, Leanbase will set `$browser_type` to either `bot` or `browser` for all events,
275
+ * but will process all events as if they were from a browser.
276
+ *
277
+ * @default false
278
+ */
279
+ opt_out_useragent_filter: boolean;
280
+ /**
281
+ * Determines the maximum length of the properties string that can be sent with capture calls.
282
+ *
283
+ * @default 65535
284
+ */
285
+ properties_string_max_length: number;
286
+ /**
287
+ * Determines whether Leanbase should respect the Do Not Track header when computing
288
+ * consent in `ConsentManager`.
289
+ *
290
+ * @see `ConsentManager`
291
+ * @default false
292
+ */
293
+ respect_dnt: boolean;
294
+ /**
295
+ * Determines if users should be opted out of Leanbase tracking by default,
296
+ * requiring additional logic to opt them into capturing by calling `leanbase.opt_in_capturing()`.
297
+ *
298
+ * @default false
299
+ */
300
+ opt_out_capturing_by_default: boolean;
301
+ /**
302
+ * Determines where we'll save the information about whether users are opted out of capturing.
303
+ *
304
+ * @default 'localStorage'
305
+ */
306
+ opt_out_capturing_persistence_type: 'localStorage' | 'cookie';
307
+ /**
308
+ * Determines if users should be opted out of Leanbase data storage by this Leanbase instance by default,
309
+ * requiring additional logic to opt them into capturing by calling `leanbase.opt_in_capturing()`.
310
+ *
311
+ * @default false
312
+ */
313
+ opt_out_persistence_by_default?: boolean;
314
+ /** @deprecated Use `consent_persistence_name` instead. This will be removed in a future major version. **/
315
+ opt_out_capturing_cookie_prefix: string | null;
316
+ /**
317
+ * Determines the key for the cookie / local storage used to store the information about whether users are opted in/out of capturing.
318
+ * When `null`, we used a key based on your token.
319
+ *
320
+ * @default null
321
+ * @see `ConsentManager._storageKey`
322
+ */
323
+ consent_persistence_name: string | null;
324
+ /**
325
+ * Function to get the device ID.
326
+ * This doesn't usually need to be set, but can be useful if you want to use a custom device ID.
327
+ *
328
+ * @param uuid - The UUID we would use for the device ID.
329
+ * @returns The device ID.
330
+ *
331
+ * @default (uuid) => uuid
332
+ */
333
+ getDeviceId: (uuid: string) => string;
334
+ /**
335
+ * A function to be called once the Leanbase scripts have loaded successfully.
336
+ *
337
+ * @param instance - The Leanbase instance that has been loaded.
338
+ */
339
+ loaded: (instance: Leanbase) => void;
340
+ }
341
+ export interface RageclickConfig {
342
+ /**
343
+ * List of CSS selectors to ignore rageclicks on
344
+ * e.g. ['.my-calendar-button']
345
+ * we consider the tree of elements from the root to the target element of the click event
346
+ * so for the tree div > div > button > svg
347
+ * and ignore list config `['[id]']`
348
+ * we will ignore the rageclick if the click-target or its parents has any id
349
+ *
350
+ * Nothing is ignored when there's an empty ignorelist, e.g. []
351
+ * If no ignorelist is set, we default to ignoring .ph-no-rageclick
352
+ * If an element has .ph-no-capture, it will always be ignored by rageclick and autocapture
353
+ */
354
+ css_selector_ignorelist?: string[];
355
+ }
356
+ export type PropertyMatchType = 'regex' | 'not_regex' | 'exact' | 'is_not' | 'icontains' | 'not_icontains';
357
+ export interface ErrorTrackingSuppressionRule {
358
+ type: 'AND' | 'OR';
359
+ values: ErrorTrackingSuppressionRuleValue[];
360
+ }
361
+ export interface ErrorTrackingSuppressionRuleValue {
362
+ key: '$exception_types' | '$exception_values';
363
+ operator: PropertyMatchType;
364
+ value: string | string[];
365
+ type: string;
366
+ }
367
+ export declare enum Compression {
368
+ GZipJS = "gzip-js",
369
+ Base64 = "base64"
370
+ }
371
+ export type SupportedWebVitalsMetrics = 'LCP' | 'CLS' | 'FCP' | 'INP';
372
+ export interface PerformanceCaptureConfig {
373
+ /**
374
+ * Works with session replay to use the browser's native performance observer to capture performance metrics
375
+ */
376
+ network_timing?: boolean;
377
+ /**
378
+ * Use chrome's web vitals library to wrap fetch and capture web vitals
379
+ */
380
+ web_vitals?: boolean;
381
+ /**
382
+ * We observe very large values reported by the Chrome web vitals library
383
+ * These outliers are likely not real, useful values, and we exclude them
384
+ * You can set this to 0 in order to include all values, NB this is not recommended
385
+ *
386
+ * @default 15 * 60 * 1000 (15 minutes)
387
+ */
388
+ __web_vitals_max_value?: number;
389
+ /**
390
+ * By default all 4 metrics are captured
391
+ * You can set this config to restrict which metrics are captured
392
+ * e.g. ['CLS', 'FCP'] to only capture those two metrics
393
+ * NB setting this does not override whether the capture is enabled
394
+ *
395
+ * @default ['LCP', 'CLS', 'FCP', 'INP']
396
+ */
397
+ web_vitals_allowed_metrics?: SupportedWebVitalsMetrics[];
398
+ /**
399
+ * We delay flushing web vitals metrics to reduce the number of events we send
400
+ * This is the maximum time we will wait before sending the metrics
401
+ *
402
+ * @default 5000
403
+ */
404
+ web_vitals_delayed_flush_ms?: number;
405
+ }
406
+ /**
407
+ * Remote configuration for the Leanbase instance
408
+ *
409
+ * All of these settings can be configured directly in your Leanbase instance
410
+ * Any configuration set in the client overrides the information from the server
411
+ */
412
+ export interface RemoteConfig {
413
+ /**
414
+ * Supported compression algorithms
415
+ */
416
+ supportedCompression: Compression[];
417
+ /**
418
+ * If set, disables autocapture
419
+ */
420
+ autocapture_opt_out?: boolean;
421
+ /**
422
+ * originally capturePerformance was replay only and so boolean true
423
+ * is equivalent to { network_timing: true }
424
+ * now capture performance can be separately enabled within replay
425
+ * and as a standalone web vitals tracker
426
+ * people can have them enabled separately
427
+ * they work standalone but enhance each other
428
+ * TODO: deprecate this so we make a new config that doesn't need this explanation
429
+ */
430
+ capturePerformance?: boolean | PerformanceCaptureConfig;
431
+ /**
432
+ * Whether we should use a custom endpoint for analytics
433
+ *
434
+ * @default { endpoint: "/e" }
435
+ */
436
+ analytics?: {
437
+ endpoint?: string;
438
+ };
439
+ /**
440
+ * Whether the `$elements_chain` property should be sent as a string or as an array
441
+ *
442
+ * @default false
443
+ */
444
+ elementsChainAsString?: boolean;
445
+ /**
446
+ * Error tracking configuration options
447
+ */
448
+ errorTracking?: {
449
+ autocaptureExceptions?: boolean;
450
+ captureExtensionExceptions?: boolean;
451
+ suppressionRules?: ErrorTrackingSuppressionRule[];
452
+ };
453
+ /**
454
+ * This is currently in development and may have breaking changes without a major version bump
455
+ */
456
+ autocaptureExceptions?: boolean | {
457
+ endpoint?: string;
458
+ };
459
+ /**
460
+ * @deprecated, moved to toolbarParams
461
+ */
462
+ toolbarVersion: 'toolbar';
463
+ /**
464
+ * Whether the user is authenticated
465
+ */
466
+ isAuthenticated: boolean;
467
+ /**
468
+ * List of site apps with their IDs and URLs
469
+ */
470
+ siteApps: {
471
+ id: string;
472
+ url: string;
473
+ }[];
474
+ /**
475
+ * Whether heatmaps are enabled
476
+ */
477
+ heatmaps?: boolean;
478
+ /**
479
+ * Whether to only capture identified users by default
480
+ */
481
+ defaultIdentifiedOnly?: boolean;
482
+ /**
483
+ * Whether to capture dead clicks
484
+ */
485
+ captureDeadClicks?: boolean;
486
+ /**
487
+ * Indicates if the team has any flags enabled (if not we don't need to load them)
488
+ */
489
+ hasFeatureFlags?: boolean;
490
+ }
491
+ /**
492
+ * These are known events Leanbase events that can be processed by the `beforeCapture` function
493
+ * That means Leanbase functionality does not rely on receiving 100% of these for calculations
494
+ * So, it is safe to sample them to reduce the volume of events sent to Leanbase
495
+ */
496
+ export type KnownEventName = '$heatmaps_data' | '$opt_in' | '$exception' | '$$heatmap' | '$web_vitals' | '$dead_click' | '$autocapture' | typeof COPY_AUTOCAPTURE_EVENT | '$rageclick';
497
+ export type EventName = KnownUnsafeEditableEvent | KnownEventName | (string & {});
498
+ export interface PersistentStore {
499
+ _is_supported: () => boolean;
500
+ _error: (error: any) => void;
501
+ _parse: (name: string) => any;
502
+ _get: (name: string) => any;
503
+ _set: (name: string, value: any, expire_days?: number | null, cross_subdomain?: boolean, secure?: boolean, debug?: boolean) => void;
504
+ _remove: (name: string, cross_subdomain?: boolean) => void;
505
+ }
506
+ export interface RequestResponse {
507
+ statusCode: number;
508
+ text?: string;
509
+ json?: any;
510
+ }
511
+ export type RequestCallback = (response: RequestResponse) => void;
512
+ type NextOptions = {
513
+ revalidate: false | 0 | number;
514
+ tags: string[];
515
+ };
516
+ export interface RequestWithOptions {
517
+ url: string;
518
+ data?: Record<string, any> | Record<string, any>[];
519
+ headers?: Record<string, any>;
520
+ transport?: 'XHR' | 'fetch' | 'sendBeacon';
521
+ method?: 'POST' | 'GET';
522
+ urlQueryArgs?: {
523
+ compression: Compression;
524
+ };
525
+ callback?: RequestCallback;
526
+ timeout?: number;
527
+ noRetries?: boolean;
528
+ disableTransport?: ('XHR' | 'fetch' | 'sendBeacon')[];
529
+ disableXHRCredentials?: boolean;
530
+ compression?: Compression | 'best-available';
531
+ fetchOptions?: {
532
+ cache?: RequestInit['cache'];
533
+ next?: NextOptions;
534
+ };
535
+ }
536
+ export type SessionIdChangedCallback = (sessionId: string, windowId: string | null | undefined, changeReason?: {
537
+ noSessionId: boolean;
538
+ activityTimeout: boolean;
539
+ sessionPastMaximumLength: boolean;
540
+ }) => void;
541
+ export type LeanbasegCaptureOptions = {
542
+ /** If provided overrides the auto-generated event ID */
543
+ uuid?: string;
544
+ disableGeoip?: boolean;
545
+ /**
546
+ * Used when `$identify` is called
547
+ * Will set person properties overriding previous values
548
+ */
549
+ $set?: Properties;
550
+ /**
551
+ * Used when `$identify` is called
552
+ * Will set person properties but only once, it will NOT override previous values
553
+ */
554
+ $set_once?: Properties;
555
+ /**
556
+ * Used to override the desired endpoint for the captured event
557
+ */
558
+ _url?: string;
559
+ /**
560
+ * key of queue, e.g. 'sessionRecording' vs 'event'
561
+ */
562
+ _batchKey?: string;
563
+ /**
564
+ * If set, overrides and disables config.properties_string_max_length
565
+ */
566
+ _noTruncate?: boolean;
567
+ /**
568
+ * If set, skips the batched queue
569
+ */
570
+ send_instantly?: boolean;
571
+ /**
572
+ * If set, skips the client side rate limiting
573
+ */
574
+ skip_client_rate_limiting?: boolean;
575
+ /**
576
+ * If set, overrides the desired transport method
577
+ */
578
+ transport?: RequestWithOptions['transport'];
579
+ /**
580
+ * If set, overrides the current timestamp
581
+ */
582
+ timestamp?: Date;
583
+ };
584
+ export interface CaptureResult {
585
+ uuid: string;
586
+ event: EventName;
587
+ properties: Properties;
588
+ $set?: Properties;
589
+ $set_once?: Properties;
590
+ timestamp?: Date;
591
+ }
592
+ export {};
package/lib/types.js ADDED
@@ -0,0 +1,7 @@
1
+ export const COPY_AUTOCAPTURE_EVENT = '$copy_autocapture';
2
+ export var Compression;
3
+ (function (Compression) {
4
+ Compression["GZipJS"] = "gzip-js";
5
+ Compression["Base64"] = "base64";
6
+ })(Compression || (Compression = {}));
7
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,sBAAsB,GAAG,mBAAmB,CAAA;AA+ZzD,MAAM,CAAN,IAAY,WAGX;AAHD,WAAY,WAAW;IACnB,iCAAkB,CAAA;IAClB,gCAAiB,CAAA;AACrB,CAAC,EAHW,WAAW,KAAX,WAAW,QAGtB"}
@@ -0,0 +1,17 @@
1
+ export declare const DEFAULT_BLOCKED_UA_STRS: string[];
2
+ /**
3
+ * Block various web spiders from executing our JS and sending false capturing data
4
+ */
5
+ export declare const isBlockedUA: (ua: string, customBlockedUserAgents: string[]) => boolean;
6
+ export interface NavigatorUAData {
7
+ brands?: {
8
+ brand: string;
9
+ version: string;
10
+ }[];
11
+ }
12
+ declare global {
13
+ interface Navigator {
14
+ userAgentData?: NavigatorUAData;
15
+ }
16
+ }
17
+ export declare const isLikelyBot: (navigator: Navigator | undefined, customBlockedUserAgents: string[]) => boolean;