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