@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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.cjs.js","sourceRoot":"","sources":["../../src/entrypoints/main.cjs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAGtC,OAAO,EAAE,QAAQ,EAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.es.js","sourceRoot":"","sources":["../../src/entrypoints/module.es.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAGtC,OAAO,EAAE,QAAQ,EAAE,CAAA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Naive rage click implementation: If mouse has not moved further than RAGE_CLICK_THRESHOLD_PX
|
|
2
|
+
// over RAGE_CLICK_CLICK_COUNT clicks with max RAGE_CLICK_TIMEOUT_MS between clicks, it's
|
|
3
|
+
// counted as a rage click
|
|
4
|
+
const RAGE_CLICK_THRESHOLD_PX = 30;
|
|
5
|
+
const RAGE_CLICK_TIMEOUT_MS = 1000;
|
|
6
|
+
const RAGE_CLICK_CLICK_COUNT = 3;
|
|
7
|
+
export default class RageClick {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.clicks = [];
|
|
10
|
+
}
|
|
11
|
+
isRageClick(x, y, timestamp) {
|
|
12
|
+
const lastClick = this.clicks[this.clicks.length - 1];
|
|
13
|
+
if (lastClick &&
|
|
14
|
+
Math.abs(x - lastClick.x) + Math.abs(y - lastClick.y) < RAGE_CLICK_THRESHOLD_PX &&
|
|
15
|
+
timestamp - lastClick.timestamp < RAGE_CLICK_TIMEOUT_MS) {
|
|
16
|
+
this.clicks.push({ x, y, timestamp });
|
|
17
|
+
if (this.clicks.length === RAGE_CLICK_CLICK_COUNT) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
this.clicks = [{ x, y, timestamp }];
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=rageclick.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rageclick.js","sourceRoot":"","sources":["../../src/extensions/rageclick.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAC/F,yFAAyF;AACzF,0BAA0B;AAE1B,MAAM,uBAAuB,GAAG,EAAE,CAAA;AAClC,MAAM,qBAAqB,GAAG,IAAI,CAAA;AAClC,MAAM,sBAAsB,GAAG,CAAC,CAAA;AAEhC,MAAM,CAAC,OAAO,OAAO,SAAS;IAG1B;QACI,IAAI,CAAC,MAAM,GAAG,EAAE,CAAA;IACpB,CAAC;IAED,WAAW,CAAC,CAAS,EAAE,CAAS,EAAE,SAAiB;QAC/C,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;QACrD,IACI,SAAS;YACT,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,uBAAuB;YAC/E,SAAS,GAAG,SAAS,CAAC,SAAS,GAAG,qBAAqB,EACzD,CAAC;YACC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,CAAA;YAErC,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,sBAAsB,EAAE,CAAC;gBAChD,OAAO,IAAI,CAAA;YACf,CAAC;QACL,CAAC;aAAM,CAAC;YACJ,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,CAAA;QACvC,CAAC;QAED,OAAO,KAAK,CAAA;IAChB,CAAC;CACJ"}
|
package/lib/iife.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Leanbase } from './leanbase';
|
|
2
|
+
import type { LeanbaseConfig } from './types';
|
|
3
|
+
type QueuedCall = {
|
|
4
|
+
fn: keyof typeof api;
|
|
5
|
+
args: any[];
|
|
6
|
+
};
|
|
7
|
+
declare const api: {
|
|
8
|
+
_instance: Leanbase | null;
|
|
9
|
+
_queue: QueuedCall[];
|
|
10
|
+
init(apiKey: string, options?: LeanbaseConfig): void;
|
|
11
|
+
capture(event: string, properties?: import("@posthog/core").PostHogEventProperties | undefined, options?: import("./types").LeanbasegCaptureOptions | undefined): void;
|
|
12
|
+
captureException(error: unknown, additionalProperties?: import("@posthog/core").PostHogEventProperties | undefined): void;
|
|
13
|
+
identify(distinctId?: string | undefined, properties?: import("@posthog/core").PostHogEventProperties | undefined, options?: import("./types").LeanbasegCaptureOptions | undefined): void;
|
|
14
|
+
group(groupType: string, groupKey: string | number, groupProperties?: import("@posthog/core").PostHogEventProperties | undefined, options?: import("@posthog/core").PostHogCaptureOptions | undefined): void;
|
|
15
|
+
alias(alias: string): void;
|
|
16
|
+
reset(): void;
|
|
17
|
+
getInstance(): Leanbase | null;
|
|
18
|
+
};
|
|
19
|
+
export default api;
|
package/lib/iife.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Leanbase } from './leanbase';
|
|
2
|
+
import { isArray } from '@posthog/core';
|
|
3
|
+
const api = {
|
|
4
|
+
_instance: null,
|
|
5
|
+
_queue: [],
|
|
6
|
+
init(apiKey, options) {
|
|
7
|
+
this._instance = new Leanbase(apiKey, options);
|
|
8
|
+
const q = this._queue;
|
|
9
|
+
this._queue = [];
|
|
10
|
+
for (const { fn, args } of q) {
|
|
11
|
+
// @ts-expect-error dynamic dispatch to API methods
|
|
12
|
+
this[fn](...args);
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
capture(...args) {
|
|
16
|
+
if (this._instance) {
|
|
17
|
+
return this._instance.capture(...args);
|
|
18
|
+
}
|
|
19
|
+
this._queue.push({ fn: 'capture', args });
|
|
20
|
+
},
|
|
21
|
+
captureException(...args) {
|
|
22
|
+
if (this._instance) {
|
|
23
|
+
return this._instance.captureException(...args);
|
|
24
|
+
}
|
|
25
|
+
this._queue.push({ fn: 'captureException', args });
|
|
26
|
+
},
|
|
27
|
+
identify(...args) {
|
|
28
|
+
if (this._instance) {
|
|
29
|
+
return this._instance.identify(...args);
|
|
30
|
+
}
|
|
31
|
+
this._queue.push({ fn: 'identify', args });
|
|
32
|
+
},
|
|
33
|
+
group(...args) {
|
|
34
|
+
if (this._instance) {
|
|
35
|
+
return this._instance.group(...args);
|
|
36
|
+
}
|
|
37
|
+
this._queue.push({ fn: 'group', args });
|
|
38
|
+
},
|
|
39
|
+
alias(...args) {
|
|
40
|
+
if (this._instance) {
|
|
41
|
+
return this._instance.alias(...args);
|
|
42
|
+
}
|
|
43
|
+
this._queue.push({ fn: 'alias', args });
|
|
44
|
+
},
|
|
45
|
+
reset() {
|
|
46
|
+
this._instance?.reset();
|
|
47
|
+
this._instance = null;
|
|
48
|
+
},
|
|
49
|
+
getInstance() {
|
|
50
|
+
return this._instance;
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
(function attachToGlobal(g) {
|
|
54
|
+
// Prefer not to overwrite if a stub already exists (e.g., user queued calls before script loaded)
|
|
55
|
+
const existing = g.leanbase;
|
|
56
|
+
if (existing && typeof existing === 'object') {
|
|
57
|
+
// If there is a pre-existing queue-compatible stub, try to drain it into our API
|
|
58
|
+
if (isArray(existing._queue)) {
|
|
59
|
+
api._queue = existing._queue;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
g.leanbase = api;
|
|
63
|
+
// Also expose PascalCase alias for familiarity
|
|
64
|
+
g.Leanbase = g.leanbase;
|
|
65
|
+
})(globalThis);
|
|
66
|
+
export default api;
|
|
67
|
+
//# sourceMappingURL=iife.js.map
|
package/lib/iife.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iife.js","sourceRoot":"","sources":["../src/iife.ts"],"names":[],"mappings":"AAAA,O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Q,GAAG,CAAC,CAAC,QAAQ,CAAA;AAC3B,CAAC,CAAC,CAAC,UAAwC,CAAC,CAAA;AAE5C,eAAe,GAAG,CAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { Leanbase } from './leanbase'
|
|
2
|
-
export type { LeanbaseConfig as LeanbaseOptions } from './types'
|
|
1
|
+
export { Leanbase } from './leanbase';
|
|
2
|
+
export type { LeanbaseConfig as LeanbaseOptions } from './types';
|
package/lib/index.js
ADDED
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
const PREFIX = '[Leanbase]';
|
|
3
|
+
export const logger = {
|
|
4
|
+
info: (...args) => {
|
|
5
|
+
if (typeof console !== 'undefined') {
|
|
6
|
+
console.log(PREFIX, ...args);
|
|
7
|
+
}
|
|
8
|
+
},
|
|
9
|
+
warn: (...args) => {
|
|
10
|
+
if (typeof console !== 'undefined') {
|
|
11
|
+
console.warn(PREFIX, ...args);
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
error: (...args) => {
|
|
15
|
+
if (typeof console !== 'undefined') {
|
|
16
|
+
console.error(PREFIX, ...args);
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
critical: (...args) => {
|
|
20
|
+
if (typeof console !== 'undefined') {
|
|
21
|
+
console.error(PREFIX, 'CRITICAL:', ...args);
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=leanbase-logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"leanbase-logger.js","sourceRoot":"","sources":["../src/leanbase-logger.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAE/B,MAAM,MAAM,GAAG,YAAY,CAAA;AAE3B,MAAM,CAAC,MAAM,MAAM,GAAG;IAClB,IAAI,EAAE,CAAC,GAAG,IAAW,EAAE,EAAE;QACrB,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE,CAAC;YACjC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAA;QAChC,CAAC;IACL,CAAC;IACD,IAAI,EAAE,CAAC,GAAG,IAAW,EAAE,EAAE;QACrB,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE,CAAC;YACjC,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAA;QACjC,CAAC;IACL,CAAC;IACD,KAAK,EAAE,CAAC,GAAG,IAAW,EAAE,EAAE;QACtB,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE,CAAC;YACjC,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAA;QAClC,CAAC;IACL,CAAC;IACD,QAAQ,EAAE,CAAC,GAAG,IAAW,EAAE,EAAE;QACzB,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE,CAAC;YACjC,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC,CAAA;QAC/C,CAAC;IACL,CAAC;CACJ,CAAA"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { LeanbaseConfig, Properties } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Leanbase Persistence Object
|
|
4
|
+
* @constructor
|
|
5
|
+
*/
|
|
6
|
+
export declare class LeanbasePersistence {
|
|
7
|
+
private _config;
|
|
8
|
+
props: Properties;
|
|
9
|
+
private _storage;
|
|
10
|
+
private _campaign_params_saved;
|
|
11
|
+
private readonly _name;
|
|
12
|
+
_disabled: boolean | undefined;
|
|
13
|
+
private _secure;
|
|
14
|
+
private _expire_days;
|
|
15
|
+
private _default_expiry;
|
|
16
|
+
private _cross_subdomain;
|
|
17
|
+
/**
|
|
18
|
+
* @param {LeanbaseConfig} config initial PostHog configuration
|
|
19
|
+
* @param {boolean=} isDisabled should persistence be disabled (e.g. because of consent management)
|
|
20
|
+
*/
|
|
21
|
+
constructor(config: LeanbaseConfig, isDisabled?: boolean);
|
|
22
|
+
/**
|
|
23
|
+
* Returns whether persistence is disabled. Only available in SDKs > 1.257.1. Do not use on extensions, otherwise
|
|
24
|
+
* it'll break backwards compatibility for any version before 1.257.1.
|
|
25
|
+
*/
|
|
26
|
+
isDisabled?(): boolean;
|
|
27
|
+
private _buildStorage;
|
|
28
|
+
properties(): Properties;
|
|
29
|
+
load(): void;
|
|
30
|
+
/**
|
|
31
|
+
* NOTE: Saving frequently causes issues with Recordings and Consent Management Platform (CMP) tools which
|
|
32
|
+
* observe cookie changes, and modify their UI, often causing infinite loops.
|
|
33
|
+
* As such callers of this should ideally check that the data has changed beforehand
|
|
34
|
+
*/
|
|
35
|
+
save(): void;
|
|
36
|
+
remove(): void;
|
|
37
|
+
clear(): void;
|
|
38
|
+
/**
|
|
39
|
+
* @param {Object} props
|
|
40
|
+
* @param {*=} default_value
|
|
41
|
+
* @param {number=} days
|
|
42
|
+
*/
|
|
43
|
+
register_once(props: Properties, default_value: any, days?: number): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* @param {Object} props
|
|
46
|
+
* @param {number=} days
|
|
47
|
+
*/
|
|
48
|
+
register(props: Properties, days?: number): boolean;
|
|
49
|
+
unregister(prop: string): void;
|
|
50
|
+
update_campaign_params(): void;
|
|
51
|
+
update_search_keyword(): void;
|
|
52
|
+
update_referrer_info(): void;
|
|
53
|
+
set_initial_person_info(): void;
|
|
54
|
+
get_initial_props(): Properties;
|
|
55
|
+
safe_merge(props: Properties): Properties;
|
|
56
|
+
update_config(config: LeanbaseConfig, oldConfig: LeanbaseConfig, isDisabled?: boolean): void;
|
|
57
|
+
set_disabled(disabled: boolean): void;
|
|
58
|
+
set_cross_subdomain(cross_subdomain: boolean): void;
|
|
59
|
+
set_secure(secure: boolean): void;
|
|
60
|
+
set_event_timer(event_name: string, timestamp: number): void;
|
|
61
|
+
remove_event_timer(event_name: string): number;
|
|
62
|
+
get_property(prop: string): any;
|
|
63
|
+
set_property(prop: string, to: any): void;
|
|
64
|
+
}
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
/* eslint camelcase: "off" */
|
|
2
|
+
import { each, extend, include, stripEmptyProperties } from './utils';
|
|
3
|
+
import { cookieStore, localPlusCookieStore, localStore, memoryStore, sessionStore } from './storage';
|
|
4
|
+
import { ENABLED_FEATURE_FLAGS, EVENT_TIMERS_KEY, INITIAL_CAMPAIGN_PARAMS, INITIAL_PERSON_INFO, INITIAL_REFERRER_INFO, PERSISTENCE_RESERVED_PROPERTIES, } from './constants';
|
|
5
|
+
import { isUndefined } from '@posthog/core';
|
|
6
|
+
import { getCampaignParams, getInitialPersonPropsFromInfo, getPersonInfo, getReferrerInfo, getSearchInfo, } from './utils/event-utils';
|
|
7
|
+
import { stripLeadingDollar, isEmptyObject, isObject } from '@posthog/core';
|
|
8
|
+
import { logger } from './leanbase-logger';
|
|
9
|
+
const CASE_INSENSITIVE_PERSISTENCE_TYPES = [
|
|
10
|
+
'cookie',
|
|
11
|
+
'localstorage',
|
|
12
|
+
'localstorage+cookie',
|
|
13
|
+
'sessionstorage',
|
|
14
|
+
'memory',
|
|
15
|
+
];
|
|
16
|
+
const parseName = (config) => {
|
|
17
|
+
let token = '';
|
|
18
|
+
if (config['token']) {
|
|
19
|
+
token = config['token'].replace(/\+/g, 'PL').replace(/\//g, 'SL').replace(/=/g, 'EQ');
|
|
20
|
+
}
|
|
21
|
+
if (config['persistence_name']) {
|
|
22
|
+
return config['persistence_name'];
|
|
23
|
+
}
|
|
24
|
+
return 'leanbase_' + token;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Leanbase Persistence Object
|
|
28
|
+
* @constructor
|
|
29
|
+
*/
|
|
30
|
+
export class LeanbasePersistence {
|
|
31
|
+
/**
|
|
32
|
+
* @param {LeanbaseConfig} config initial PostHog configuration
|
|
33
|
+
* @param {boolean=} isDisabled should persistence be disabled (e.g. because of consent management)
|
|
34
|
+
*/
|
|
35
|
+
constructor(config, isDisabled) {
|
|
36
|
+
this._config = config;
|
|
37
|
+
this.props = {};
|
|
38
|
+
this._campaign_params_saved = false;
|
|
39
|
+
this._name = parseName(config);
|
|
40
|
+
this._storage = this._buildStorage(config);
|
|
41
|
+
this.load();
|
|
42
|
+
if (config.debug) {
|
|
43
|
+
logger.info('Persistence loaded', config['persistence'], { ...this.props });
|
|
44
|
+
}
|
|
45
|
+
this.update_config(config, config, isDisabled);
|
|
46
|
+
this.save();
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Returns whether persistence is disabled. Only available in SDKs > 1.257.1. Do not use on extensions, otherwise
|
|
50
|
+
* it'll break backwards compatibility for any version before 1.257.1.
|
|
51
|
+
*/
|
|
52
|
+
isDisabled() {
|
|
53
|
+
return !!this._disabled;
|
|
54
|
+
}
|
|
55
|
+
_buildStorage(config) {
|
|
56
|
+
if (CASE_INSENSITIVE_PERSISTENCE_TYPES.indexOf(config['persistence'].toLowerCase()) === -1) {
|
|
57
|
+
logger.info('Unknown persistence type ' + config['persistence'] + '; falling back to localStorage+cookie');
|
|
58
|
+
config['persistence'] = 'localStorage+cookie';
|
|
59
|
+
}
|
|
60
|
+
let store;
|
|
61
|
+
const storage_type = config['persistence'].toLowerCase();
|
|
62
|
+
if (storage_type === 'localstorage' && localStore._is_supported()) {
|
|
63
|
+
store = localStore;
|
|
64
|
+
}
|
|
65
|
+
else if (storage_type === 'localstorage+cookie' && localPlusCookieStore._is_supported()) {
|
|
66
|
+
store = localPlusCookieStore;
|
|
67
|
+
}
|
|
68
|
+
else if (storage_type === 'sessionstorage' && sessionStore._is_supported()) {
|
|
69
|
+
store = sessionStore;
|
|
70
|
+
}
|
|
71
|
+
else if (storage_type === 'memory') {
|
|
72
|
+
store = memoryStore;
|
|
73
|
+
}
|
|
74
|
+
else if (storage_type === 'cookie') {
|
|
75
|
+
store = cookieStore;
|
|
76
|
+
}
|
|
77
|
+
else if (localPlusCookieStore._is_supported()) {
|
|
78
|
+
store = localPlusCookieStore;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
store = cookieStore;
|
|
82
|
+
}
|
|
83
|
+
return store;
|
|
84
|
+
}
|
|
85
|
+
properties() {
|
|
86
|
+
const p = {};
|
|
87
|
+
// Filter out reserved properties
|
|
88
|
+
each(this.props, function (v, k) {
|
|
89
|
+
if (k === ENABLED_FEATURE_FLAGS && isObject(v)) {
|
|
90
|
+
const keys = Object.keys(v);
|
|
91
|
+
for (let i = 0; i < keys.length; i++) {
|
|
92
|
+
p[`$feature/${keys[i]}`] = v[keys[i]];
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else if (!include(PERSISTENCE_RESERVED_PROPERTIES, k)) {
|
|
96
|
+
p[k] = v;
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
return p;
|
|
100
|
+
}
|
|
101
|
+
load() {
|
|
102
|
+
if (this._disabled) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const entry = this._storage._parse(this._name);
|
|
106
|
+
if (entry) {
|
|
107
|
+
this.props = extend({}, entry);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* NOTE: Saving frequently causes issues with Recordings and Consent Management Platform (CMP) tools which
|
|
112
|
+
* observe cookie changes, and modify their UI, often causing infinite loops.
|
|
113
|
+
* As such callers of this should ideally check that the data has changed beforehand
|
|
114
|
+
*/
|
|
115
|
+
save() {
|
|
116
|
+
if (this._disabled) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
this._storage._set(this._name, this.props, this._expire_days, this._cross_subdomain, this._secure, this._config.debug);
|
|
120
|
+
}
|
|
121
|
+
remove() {
|
|
122
|
+
this._storage._remove(this._name, false);
|
|
123
|
+
this._storage._remove(this._name, true);
|
|
124
|
+
}
|
|
125
|
+
clear() {
|
|
126
|
+
this.remove();
|
|
127
|
+
this.props = {};
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* @param {Object} props
|
|
131
|
+
* @param {*=} default_value
|
|
132
|
+
* @param {number=} days
|
|
133
|
+
*/
|
|
134
|
+
register_once(props, default_value, days) {
|
|
135
|
+
if (isObject(props)) {
|
|
136
|
+
if (isUndefined(default_value)) {
|
|
137
|
+
default_value = 'None';
|
|
138
|
+
}
|
|
139
|
+
this._expire_days = isUndefined(days) ? this._default_expiry : days;
|
|
140
|
+
let hasChanges = false;
|
|
141
|
+
each(props, (val, prop) => {
|
|
142
|
+
if (!this.props.hasOwnProperty(prop) || this.props[prop] === default_value) {
|
|
143
|
+
this.props[prop] = val;
|
|
144
|
+
hasChanges = true;
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
if (hasChanges) {
|
|
148
|
+
this.save();
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* @param {Object} props
|
|
156
|
+
* @param {number=} days
|
|
157
|
+
*/
|
|
158
|
+
register(props, days) {
|
|
159
|
+
if (isObject(props)) {
|
|
160
|
+
this._expire_days = isUndefined(days) ? this._default_expiry : days;
|
|
161
|
+
let hasChanges = false;
|
|
162
|
+
each(props, (val, prop) => {
|
|
163
|
+
if (props.hasOwnProperty(prop) && this.props[prop] !== val) {
|
|
164
|
+
this.props[prop] = val;
|
|
165
|
+
hasChanges = true;
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
if (hasChanges) {
|
|
169
|
+
this.save();
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
unregister(prop) {
|
|
176
|
+
if (prop in this.props) {
|
|
177
|
+
delete this.props[prop];
|
|
178
|
+
this.save();
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
update_campaign_params() {
|
|
182
|
+
if (!this._campaign_params_saved) {
|
|
183
|
+
const campaignParams = getCampaignParams(this._config.custom_campaign_params, this._config.mask_personal_data_properties, this._config.custom_personal_data_properties);
|
|
184
|
+
if (!isEmptyObject(stripEmptyProperties(campaignParams))) {
|
|
185
|
+
this.register(campaignParams);
|
|
186
|
+
}
|
|
187
|
+
this._campaign_params_saved = true;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
update_search_keyword() {
|
|
191
|
+
this.register(getSearchInfo());
|
|
192
|
+
}
|
|
193
|
+
update_referrer_info() {
|
|
194
|
+
this.register_once(getReferrerInfo(), undefined);
|
|
195
|
+
}
|
|
196
|
+
set_initial_person_info() {
|
|
197
|
+
if (this.props[INITIAL_CAMPAIGN_PARAMS] || this.props[INITIAL_REFERRER_INFO]) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
this.register_once({
|
|
201
|
+
[INITIAL_PERSON_INFO]: getPersonInfo(this._config.mask_personal_data_properties, this._config.custom_personal_data_properties),
|
|
202
|
+
}, undefined);
|
|
203
|
+
}
|
|
204
|
+
get_initial_props() {
|
|
205
|
+
const p = {};
|
|
206
|
+
each([INITIAL_REFERRER_INFO, INITIAL_CAMPAIGN_PARAMS], (key) => {
|
|
207
|
+
const initialReferrerInfo = this.props[key];
|
|
208
|
+
if (initialReferrerInfo) {
|
|
209
|
+
each(initialReferrerInfo, function (v, k) {
|
|
210
|
+
p['$initial_' + stripLeadingDollar(k)] = v;
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
const initialPersonInfo = this.props[INITIAL_PERSON_INFO];
|
|
215
|
+
if (initialPersonInfo) {
|
|
216
|
+
const initialPersonProps = getInitialPersonPropsFromInfo(initialPersonInfo);
|
|
217
|
+
extend(p, initialPersonProps);
|
|
218
|
+
}
|
|
219
|
+
return p;
|
|
220
|
+
}
|
|
221
|
+
safe_merge(props) {
|
|
222
|
+
each(this.props, function (val, prop) {
|
|
223
|
+
if (!(prop in props)) {
|
|
224
|
+
props[prop] = val;
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
return props;
|
|
228
|
+
}
|
|
229
|
+
update_config(config, oldConfig, isDisabled) {
|
|
230
|
+
this._default_expiry = this._expire_days = config['cookie_expiration'];
|
|
231
|
+
this.set_disabled(config['disable_persistence'] || !!isDisabled);
|
|
232
|
+
this.set_cross_subdomain(config['cross_subdomain_cookie']);
|
|
233
|
+
this.set_secure(config['secure_cookie']);
|
|
234
|
+
if (config.persistence !== oldConfig.persistence) {
|
|
235
|
+
const newStore = this._buildStorage(config);
|
|
236
|
+
const props = this.props;
|
|
237
|
+
this.clear();
|
|
238
|
+
this._storage = newStore;
|
|
239
|
+
this.props = props;
|
|
240
|
+
this.save();
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
set_disabled(disabled) {
|
|
244
|
+
this._disabled = disabled;
|
|
245
|
+
if (this._disabled) {
|
|
246
|
+
return this.remove();
|
|
247
|
+
}
|
|
248
|
+
this.save();
|
|
249
|
+
}
|
|
250
|
+
set_cross_subdomain(cross_subdomain) {
|
|
251
|
+
if (cross_subdomain !== this._cross_subdomain) {
|
|
252
|
+
this._cross_subdomain = cross_subdomain;
|
|
253
|
+
this.remove();
|
|
254
|
+
this.save();
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
set_secure(secure) {
|
|
258
|
+
if (secure !== this._secure) {
|
|
259
|
+
this._secure = secure;
|
|
260
|
+
this.remove();
|
|
261
|
+
this.save();
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
set_event_timer(event_name, timestamp) {
|
|
265
|
+
const timers = this.props[EVENT_TIMERS_KEY] || {};
|
|
266
|
+
timers[event_name] = timestamp;
|
|
267
|
+
this.props[EVENT_TIMERS_KEY] = timers;
|
|
268
|
+
this.save();
|
|
269
|
+
}
|
|
270
|
+
remove_event_timer(event_name) {
|
|
271
|
+
const timers = this.props[EVENT_TIMERS_KEY] || {};
|
|
272
|
+
const timestamp = timers[event_name];
|
|
273
|
+
if (!isUndefined(timestamp)) {
|
|
274
|
+
delete this.props[EVENT_TIMERS_KEY][event_name];
|
|
275
|
+
this.save();
|
|
276
|
+
}
|
|
277
|
+
return timestamp;
|
|
278
|
+
}
|
|
279
|
+
get_property(prop) {
|
|
280
|
+
return this.props[prop];
|
|
281
|
+
}
|
|
282
|
+
set_property(prop, to) {
|
|
283
|
+
this.props[prop] = to;
|
|
284
|
+
this.save();
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
//# sourceMappingURL=leanbase-persistence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"leanbase-persistence.js","sourceRoot":"","sources":["../src/leanbase-persistence.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAE7B,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AACrE,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAEpG,OAAO,EACH,qBAAqB,EACrB,gBAAgB,EAChB,uBAAuB,EACvB,mBAAmB,EACnB,qBAAqB,EACrB,+BAA+B,GAClC,MAAM,aAAa,CAAA;AAEpB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EACH,iBAAiB,EACjB,6BAA6B,EAC7B,aAAa,EACb,eAAe,EACf,aAAa,GAChB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC3E,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE1C,MAAM,kCAAkC,GAAwD;IAC5F,QAAQ;IACR,cAAc;IACd,qBAAqB;IACrB,gBAAgB;IAChB,QAAQ;CACX,CAAA;AAED,MAAM,SAAS,GAAG,CAAC,MA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|
|
1
|
+
import { PostHogCore } from '@posthog/core';
|
|
2
|
+
import type { PostHogEventProperties, PostHogFetchOptions, PostHogFetchResponse, PostHogPersistedProperty } from '@posthog/core';
|
|
3
|
+
import { LeanbaseConfig, LeanbasegCaptureOptions as LeanbaseCaptureOptions, RemoteConfig, Properties } from './types';
|
|
4
|
+
import { LeanbasePersistence } from './leanbase-persistence';
|
|
5
|
+
import { Autocapture } from './autocapture';
|
|
6
|
+
import { SessionIdManager } from './sessionid';
|
|
7
|
+
import { SessionPropsManager } from './session-props';
|
|
8
|
+
import { PageViewManager } from './page-view';
|
|
9
|
+
import { ScrollManager } from './scroll-manager';
|
|
10
|
+
export declare class Leanbase extends PostHogCore {
|
|
11
|
+
config: LeanbaseConfig;
|
|
12
|
+
scrollManager: ScrollManager;
|
|
13
|
+
pageViewManager: PageViewManager;
|
|
14
|
+
replayAutocapture?: Autocapture;
|
|
15
|
+
persistence?: LeanbasePersistence;
|
|
16
|
+
sessionPersistence?: LeanbasePersistence;
|
|
17
|
+
sessionManager?: SessionIdManager;
|
|
18
|
+
sessionPropsManager?: SessionPropsManager;
|
|
19
|
+
isRemoteConfigLoaded?: boolean;
|
|
20
|
+
personProcessingSetOncePropertiesSent: boolean;
|
|
21
|
+
isLoaded: boolean;
|
|
22
|
+
initialPageviewCaptured: boolean;
|
|
23
|
+
visibilityStateListener: (() => void) | null;
|
|
24
|
+
constructor(token: string, config?: Partial<LeanbaseConfig>);
|
|
25
|
+
init(token: string, config: Partial<LeanbaseConfig>): void;
|
|
26
|
+
captureInitialPageview(): void;
|
|
27
|
+
capturePageLeave(): void;
|
|
28
|
+
loadRemoteConfig(): Promise<void>;
|
|
29
|
+
onRemoteConfig(config: RemoteConfig): void;
|
|
30
|
+
fetch(url: string, options: PostHogFetchOptions): Promise<PostHogFetchResponse>;
|
|
31
|
+
setConfig(config: Partial<LeanbaseConfig>): void;
|
|
32
|
+
getLibraryId(): string;
|
|
33
|
+
getLibraryVersion(): string;
|
|
34
|
+
getCustomUserAgent(): void;
|
|
35
|
+
getPersistedProperty<T>(key: PostHogPersistedProperty): T | undefined;
|
|
36
|
+
setPersistedProperty<T>(key: PostHogPersistedProperty, value: T | null): void;
|
|
37
|
+
calculateEventProperties(eventName: string, eventProperties: PostHogEventProperties, timestamp: Date, uuid: string, readOnly?: boolean): Properties;
|
|
38
|
+
isIdentified(): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Add additional set_once properties to the event when creating a person profile. This allows us to create the
|
|
41
|
+
* profile with mostly-accurate properties, despite earlier events not setting them. We do this by storing them in
|
|
42
|
+
* persistence.
|
|
43
|
+
* @param dataSetOnce
|
|
44
|
+
*/
|
|
45
|
+
calculateSetOnceProperties(dataSetOnce?: Properties): Properties | undefined;
|
|
46
|
+
capture(event: string, properties?: PostHogEventProperties, options?: LeanbaseCaptureOptions): void;
|
|
47
|
+
identify(distinctId?: string, properties?: PostHogEventProperties, options?: LeanbaseCaptureOptions): void;
|
|
48
|
+
destroy(): void;
|
|
49
|
+
}
|