@leanbase.com/js 0.1.0 → 0.1.2

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/index.d.ts CHANGED
@@ -1,30 +1,779 @@
1
- import { PostHogCore, PostHogCoreOptions, PostHogFetchOptions, PostHogFetchResponse, PostHogPersistedProperty, PostHogEventProperties, PostHogCaptureOptions } from '@posthog/core';
1
+ import { PostHogCoreOptions, FeatureFlagValue, JsonType, PostHogCore, PostHogFetchOptions, PostHogFetchResponse, PostHogPersistedProperty, PostHogEventProperties } from '@posthog/core';
2
2
 
3
- interface LeanbaseOptions extends Partial<PostHogCoreOptions> {
3
+ type Property = any;
4
+ type Properties = Record<string, Property>;
5
+ type AutocaptureCompatibleElement = 'a' | 'button' | 'form' | 'input' | 'select' | 'textarea' | 'label';
6
+ type DomAutocaptureEvents = 'click' | 'change' | 'submit';
7
+ interface BootstrapConfig {
8
+ distinctId?: string;
9
+ isIdentifiedId?: boolean;
10
+ featureFlags?: Record<string, FeatureFlagValue>;
11
+ featureFlagPayloads?: Record<string, JsonType>;
4
12
  /**
5
- * Enable autocapture of clicks and form interactions
6
- * @default true
13
+ * 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:
14
+ * - unique to this user
15
+ * - a valid UUID v7
16
+ * - the timestamp part must be <= the timestamp of the first event in the session
17
+ * - the timestamp of the last event in the session must be < the timestamp part + 24 hours
18
+ * **/
19
+ sessionID?: string;
20
+ }
21
+ /**
22
+ * If an array is passed for an allowlist, autocapture events will only be sent for elements matching
23
+ * at least one of the elements in the array. Multiple allowlists can be used
24
+ */
25
+ interface AutocaptureConfig {
26
+ /**
27
+ * List of URLs to allow autocapture on, can be strings to match
28
+ * or regexes e.g. ['https://example.com', 'test.com/.*']
29
+ * this is useful when you want to autocapture on specific pages only
30
+ *
31
+ * if you set both url_allowlist and url_ignorelist,
32
+ * we check the allowlist first and then the ignorelist.
33
+ * the ignorelist can override the allowlist
34
+ */
35
+ url_allowlist?: (string | RegExp)[];
36
+ /**
37
+ * List of URLs to not allow autocapture on, can be strings to match
38
+ * or regexes e.g. ['https://example.com', 'test.com/.*']
39
+ * this is useful when you want to autocapture on most pages but not some specific ones
40
+ *
41
+ * if you set both url_allowlist and url_ignorelist,
42
+ * we check the allowlist first and then the ignorelist.
43
+ * the ignorelist can override the allowlist
44
+ */
45
+ url_ignorelist?: (string | RegExp)[];
46
+ /**
47
+ * List of DOM events to allow autocapture on e.g. ['click', 'change', 'submit']
48
+ */
49
+ dom_event_allowlist?: DomAutocaptureEvents[];
50
+ /**
51
+ * List of DOM elements to allow autocapture on
52
+ * e.g. ['a', 'button', 'form', 'input', 'select', 'textarea', 'label']
53
+ *
54
+ * We consider the tree of elements from the root to the target element of the click event
55
+ * so for the tree `div > div > button > svg`
56
+ * if the allowlist has `button` then we allow the capture when the `button` or the `svg` is the click target
57
+ * but not if either of the `div`s are detected as the click target
7
58
  */
8
- autocapture?: boolean;
59
+ element_allowlist?: AutocaptureCompatibleElement[];
60
+ /**
61
+ * List of CSS selectors to allow autocapture on
62
+ * e.g. ['[ph-capture]']
63
+ * we consider the tree of elements from the root to the target element of the click event
64
+ * so for the tree div > div > button > svg
65
+ * and allow list config `['[id]']`
66
+ * we will capture the click if the click-target or its parents has any id
67
+ *
68
+ * Everything is allowed when there's no allowlist
69
+ */
70
+ css_selector_allowlist?: string[];
71
+ /**
72
+ * Exclude certain element attributes from autocapture
73
+ * E.g. ['aria-label'] or [data-attr-pii]
74
+ */
75
+ element_attribute_ignorelist?: string[];
76
+ /**
77
+ * When set to true, autocapture will capture the text of any element that is cut or copied.
78
+ */
79
+ capture_copied_text?: boolean;
80
+ }
81
+ interface LeanbaseConfig extends Partial<PostHogCoreOptions> {
9
82
  /**
10
83
  * API host for Leanbase
11
84
  * @default 'https://i.leanbase.co'
12
85
  */
13
86
  host?: string;
87
+ /**
88
+ * The token for your Leanbase project.
89
+ * It should NOT be provided manually in the config, but rather passed as the first parameter to `leanbase.init()`.
90
+ */
91
+ token: string;
92
+ /**
93
+ * Enables debug mode, which provides more verbose logging for development purposes.
94
+ * @default false
95
+ */
96
+ debug?: boolean;
97
+ /**
98
+ * Determines whether Leanbase should autocapture events.
99
+ * This setting does not affect capturing pageview events (see `capture_pageview`).
100
+ *
101
+ * by default autocapture is ignored on elements that match a `ph-no-capture` css class on the element or a parent
102
+ * @default true
103
+ */
104
+ autocapture: boolean | AutocaptureConfig;
105
+ /**
106
+ * Determines whether Leanbase should capture pageview events automatically.
107
+ * Can be:
108
+ * - `true`: Capture regular pageviews (default)
109
+ * - `false`: Don't capture any pageviews
110
+ * - `'history_change'`: Only capture pageviews on history API changes (pushState, replaceState, popstate)
111
+ *
112
+ * @default true
113
+ */
114
+ capture_pageview: boolean | 'history_change';
115
+ /**
116
+ * Determines the session idle timeout in seconds.
117
+ * Any new event that's happened after this timeout will create a new session.
118
+ *
119
+ * @default 30 * 60 -- 30 minutes
120
+ */
121
+ session_idle_timeout_seconds: number;
122
+ /**
123
+ * An object containing the `distinctID`, `isIdentifiedID`, and `featureFlags` keys,
124
+ * where `distinctID` is a string, and `featureFlags` is an object of key-value pairs.
125
+ *
126
+ * Since there is a delay between initializing PostHog and fetching feature flags,
127
+ * feature flags are not always available immediately.
128
+ * This makes them unusable if you want to do something like redirecting a user
129
+ * to a different page based on a feature flag.
130
+ *
131
+ * You can, therefore, fetch the feature flags in your server and pre-fill them here,
132
+ * allowing PostHog to know the feature flag values immediately.
133
+ *
134
+ * After the SDK fetches feature flags from PostHog, it will use those flag values instead of bootstrapped ones.
135
+ *
136
+ * @default {}
137
+ */
138
+ bootstrap: BootstrapConfig;
139
+ /**
140
+ * Determines whether Leanbase should capture pageleave events.
141
+ * If set to `true`, it will capture pageleave events for all pages.
142
+ * If set to `'if_capture_pageview'`, it will only capture pageleave events if `capture_pageview` is also set to `true` or `'history_change'`.
143
+ *
144
+ * @default 'if_capture_pageview'
145
+ */
146
+ capture_pageleave: boolean | 'if_capture_pageview';
147
+ /**
148
+ * Determines whether Leanbase should capture rage clicks.
149
+ *
150
+ * 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
151
+ * @default true
152
+ */
153
+ rageclick: boolean | RageclickConfig;
154
+ /**
155
+ * Determines where to store the Leanbase persistence information.
156
+ */
157
+ persistence: 'localStorage' | 'cookie' | 'memory' | 'localStorage+cookie' | 'sessionStorage';
158
+ /**
159
+ * The name for the super properties persistent store
160
+ *
161
+ * @default ''
162
+ */
163
+ persistence_name: string;
164
+ /**
165
+ * Prevent autocapture from capturing any attribute names on elements.
166
+ *
167
+ * @default false
168
+ */
169
+ mask_all_element_attributes: boolean;
170
+ /**
171
+ * Prevent autocapture from capturing `textContent` on elements.
172
+ *
173
+ * @default false
174
+ */
175
+ mask_all_text: boolean;
176
+ /**
177
+ * Used to extend the list of campaign parameters that are saved by default.
178
+ *
179
+ * @see {CAMPAIGN_PARAMS} from './utils/event-utils' - Default campaign parameters like utm_source, utm_medium, etc.
180
+ * @default []
181
+ */
182
+ custom_campaign_params: string[];
183
+ /**
184
+ * Mask personal data properties from the current URL.
185
+ * This will mask personal data properties such as advertising IDs (gclid, fbclid, etc.), and you can also add
186
+ * custom properties to mask with `custom_personal_data_properties`.
187
+ * @default false
188
+ * @see {PERSONAL_DATA_CAMPAIGN_PARAMS} - Default campaign parameters that are masked by default.
189
+ * @see {LeanbaseConfig.custom_personal_data_properties} - Custom list of personal data properties to mask.
190
+ */
191
+ mask_personal_data_properties: boolean;
192
+ /**
193
+ * Custom list of personal data properties to mask.
194
+ *
195
+ * E.g. if you added `email` to this list, then any `email` property in the URL will be masked.
196
+ * https://www.example.com/login?email=john.doe%40example.com => https://www.example.com/login?email=<MASKED>
197
+ *
198
+ * @default []
199
+ * @see {LeanbaseConfig.mask_personal_data_properties} - Must be enabled for this to take effect.
200
+ */
201
+ custom_personal_data_properties: string[];
202
+ /**
203
+ * Determines the number of days to store cookies for.
204
+ *
205
+ * @default 365
206
+ */
207
+ cookie_expiration: number;
208
+ /**
209
+ * Determines whether Leanbase should use secure cookies.
210
+ * If this is `true`, Leanbase cookies will be marked as secure,
211
+ * meaning they will only be transmitted over HTTPS.
212
+ *
213
+ * @default window.location.protocol === 'https:'
214
+ */
215
+ secure_cookie: boolean;
216
+ /**
217
+ * Determines if cookie should be set on the top level domain (example.com).
218
+ * If leanbase-js is loaded on a subdomain (test.example.com), and `cross_subdomain_cookie` is set to false,
219
+ * it'll set the cookie on the subdomain only (test.example.com).
220
+ *
221
+ * 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.
222
+ * The current list of excluded platforms is `herokuapp.com`, `vercel.app`, and `netlify.app`.
223
+ *
224
+ * @see `isCrossDomainCookie`
225
+ * @default true
226
+ */
227
+ cross_subdomain_cookie: boolean;
228
+ /**
229
+ * Determines whether Leanbase should disable persistence.
230
+ * 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.
231
+ *
232
+ * @default false
233
+ */
234
+ disable_persistence: boolean;
235
+ /**
236
+ * Enables cookieless mode. In this mode, Leanbase will not set any cookies, or use session or local storage. User
237
+ * identity is handled by generating a privacy-preserving hash on Leanbase's servers.
238
+ * - 'always' - enable cookieless mode immediately on startup, use this if you do not intend to show a cookie banner
239
+ * - '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.
240
+ *
241
+ * 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.
242
+ * */
243
+ cookieless_mode?: 'always' | 'on_reject';
244
+ /**
245
+ * Determines whether PostHog should save referrer information.
246
+ *
247
+ * @default true
248
+ */
249
+ save_referrer: boolean;
250
+ /**
251
+ * Determines whether PostHog should save marketing parameters.
252
+ * These are `utm_*` paramaters and friends.
253
+ *
254
+ * @see {CAMPAIGN_PARAMS} from './utils/event-utils' - Default campaign parameters like utm_source, utm_medium, etc.
255
+ * @default true
256
+ */
257
+ save_campaign_params: boolean;
258
+ /**
259
+ * Determines whether to disable scroll properties.
260
+ * These allow you to keep track of how far down someone scrolled in your website.
261
+ *
262
+ * @default false
263
+ */
264
+ disable_scroll_properties?: boolean;
265
+ /**
266
+ * Let the pageview scroll stats use a custom css selector for the root element, e.g. `main`
267
+ * It will use `window.document.documentElement` if not specified.
268
+ */
269
+ scroll_root_selector?: string | string[];
270
+ /**
271
+ * Determines if users should be opted out of user agent filtering such as googlebot or other bots.
272
+ * If this is set to `true`, PostHog will set `$browser_type` to either `bot` or `browser` for all events,
273
+ * but will process all events as if they were from a browser.
274
+ *
275
+ * @default false
276
+ */
277
+ opt_out_useragent_filter: boolean;
278
+ /**
279
+ * Determines the maximum length of the properties string that can be sent with capture calls.
280
+ *
281
+ * @default 65535
282
+ */
283
+ properties_string_max_length: number;
284
+ /**
285
+ * A function to be called once the Leanbase scripts have loaded successfully.
286
+ *
287
+ * @param instance - The Leanbase instance that has been loaded.
288
+ */
289
+ loaded: (instance: Leanbase) => void;
14
290
  }
15
- declare class Leanbase extends PostHogCore {
291
+ interface RageclickConfig {
292
+ /**
293
+ * List of CSS selectors to ignore rageclicks on
294
+ * e.g. ['.my-calendar-button']
295
+ * we consider the tree of elements from the root to the target element of the click event
296
+ * so for the tree div > div > button > svg
297
+ * and ignore list config `['[id]']`
298
+ * we will ignore the rageclick if the click-target or its parents has any id
299
+ *
300
+ * Nothing is ignored when there's an empty ignorelist, e.g. []
301
+ * If no ignorelist is set, we default to ignoring .ph-no-rageclick
302
+ * If an element has .ph-no-capture, it will always be ignored by rageclick and autocapture
303
+ */
304
+ css_selector_ignorelist?: string[];
305
+ }
306
+ type PropertyMatchType = 'regex' | 'not_regex' | 'exact' | 'is_not' | 'icontains' | 'not_icontains';
307
+ interface ErrorTrackingSuppressionRule {
308
+ type: 'AND' | 'OR';
309
+ values: ErrorTrackingSuppressionRuleValue[];
310
+ }
311
+ interface ErrorTrackingSuppressionRuleValue {
312
+ key: '$exception_types' | '$exception_values';
313
+ operator: PropertyMatchType;
314
+ value: string | string[];
315
+ type: string;
316
+ }
317
+ declare enum Compression {
318
+ GZipJS = "gzip-js",
319
+ Base64 = "base64"
320
+ }
321
+ type SupportedWebVitalsMetrics = 'LCP' | 'CLS' | 'FCP' | 'INP';
322
+ interface PerformanceCaptureConfig {
323
+ /**
324
+ * Works with session replay to use the browser's native performance observer to capture performance metrics
325
+ */
326
+ network_timing?: boolean;
327
+ /**
328
+ * Use chrome's web vitals library to wrap fetch and capture web vitals
329
+ */
330
+ web_vitals?: boolean;
331
+ /**
332
+ * We observe very large values reported by the Chrome web vitals library
333
+ * These outliers are likely not real, useful values, and we exclude them
334
+ * You can set this to 0 in order to include all values, NB this is not recommended
335
+ *
336
+ * @default 15 * 60 * 1000 (15 minutes)
337
+ */
338
+ __web_vitals_max_value?: number;
339
+ /**
340
+ * By default all 4 metrics are captured
341
+ * You can set this config to restrict which metrics are captured
342
+ * e.g. ['CLS', 'FCP'] to only capture those two metrics
343
+ * NB setting this does not override whether the capture is enabled
344
+ *
345
+ * @default ['LCP', 'CLS', 'FCP', 'INP']
346
+ */
347
+ web_vitals_allowed_metrics?: SupportedWebVitalsMetrics[];
348
+ /**
349
+ * We delay flushing web vitals metrics to reduce the number of events we send
350
+ * This is the maximum time we will wait before sending the metrics
351
+ *
352
+ * @default 5000
353
+ */
354
+ web_vitals_delayed_flush_ms?: number;
355
+ }
356
+ /**
357
+ * Remote configuration for the Leanbase instance
358
+ *
359
+ * All of these settings can be configured directly in your Leanbase instance
360
+ * Any configuration set in the client overrides the information from the server
361
+ */
362
+ interface RemoteConfig {
363
+ /**
364
+ * Supported compression algorithms
365
+ */
366
+ supportedCompression: Compression[];
367
+ /**
368
+ * If set, disables autocapture
369
+ */
370
+ autocapture_opt_out?: boolean;
371
+ /**
372
+ * originally capturePerformance was replay only and so boolean true
373
+ * is equivalent to { network_timing: true }
374
+ * now capture performance can be separately enabled within replay
375
+ * and as a standalone web vitals tracker
376
+ * people can have them enabled separately
377
+ * they work standalone but enhance each other
378
+ * TODO: deprecate this so we make a new config that doesn't need this explanation
379
+ */
380
+ capturePerformance?: boolean | PerformanceCaptureConfig;
381
+ /**
382
+ * Whether we should use a custom endpoint for analytics
383
+ *
384
+ * @default { endpoint: "/e" }
385
+ */
386
+ analytics?: {
387
+ endpoint?: string;
388
+ };
389
+ /**
390
+ * Whether the `$elements_chain` property should be sent as a string or as an array
391
+ *
392
+ * @default false
393
+ */
394
+ elementsChainAsString?: boolean;
395
+ /**
396
+ * Error tracking configuration options
397
+ */
398
+ errorTracking?: {
399
+ autocaptureExceptions?: boolean;
400
+ captureExtensionExceptions?: boolean;
401
+ suppressionRules?: ErrorTrackingSuppressionRule[];
402
+ };
403
+ /**
404
+ * This is currently in development and may have breaking changes without a major version bump
405
+ */
406
+ autocaptureExceptions?: boolean | {
407
+ endpoint?: string;
408
+ };
409
+ /**
410
+ * @deprecated, moved to toolbarParams
411
+ */
412
+ toolbarVersion: 'toolbar';
413
+ /**
414
+ * Whether the user is authenticated
415
+ */
416
+ isAuthenticated: boolean;
417
+ /**
418
+ * List of site apps with their IDs and URLs
419
+ */
420
+ siteApps: {
421
+ id: string;
422
+ url: string;
423
+ }[];
424
+ /**
425
+ * Whether heatmaps are enabled
426
+ */
427
+ heatmaps?: boolean;
428
+ /**
429
+ * Whether to only capture identified users by default
430
+ */
431
+ defaultIdentifiedOnly?: boolean;
432
+ /**
433
+ * Whether to capture dead clicks
434
+ */
435
+ captureDeadClicks?: boolean;
436
+ /**
437
+ * Indicates if the team has any flags enabled (if not we don't need to load them)
438
+ */
439
+ hasFeatureFlags?: boolean;
440
+ }
441
+ interface RequestResponse {
442
+ statusCode: number;
443
+ text?: string;
444
+ json?: any;
445
+ }
446
+ type RequestCallback = (response: RequestResponse) => void;
447
+ type NextOptions = {
448
+ revalidate: false | 0 | number;
449
+ tags: string[];
450
+ };
451
+ interface RequestWithOptions {
452
+ url: string;
453
+ data?: Record<string, any> | Record<string, any>[];
454
+ headers?: Record<string, any>;
455
+ transport?: 'XHR' | 'fetch' | 'sendBeacon';
456
+ method?: 'POST' | 'GET';
457
+ urlQueryArgs?: {
458
+ compression: Compression;
459
+ };
460
+ callback?: RequestCallback;
461
+ timeout?: number;
462
+ noRetries?: boolean;
463
+ disableTransport?: ('XHR' | 'fetch' | 'sendBeacon')[];
464
+ disableXHRCredentials?: boolean;
465
+ compression?: Compression | 'best-available';
466
+ fetchOptions?: {
467
+ cache?: RequestInit['cache'];
468
+ next?: NextOptions;
469
+ };
470
+ }
471
+ type SessionIdChangedCallback = (sessionId: string, windowId: string | null | undefined, changeReason?: {
472
+ noSessionId: boolean;
473
+ activityTimeout: boolean;
474
+ sessionPastMaximumLength: boolean;
475
+ }) => void;
476
+ type LeanbasegCaptureOptions = {
477
+ /** If provided overrides the auto-generated event ID */
478
+ uuid?: string;
479
+ disableGeoip?: boolean;
480
+ /**
481
+ * Used when `$identify` is called
482
+ * Will set person properties overriding previous values
483
+ */
484
+ $set?: Properties;
485
+ /**
486
+ * Used when `$identify` is called
487
+ * Will set person properties but only once, it will NOT override previous values
488
+ */
489
+ $set_once?: Properties;
490
+ /**
491
+ * Used to override the desired endpoint for the captured event
492
+ */
493
+ _url?: string;
494
+ /**
495
+ * key of queue, e.g. 'sessionRecording' vs 'event'
496
+ */
497
+ _batchKey?: string;
498
+ /**
499
+ * If set, overrides and disables config.properties_string_max_length
500
+ */
501
+ _noTruncate?: boolean;
502
+ /**
503
+ * If set, skips the batched queue
504
+ */
505
+ send_instantly?: boolean;
506
+ /**
507
+ * If set, skips the client side rate limiting
508
+ */
509
+ skip_client_rate_limiting?: boolean;
510
+ /**
511
+ * If set, overrides the desired transport method
512
+ */
513
+ transport?: RequestWithOptions['transport'];
514
+ /**
515
+ * If set, overrides the current timestamp
516
+ */
517
+ timestamp?: Date;
518
+ };
519
+
520
+ /**
521
+ * Leanbase Persistence Object
522
+ * @constructor
523
+ */
524
+ declare class LeanbasePersistence {
525
+ private _config;
526
+ props: Properties;
16
527
  private _storage;
17
- private _storageKey;
18
- constructor(apiKey: string, options?: LeanbaseOptions);
528
+ private _campaign_params_saved;
529
+ private readonly _name;
530
+ _disabled: boolean | undefined;
531
+ private _secure;
532
+ private _expire_days;
533
+ private _default_expiry;
534
+ private _cross_subdomain;
535
+ /**
536
+ * @param {LeanbaseConfig} config initial PostHog configuration
537
+ * @param {boolean=} isDisabled should persistence be disabled (e.g. because of consent management)
538
+ */
539
+ constructor(config: LeanbaseConfig, isDisabled?: boolean);
540
+ /**
541
+ * Returns whether persistence is disabled. Only available in SDKs > 1.257.1. Do not use on extensions, otherwise
542
+ * it'll break backwards compatibility for any version before 1.257.1.
543
+ */
544
+ isDisabled?(): boolean;
545
+ private _buildStorage;
546
+ properties(): Properties;
547
+ load(): void;
548
+ /**
549
+ * NOTE: Saving frequently causes issues with Recordings and Consent Management Platform (CMP) tools which
550
+ * observe cookie changes, and modify their UI, often causing infinite loops.
551
+ * As such callers of this should ideally check that the data has changed beforehand
552
+ */
553
+ save(): void;
554
+ remove(): void;
555
+ clear(): void;
556
+ /**
557
+ * @param {Object} props
558
+ * @param {*=} default_value
559
+ * @param {number=} days
560
+ */
561
+ register_once(props: Properties, default_value: any, days?: number): boolean;
562
+ /**
563
+ * @param {Object} props
564
+ * @param {number=} days
565
+ */
566
+ register(props: Properties, days?: number): boolean;
567
+ unregister(prop: string): void;
568
+ update_campaign_params(): void;
569
+ update_search_keyword(): void;
570
+ update_referrer_info(): void;
571
+ set_initial_person_info(): void;
572
+ get_initial_props(): Properties;
573
+ safe_merge(props: Properties): Properties;
574
+ update_config(config: LeanbaseConfig, oldConfig: LeanbaseConfig, isDisabled?: boolean): void;
575
+ set_disabled(disabled: boolean): void;
576
+ set_cross_subdomain(cross_subdomain: boolean): void;
577
+ set_secure(secure: boolean): void;
578
+ set_event_timer(event_name: string, timestamp: number): void;
579
+ remove_event_timer(event_name: string): number;
580
+ get_property(prop: string): any;
581
+ set_property(prop: string, to: any): void;
582
+ }
583
+
584
+ declare class RageClick {
585
+ clicks: {
586
+ x: number;
587
+ y: number;
588
+ timestamp: number;
589
+ }[];
590
+ constructor();
591
+ isRageClick(x: number, y: number, timestamp: number): boolean;
592
+ }
593
+
594
+ declare class Autocapture {
595
+ instance: Leanbase;
596
+ _initialized: boolean;
597
+ _isDisabledServerSide: boolean | null;
598
+ _elementSelectors: Set<string> | null;
599
+ rageclicks: RageClick;
600
+ _elementsChainAsString: boolean;
601
+ constructor(instance: Leanbase);
602
+ private get _config();
603
+ _addDomEventHandlers(): void;
604
+ startIfEnabled(): void;
605
+ onRemoteConfig(response: RemoteConfig): void;
606
+ setElementSelectors(selectors: Set<string>): void;
607
+ getElementSelectors(element: Element | null): string[] | null;
608
+ get isEnabled(): boolean;
609
+ private _captureEvent;
610
+ isBrowserSupported(): boolean;
611
+ }
612
+
613
+ declare class SessionIdManager {
614
+ private readonly _sessionIdGenerator;
615
+ private readonly _windowIdGenerator;
616
+ private _config;
617
+ private _persistence;
618
+ private _windowId;
619
+ private _sessionId;
620
+ private readonly _window_id_storage_key;
621
+ private readonly _primary_window_exists_storage_key;
622
+ private _sessionStartTimestamp;
623
+ private _sessionActivityTimestamp;
624
+ private _sessionIdChangedHandlers;
625
+ private readonly _sessionTimeoutMs;
626
+ private _enforceIdleTimeout;
627
+ private _beforeUnloadListener;
628
+ private _eventEmitter;
629
+ on(event: 'forcedIdleReset', handler: () => void): () => void;
630
+ constructor(instance: Leanbase, sessionIdGenerator?: () => string, windowIdGenerator?: () => string);
631
+ get sessionTimeoutMs(): number;
632
+ onSessionId(callback: SessionIdChangedCallback): () => void;
633
+ private _canUseSessionStorage;
634
+ private _setWindowId;
635
+ private _getWindowId;
636
+ private _setSessionId;
637
+ private _getSessionId;
638
+ resetSessionId(): void;
639
+ /**
640
+ * Cleans up resources used by SessionIdManager.
641
+ * Should be called when the SessionIdManager is no longer needed to prevent memory leaks.
642
+ */
643
+ destroy(): void;
644
+ private _listenToReloadWindow;
645
+ private _sessionHasBeenIdleTooLong;
646
+ checkAndGetSessionAndWindowId(readOnly?: boolean, _timestamp?: number | null): {
647
+ sessionId: string;
648
+ windowId: string;
649
+ sessionStartTimestamp: number;
650
+ changeReason: {
651
+ noSessionId: boolean;
652
+ activityTimeout: boolean;
653
+ sessionPastMaximumLength: boolean;
654
+ } | undefined;
655
+ lastActivityTimestamp: number;
656
+ };
657
+ private _resetIdleTimer;
658
+ }
659
+
660
+ interface LegacySessionSourceProps {
661
+ initialPathName: string;
662
+ referringDomain: string;
663
+ utm_medium?: string;
664
+ utm_source?: string;
665
+ utm_campaign?: string;
666
+ utm_content?: string;
667
+ utm_term?: string;
668
+ }
669
+ interface CurrentSessionSourceProps {
670
+ r: string;
671
+ u: string | undefined;
672
+ }
673
+ interface StoredSessionSourceProps {
674
+ sessionId: string;
675
+ props: LegacySessionSourceProps | CurrentSessionSourceProps;
676
+ }
677
+ declare class SessionPropsManager {
678
+ private readonly _instance;
679
+ private readonly _sessionIdManager;
680
+ private readonly _persistence;
681
+ private readonly _sessionSourceParamGenerator;
682
+ constructor(instance: Leanbase, sessionIdManager: SessionIdManager, persistence: LeanbasePersistence, sessionSourceParamGenerator?: (instance?: Leanbase) => LegacySessionSourceProps | CurrentSessionSourceProps);
683
+ _getStored(): StoredSessionSourceProps | undefined;
684
+ _onSessionIdCallback: (sessionId: string) => void;
685
+ getSetOnceProps(): Record<string, any>;
686
+ getSessionProps(): Record<string, any>;
687
+ }
688
+
689
+ interface PageViewEventProperties {
690
+ $pageview_id?: string;
691
+ $prev_pageview_id?: string;
692
+ $prev_pageview_pathname?: string;
693
+ $prev_pageview_duration?: number;
694
+ $prev_pageview_last_scroll?: number;
695
+ $prev_pageview_last_scroll_percentage?: number;
696
+ $prev_pageview_max_scroll?: number;
697
+ $prev_pageview_max_scroll_percentage?: number;
698
+ $prev_pageview_last_content?: number;
699
+ $prev_pageview_last_content_percentage?: number;
700
+ $prev_pageview_max_content?: number;
701
+ $prev_pageview_max_content_percentage?: number;
702
+ }
703
+ declare class PageViewManager {
704
+ _currentPageview?: {
705
+ timestamp: Date;
706
+ pageViewId: string | undefined;
707
+ pathname: string | undefined;
708
+ };
709
+ _instance: Leanbase;
710
+ constructor(instance: Leanbase);
711
+ doPageView(timestamp: Date, pageViewId?: string): PageViewEventProperties;
712
+ doPageLeave(timestamp: Date): PageViewEventProperties;
713
+ doEvent(): PageViewEventProperties;
714
+ private _previousPageViewProperties;
715
+ }
716
+
717
+ interface ScrollContext {
718
+ maxScrollHeight?: number;
719
+ maxScrollY?: number;
720
+ lastScrollY?: number;
721
+ maxContentHeight?: number;
722
+ maxContentY?: number;
723
+ lastContentY?: number;
724
+ }
725
+ declare class ScrollManager {
726
+ private _instance;
727
+ private _context;
728
+ constructor(_instance: Leanbase);
729
+ getContext(): ScrollContext | undefined;
730
+ resetContext(): ScrollContext | undefined;
731
+ private _updateScrollData;
732
+ startMeasuringScrollPosition(): void;
733
+ scrollElement(): Element | undefined;
734
+ scrollY(): number;
735
+ scrollX(): number;
736
+ }
737
+
738
+ declare class Leanbase extends PostHogCore {
739
+ config: LeanbaseConfig;
740
+ scrollManager: ScrollManager;
741
+ pageViewManager: PageViewManager;
742
+ replayAutocapture?: Autocapture;
743
+ persistence?: LeanbasePersistence;
744
+ sessionPersistence?: LeanbasePersistence;
745
+ sessionManager?: SessionIdManager;
746
+ sessionPropsManager?: SessionPropsManager;
747
+ isRemoteConfigLoaded?: boolean;
748
+ personProcessingSetOncePropertiesSent: boolean;
749
+ isLoaded: boolean;
750
+ initialPageviewCaptured: boolean;
751
+ visibilityStateListener: (() => void) | null;
752
+ constructor(token: string, config?: Partial<LeanbaseConfig>);
753
+ init(token: string, config: Partial<LeanbaseConfig>): void;
754
+ captureInitialPageview(): void;
755
+ capturePageLeave(): void;
756
+ loadRemoteConfig(): Promise<void>;
757
+ onRemoteConfig(config: RemoteConfig): void;
19
758
  fetch(url: string, options: PostHogFetchOptions): Promise<PostHogFetchResponse>;
759
+ setConfig(config: Partial<LeanbaseConfig>): void;
20
760
  getLibraryId(): string;
21
761
  getLibraryVersion(): string;
22
762
  getCustomUserAgent(): void;
23
763
  getPersistedProperty<T>(key: PostHogPersistedProperty): T | undefined;
24
764
  setPersistedProperty<T>(key: PostHogPersistedProperty, value: T | null): void;
25
- capture(event: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
26
- identify(distinctId?: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
765
+ calculateEventProperties(eventName: string, eventProperties: PostHogEventProperties, timestamp: Date, uuid: string, readOnly?: boolean): Properties;
766
+ isIdentified(): boolean;
767
+ /**
768
+ * Add additional set_once properties to the event when creating a person profile. This allows us to create the
769
+ * profile with mostly-accurate properties, despite earlier events not setting them. We do this by storing them in
770
+ * persistence.
771
+ * @param dataSetOnce
772
+ */
773
+ calculateSetOnceProperties(dataSetOnce?: Properties): Properties | undefined;
774
+ capture(event: string, properties?: PostHogEventProperties, options?: LeanbasegCaptureOptions): void;
775
+ identify(distinctId?: string, properties?: PostHogEventProperties, options?: LeanbasegCaptureOptions): void;
27
776
  destroy(): void;
28
777
  }
29
778
 
30
- export { Leanbase, type LeanbaseOptions };
779
+ export { Leanbase, type LeanbaseConfig as LeanbaseOptions };