@leanbase.com/js 0.1.2 → 0.2.0-alpha.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.
- package/dist/autocapture-utils.d.ts +17 -0
- package/dist/autocapture.d.ts +35 -0
- package/dist/config.d.ts +5 -0
- package/dist/constants.d.ts +54 -0
- package/dist/entrypoints/main.cjs.d.ts +4 -0
- package/dist/entrypoints/module.es.d.ts +4 -0
- package/dist/extensions/rageclick.d.ts +9 -0
- package/dist/iife.d.ts +19 -0
- package/dist/index.d.ts +2 -779
- package/dist/leanbase-logger.d.ts +6 -0
- package/dist/leanbase-persistence.d.ts +64 -0
- package/dist/leanbase.d.ts +49 -0
- package/dist/leanbase.iife.js +1 -4745
- package/dist/leanbase.iife.js.map +1 -1
- package/dist/main.js +2 -0
- package/dist/main.js.map +1 -0
- package/dist/module.d.ts +780 -0
- package/dist/module.js +2 -0
- package/dist/module.js.map +1 -0
- package/dist/page-view.d.ts +29 -0
- package/dist/scroll-manager.d.ts +21 -0
- package/dist/session-props.d.ts +32 -0
- package/dist/sessionid.d.ts +50 -0
- package/dist/storage.d.ts +24 -0
- package/{src/types.ts → dist/types.d.ts} +145 -235
- package/dist/utils/blocked-uas.d.ts +17 -0
- package/dist/utils/element-utils.d.ts +5 -0
- package/dist/utils/event-utils.d.ts +22 -0
- package/dist/utils/index.d.ts +44 -0
- package/dist/utils/request-utils.d.ts +12 -0
- package/dist/utils/simple-event-emitter.d.ts +6 -0
- package/dist/utils/user-agent-utils.d.ts +18 -0
- package/dist/uuidv7.d.ts +43 -0
- package/dist/version.d.ts +1 -0
- package/lib/autocapture-utils.d.ts +17 -0
- package/{src/autocapture-utils.ts → lib/autocapture-utils.js} +196 -280
- package/lib/autocapture-utils.js.map +1 -0
- package/lib/autocapture.d.ts +35 -0
- package/lib/autocapture.js +311 -0
- package/lib/autocapture.js.map +1 -0
- package/lib/config.d.ts +5 -0
- package/lib/config.js +7 -0
- package/lib/config.js.map +1 -0
- package/lib/constants.d.ts +54 -0
- package/{src/constants.ts → lib/constants.js} +58 -55
- package/lib/constants.js.map +1 -0
- package/lib/entrypoints/main.cjs.d.ts +4 -0
- package/lib/entrypoints/main.cjs.js +3 -0
- package/lib/entrypoints/main.cjs.js.map +1 -0
- package/lib/entrypoints/module.es.d.ts +4 -0
- package/lib/entrypoints/module.es.js +3 -0
- package/lib/entrypoints/module.es.js.map +1 -0
- package/lib/extensions/rageclick.d.ts +9 -0
- package/lib/extensions/rageclick.js +27 -0
- package/lib/extensions/rageclick.js.map +1 -0
- package/lib/iife.d.ts +19 -0
- package/lib/iife.js +67 -0
- package/lib/iife.js.map +1 -0
- package/{src/index.ts → lib/index.d.ts} +2 -2
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -0
- package/lib/leanbase-logger.d.ts +6 -0
- package/lib/leanbase-logger.js +25 -0
- package/lib/leanbase-logger.js.map +1 -0
- package/lib/leanbase-persistence.d.ts +64 -0
- package/lib/leanbase-persistence.js +287 -0
- package/lib/leanbase-persistence.js.map +1 -0
- package/lib/leanbase.d.ts +49 -0
- package/lib/leanbase.js +294 -0
- package/lib/leanbase.js.map +1 -0
- package/lib/page-view.d.ts +29 -0
- package/lib/page-view.js +81 -0
- package/lib/page-view.js.map +1 -0
- package/lib/scroll-manager.d.ts +21 -0
- package/lib/scroll-manager.js +79 -0
- package/lib/scroll-manager.js.map +1 -0
- package/lib/session-props.d.ts +32 -0
- package/lib/session-props.js +73 -0
- package/lib/session-props.js.map +1 -0
- package/lib/sessionid.d.ts +50 -0
- package/{src/sessionid.ts → lib/sessionid.js} +128 -204
- package/lib/sessionid.js.map +1 -0
- package/lib/storage.d.ts +24 -0
- package/{src/storage.ts → lib/storage.js} +182 -225
- package/lib/storage.js.map +1 -0
- package/lib/types.d.ts +544 -0
- package/lib/types.js +7 -0
- package/lib/types.js.map +1 -0
- package/lib/utils/blocked-uas.d.ts +17 -0
- package/{src/utils/blocked-uas.ts → lib/utils/blocked-uas.js} +19 -48
- package/lib/utils/blocked-uas.js.map +1 -0
- package/lib/utils/element-utils.d.ts +5 -0
- package/{src/utils/element-utils.ts → lib/utils/element-utils.js} +13 -17
- package/lib/utils/element-utils.js.map +1 -0
- package/lib/utils/event-utils.d.ts +22 -0
- package/lib/utils/event-utils.js +258 -0
- package/lib/utils/event-utils.js.map +1 -0
- package/lib/utils/index.d.ts +44 -0
- package/lib/utils/index.js +183 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/request-utils.d.ts +12 -0
- package/lib/utils/request-utils.js +107 -0
- package/lib/utils/request-utils.js.map +1 -0
- package/lib/utils/simple-event-emitter.d.ts +6 -0
- package/lib/utils/simple-event-emitter.js +24 -0
- package/lib/utils/simple-event-emitter.js.map +1 -0
- package/lib/utils/user-agent-utils.d.ts +18 -0
- package/lib/utils/user-agent-utils.js +369 -0
- package/lib/utils/user-agent-utils.js.map +1 -0
- package/lib/uuidv7.d.ts +43 -0
- package/{src/uuidv7.ts → lib/uuidv7.js} +103 -131
- package/lib/uuidv7.js.map +1 -0
- package/lib/version.d.ts +1 -0
- package/lib/version.js +2 -0
- package/lib/version.js.map +1 -0
- package/package.json +23 -11
- package/dist/index.cjs +0 -3032
- package/dist/index.cjs.map +0 -1
- package/dist/index.mjs +0 -3030
- package/dist/index.mjs.map +0 -1
- package/src/autocapture.ts +0 -415
- package/src/config.ts +0 -8
- package/src/extensions/rageclick.ts +0 -34
- package/src/iife.ts +0 -87
- package/src/leanbase-logger.ts +0 -26
- package/src/leanbase-persistence.ts +0 -374
- package/src/leanbase.ts +0 -424
- package/src/page-view.ts +0 -124
- package/src/scroll-manager.ts +0 -103
- package/src/session-props.ts +0 -114
- package/src/utils/event-utils.ts +0 -304
- package/src/utils/index.ts +0 -222
- package/src/utils/request-utils.ts +0 -128
- package/src/utils/simple-event-emitter.ts +0 -27
- package/src/utils/user-agent-utils.ts +0 -357
- package/src/version.ts +0 -1
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,544 @@
|
|
|
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 PostHog 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 PostHog to know the feature flag values immediately.
|
|
135
|
+
*
|
|
136
|
+
* After the SDK fetches feature flags from PostHog, 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 PostHog 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 PostHog should save referrer information.
|
|
248
|
+
*
|
|
249
|
+
* @default true
|
|
250
|
+
*/
|
|
251
|
+
save_referrer: boolean;
|
|
252
|
+
/**
|
|
253
|
+
* Determines whether PostHog 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`, PostHog 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
|
+
* A function to be called once the Leanbase scripts have loaded successfully.
|
|
288
|
+
*
|
|
289
|
+
* @param instance - The Leanbase instance that has been loaded.
|
|
290
|
+
*/
|
|
291
|
+
loaded: (instance: Leanbase) => void;
|
|
292
|
+
}
|
|
293
|
+
export interface RageclickConfig {
|
|
294
|
+
/**
|
|
295
|
+
* List of CSS selectors to ignore rageclicks on
|
|
296
|
+
* e.g. ['.my-calendar-button']
|
|
297
|
+
* we consider the tree of elements from the root to the target element of the click event
|
|
298
|
+
* so for the tree div > div > button > svg
|
|
299
|
+
* and ignore list config `['[id]']`
|
|
300
|
+
* we will ignore the rageclick if the click-target or its parents has any id
|
|
301
|
+
*
|
|
302
|
+
* Nothing is ignored when there's an empty ignorelist, e.g. []
|
|
303
|
+
* If no ignorelist is set, we default to ignoring .ph-no-rageclick
|
|
304
|
+
* If an element has .ph-no-capture, it will always be ignored by rageclick and autocapture
|
|
305
|
+
*/
|
|
306
|
+
css_selector_ignorelist?: string[];
|
|
307
|
+
}
|
|
308
|
+
export type PropertyMatchType = 'regex' | 'not_regex' | 'exact' | 'is_not' | 'icontains' | 'not_icontains';
|
|
309
|
+
export interface ErrorTrackingSuppressionRule {
|
|
310
|
+
type: 'AND' | 'OR';
|
|
311
|
+
values: ErrorTrackingSuppressionRuleValue[];
|
|
312
|
+
}
|
|
313
|
+
export interface ErrorTrackingSuppressionRuleValue {
|
|
314
|
+
key: '$exception_types' | '$exception_values';
|
|
315
|
+
operator: PropertyMatchType;
|
|
316
|
+
value: string | string[];
|
|
317
|
+
type: string;
|
|
318
|
+
}
|
|
319
|
+
export declare enum Compression {
|
|
320
|
+
GZipJS = "gzip-js",
|
|
321
|
+
Base64 = "base64"
|
|
322
|
+
}
|
|
323
|
+
export type SupportedWebVitalsMetrics = 'LCP' | 'CLS' | 'FCP' | 'INP';
|
|
324
|
+
export interface PerformanceCaptureConfig {
|
|
325
|
+
/**
|
|
326
|
+
* Works with session replay to use the browser's native performance observer to capture performance metrics
|
|
327
|
+
*/
|
|
328
|
+
network_timing?: boolean;
|
|
329
|
+
/**
|
|
330
|
+
* Use chrome's web vitals library to wrap fetch and capture web vitals
|
|
331
|
+
*/
|
|
332
|
+
web_vitals?: boolean;
|
|
333
|
+
/**
|
|
334
|
+
* We observe very large values reported by the Chrome web vitals library
|
|
335
|
+
* These outliers are likely not real, useful values, and we exclude them
|
|
336
|
+
* You can set this to 0 in order to include all values, NB this is not recommended
|
|
337
|
+
*
|
|
338
|
+
* @default 15 * 60 * 1000 (15 minutes)
|
|
339
|
+
*/
|
|
340
|
+
__web_vitals_max_value?: number;
|
|
341
|
+
/**
|
|
342
|
+
* By default all 4 metrics are captured
|
|
343
|
+
* You can set this config to restrict which metrics are captured
|
|
344
|
+
* e.g. ['CLS', 'FCP'] to only capture those two metrics
|
|
345
|
+
* NB setting this does not override whether the capture is enabled
|
|
346
|
+
*
|
|
347
|
+
* @default ['LCP', 'CLS', 'FCP', 'INP']
|
|
348
|
+
*/
|
|
349
|
+
web_vitals_allowed_metrics?: SupportedWebVitalsMetrics[];
|
|
350
|
+
/**
|
|
351
|
+
* We delay flushing web vitals metrics to reduce the number of events we send
|
|
352
|
+
* This is the maximum time we will wait before sending the metrics
|
|
353
|
+
*
|
|
354
|
+
* @default 5000
|
|
355
|
+
*/
|
|
356
|
+
web_vitals_delayed_flush_ms?: number;
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Remote configuration for the Leanbase instance
|
|
360
|
+
*
|
|
361
|
+
* All of these settings can be configured directly in your Leanbase instance
|
|
362
|
+
* Any configuration set in the client overrides the information from the server
|
|
363
|
+
*/
|
|
364
|
+
export interface RemoteConfig {
|
|
365
|
+
/**
|
|
366
|
+
* Supported compression algorithms
|
|
367
|
+
*/
|
|
368
|
+
supportedCompression: Compression[];
|
|
369
|
+
/**
|
|
370
|
+
* If set, disables autocapture
|
|
371
|
+
*/
|
|
372
|
+
autocapture_opt_out?: boolean;
|
|
373
|
+
/**
|
|
374
|
+
* originally capturePerformance was replay only and so boolean true
|
|
375
|
+
* is equivalent to { network_timing: true }
|
|
376
|
+
* now capture performance can be separately enabled within replay
|
|
377
|
+
* and as a standalone web vitals tracker
|
|
378
|
+
* people can have them enabled separately
|
|
379
|
+
* they work standalone but enhance each other
|
|
380
|
+
* TODO: deprecate this so we make a new config that doesn't need this explanation
|
|
381
|
+
*/
|
|
382
|
+
capturePerformance?: boolean | PerformanceCaptureConfig;
|
|
383
|
+
/**
|
|
384
|
+
* Whether we should use a custom endpoint for analytics
|
|
385
|
+
*
|
|
386
|
+
* @default { endpoint: "/e" }
|
|
387
|
+
*/
|
|
388
|
+
analytics?: {
|
|
389
|
+
endpoint?: string;
|
|
390
|
+
};
|
|
391
|
+
/**
|
|
392
|
+
* Whether the `$elements_chain` property should be sent as a string or as an array
|
|
393
|
+
*
|
|
394
|
+
* @default false
|
|
395
|
+
*/
|
|
396
|
+
elementsChainAsString?: boolean;
|
|
397
|
+
/**
|
|
398
|
+
* Error tracking configuration options
|
|
399
|
+
*/
|
|
400
|
+
errorTracking?: {
|
|
401
|
+
autocaptureExceptions?: boolean;
|
|
402
|
+
captureExtensionExceptions?: boolean;
|
|
403
|
+
suppressionRules?: ErrorTrackingSuppressionRule[];
|
|
404
|
+
};
|
|
405
|
+
/**
|
|
406
|
+
* This is currently in development and may have breaking changes without a major version bump
|
|
407
|
+
*/
|
|
408
|
+
autocaptureExceptions?: boolean | {
|
|
409
|
+
endpoint?: string;
|
|
410
|
+
};
|
|
411
|
+
/**
|
|
412
|
+
* @deprecated, moved to toolbarParams
|
|
413
|
+
*/
|
|
414
|
+
toolbarVersion: 'toolbar';
|
|
415
|
+
/**
|
|
416
|
+
* Whether the user is authenticated
|
|
417
|
+
*/
|
|
418
|
+
isAuthenticated: boolean;
|
|
419
|
+
/**
|
|
420
|
+
* List of site apps with their IDs and URLs
|
|
421
|
+
*/
|
|
422
|
+
siteApps: {
|
|
423
|
+
id: string;
|
|
424
|
+
url: string;
|
|
425
|
+
}[];
|
|
426
|
+
/**
|
|
427
|
+
* Whether heatmaps are enabled
|
|
428
|
+
*/
|
|
429
|
+
heatmaps?: boolean;
|
|
430
|
+
/**
|
|
431
|
+
* Whether to only capture identified users by default
|
|
432
|
+
*/
|
|
433
|
+
defaultIdentifiedOnly?: boolean;
|
|
434
|
+
/**
|
|
435
|
+
* Whether to capture dead clicks
|
|
436
|
+
*/
|
|
437
|
+
captureDeadClicks?: boolean;
|
|
438
|
+
/**
|
|
439
|
+
* Indicates if the team has any flags enabled (if not we don't need to load them)
|
|
440
|
+
*/
|
|
441
|
+
hasFeatureFlags?: boolean;
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* These are known events Leanbase events that can be processed by the `beforeCapture` function
|
|
445
|
+
* That means Leanbase functionality does not rely on receiving 100% of these for calculations
|
|
446
|
+
* So, it is safe to sample them to reduce the volume of events sent to Leanbase
|
|
447
|
+
*/
|
|
448
|
+
export type KnownEventName = '$heatmaps_data' | '$opt_in' | '$exception' | '$$heatmap' | '$web_vitals' | '$dead_click' | '$autocapture' | typeof COPY_AUTOCAPTURE_EVENT | '$rageclick';
|
|
449
|
+
export type EventName = KnownUnsafeEditableEvent | KnownEventName | (string & {});
|
|
450
|
+
export interface PersistentStore {
|
|
451
|
+
_is_supported: () => boolean;
|
|
452
|
+
_error: (error: any) => void;
|
|
453
|
+
_parse: (name: string) => any;
|
|
454
|
+
_get: (name: string) => any;
|
|
455
|
+
_set: (name: string, value: any, expire_days?: number | null, cross_subdomain?: boolean, secure?: boolean, debug?: boolean) => void;
|
|
456
|
+
_remove: (name: string, cross_subdomain?: boolean) => void;
|
|
457
|
+
}
|
|
458
|
+
export interface RequestResponse {
|
|
459
|
+
statusCode: number;
|
|
460
|
+
text?: string;
|
|
461
|
+
json?: any;
|
|
462
|
+
}
|
|
463
|
+
export type RequestCallback = (response: RequestResponse) => void;
|
|
464
|
+
type NextOptions = {
|
|
465
|
+
revalidate: false | 0 | number;
|
|
466
|
+
tags: string[];
|
|
467
|
+
};
|
|
468
|
+
export interface RequestWithOptions {
|
|
469
|
+
url: string;
|
|
470
|
+
data?: Record<string, any> | Record<string, any>[];
|
|
471
|
+
headers?: Record<string, any>;
|
|
472
|
+
transport?: 'XHR' | 'fetch' | 'sendBeacon';
|
|
473
|
+
method?: 'POST' | 'GET';
|
|
474
|
+
urlQueryArgs?: {
|
|
475
|
+
compression: Compression;
|
|
476
|
+
};
|
|
477
|
+
callback?: RequestCallback;
|
|
478
|
+
timeout?: number;
|
|
479
|
+
noRetries?: boolean;
|
|
480
|
+
disableTransport?: ('XHR' | 'fetch' | 'sendBeacon')[];
|
|
481
|
+
disableXHRCredentials?: boolean;
|
|
482
|
+
compression?: Compression | 'best-available';
|
|
483
|
+
fetchOptions?: {
|
|
484
|
+
cache?: RequestInit['cache'];
|
|
485
|
+
next?: NextOptions;
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
export type SessionIdChangedCallback = (sessionId: string, windowId: string | null | undefined, changeReason?: {
|
|
489
|
+
noSessionId: boolean;
|
|
490
|
+
activityTimeout: boolean;
|
|
491
|
+
sessionPastMaximumLength: boolean;
|
|
492
|
+
}) => void;
|
|
493
|
+
export type LeanbasegCaptureOptions = {
|
|
494
|
+
/** If provided overrides the auto-generated event ID */
|
|
495
|
+
uuid?: string;
|
|
496
|
+
disableGeoip?: boolean;
|
|
497
|
+
/**
|
|
498
|
+
* Used when `$identify` is called
|
|
499
|
+
* Will set person properties overriding previous values
|
|
500
|
+
*/
|
|
501
|
+
$set?: Properties;
|
|
502
|
+
/**
|
|
503
|
+
* Used when `$identify` is called
|
|
504
|
+
* Will set person properties but only once, it will NOT override previous values
|
|
505
|
+
*/
|
|
506
|
+
$set_once?: Properties;
|
|
507
|
+
/**
|
|
508
|
+
* Used to override the desired endpoint for the captured event
|
|
509
|
+
*/
|
|
510
|
+
_url?: string;
|
|
511
|
+
/**
|
|
512
|
+
* key of queue, e.g. 'sessionRecording' vs 'event'
|
|
513
|
+
*/
|
|
514
|
+
_batchKey?: string;
|
|
515
|
+
/**
|
|
516
|
+
* If set, overrides and disables config.properties_string_max_length
|
|
517
|
+
*/
|
|
518
|
+
_noTruncate?: boolean;
|
|
519
|
+
/**
|
|
520
|
+
* If set, skips the batched queue
|
|
521
|
+
*/
|
|
522
|
+
send_instantly?: boolean;
|
|
523
|
+
/**
|
|
524
|
+
* If set, skips the client side rate limiting
|
|
525
|
+
*/
|
|
526
|
+
skip_client_rate_limiting?: boolean;
|
|
527
|
+
/**
|
|
528
|
+
* If set, overrides the desired transport method
|
|
529
|
+
*/
|
|
530
|
+
transport?: RequestWithOptions['transport'];
|
|
531
|
+
/**
|
|
532
|
+
* If set, overrides the current timestamp
|
|
533
|
+
*/
|
|
534
|
+
timestamp?: Date;
|
|
535
|
+
};
|
|
536
|
+
export interface CaptureResult {
|
|
537
|
+
uuid: string;
|
|
538
|
+
event: EventName;
|
|
539
|
+
properties: Properties;
|
|
540
|
+
$set?: Properties;
|
|
541
|
+
$set_once?: Properties;
|
|
542
|
+
timestamp?: Date;
|
|
543
|
+
}
|
|
544
|
+
export {};
|
package/lib/types.js
ADDED
package/lib/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,sBAAsB,GAAG,mBAAmB,CAAA;AAwWzD,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;
|