@v-tilt/browser 1.0.8 → 1.0.10
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/array.js +1 -1
- package/dist/array.js.map +1 -1
- package/dist/array.no-external.js +1 -1
- package/dist/array.no-external.js.map +1 -1
- package/dist/constants.d.ts +0 -1
- package/dist/extensions/history-autocapture.d.ts +0 -2
- package/dist/main.js +1 -1
- package/dist/main.js.map +1 -1
- package/dist/module.d.ts +53 -133
- package/dist/module.js +1 -1
- package/dist/module.js.map +1 -1
- package/dist/module.no-external.d.ts +53 -133
- package/dist/module.no-external.js +1 -1
- package/dist/module.no-external.js.map +1 -1
- package/dist/session.d.ts +5 -5
- package/dist/types.d.ts +2 -1
- package/dist/user-manager.d.ts +30 -20
- package/dist/utils/event-utils.d.ts +7 -8
- package/dist/utils/index.d.ts +0 -5
- package/dist/utils/patch.d.ts +0 -1
- package/dist/vtilt.d.ts +54 -14
- package/dist/web-vitals.d.ts +3 -3
- package/lib/constants.d.ts +0 -1
- package/lib/constants.js +1 -23
- package/lib/extensions/history-autocapture.d.ts +0 -2
- package/lib/extensions/history-autocapture.js +3 -5
- package/lib/session.d.ts +5 -5
- package/lib/session.js +8 -8
- package/lib/types.d.ts +2 -1
- package/lib/user-manager.d.ts +30 -20
- package/lib/user-manager.js +103 -94
- package/lib/utils/event-utils.d.ts +7 -8
- package/lib/utils/event-utils.js +8 -9
- package/lib/utils/index.d.ts +0 -5
- package/lib/utils/index.js +0 -13
- package/lib/utils/patch.d.ts +0 -1
- package/lib/utils/patch.js +0 -1
- package/lib/vtilt.d.ts +54 -14
- package/lib/vtilt.js +323 -41
- package/lib/web-vitals.d.ts +3 -3
- package/lib/web-vitals.js +3 -3
- package/package.json +1 -1
- package/dist/tracking.d.ts +0 -120
- package/dist/utils/is-function.d.ts +0 -4
- package/lib/tracking.d.ts +0 -120
- package/lib/tracking.js +0 -338
- package/lib/utils/is-function.d.ts +0 -4
- package/lib/utils/is-function.js +0 -9
|
@@ -1,35 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Get browser language
|
|
2
|
+
* Get browser language
|
|
3
3
|
* Returns the browser's language setting (e.g., "en-US")
|
|
4
4
|
*/
|
|
5
5
|
export declare function getBrowserLanguage(): string | undefined;
|
|
6
6
|
/**
|
|
7
|
-
* Get browser language prefix
|
|
7
|
+
* Get browser language prefix
|
|
8
8
|
* Returns the language code without region (e.g., "en" from "en-US")
|
|
9
9
|
*/
|
|
10
10
|
export declare function getBrowserLanguagePrefix(): string | undefined;
|
|
11
11
|
/**
|
|
12
|
-
* Get referrer
|
|
12
|
+
* Get referrer
|
|
13
13
|
* Returns document.referrer or '$direct' if no referrer
|
|
14
14
|
*/
|
|
15
15
|
export declare function getReferrer(): string;
|
|
16
16
|
/**
|
|
17
|
-
* Get referring domain
|
|
17
|
+
* Get referring domain
|
|
18
18
|
* Returns the hostname of the referrer URL or '$direct' if no referrer
|
|
19
19
|
*/
|
|
20
20
|
export declare function getReferringDomain(): string;
|
|
21
21
|
/**
|
|
22
|
-
* Get timezone
|
|
22
|
+
* Get timezone
|
|
23
23
|
* Returns the timezone (e.g., "America/New_York")
|
|
24
24
|
*/
|
|
25
25
|
export declare function getTimezone(): string | undefined;
|
|
26
26
|
/**
|
|
27
|
-
* Get timezone offset
|
|
27
|
+
* Get timezone offset
|
|
28
28
|
* Returns the timezone offset in minutes
|
|
29
29
|
*/
|
|
30
30
|
export declare function getTimezoneOffset(): number | undefined;
|
|
31
31
|
/**
|
|
32
|
-
* Get event properties that should be added to all events
|
|
33
|
-
* Matches PostHog's getEventProperties() implementation
|
|
32
|
+
* Get event properties that should be added to all events
|
|
34
33
|
*/
|
|
35
34
|
export declare function getEventProperties(): Record<string, any>;
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { EventPayload } from "../types";
|
|
2
1
|
/**
|
|
3
2
|
* Generate uuid to identify the session. Random, not data-derived
|
|
4
3
|
*/
|
|
@@ -11,10 +10,6 @@ export declare function isValidUserAgent(userAgent: string): boolean;
|
|
|
11
10
|
* Validate payload string
|
|
12
11
|
*/
|
|
13
12
|
export declare function isValidPayload(payloadStr: string): boolean;
|
|
14
|
-
/**
|
|
15
|
-
* Try to mask PPI and potential sensible attributes
|
|
16
|
-
*/
|
|
17
|
-
export declare function maskSuspiciousAttributes(payload: EventPayload): string;
|
|
18
13
|
/**
|
|
19
14
|
* Check if current environment is a test environment
|
|
20
15
|
*/
|
package/dist/utils/patch.d.ts
CHANGED
package/dist/vtilt.d.ts
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import { VTiltConfig, EventPayload } from "./types";
|
|
2
|
-
import { TrackingManager } from "./tracking";
|
|
3
2
|
import { HistoryAutocapture } from "./extensions/history-autocapture";
|
|
3
|
+
interface QueuedRequest {
|
|
4
|
+
url: string;
|
|
5
|
+
event: any;
|
|
6
|
+
}
|
|
4
7
|
export declare class VTilt {
|
|
5
8
|
private configManager;
|
|
6
|
-
|
|
9
|
+
private sessionManager;
|
|
10
|
+
private userManager;
|
|
7
11
|
private webVitalsManager;
|
|
8
12
|
historyAutocapture?: HistoryAutocapture;
|
|
9
13
|
__loaded: boolean;
|
|
10
14
|
private _initialPageviewCaptured;
|
|
11
15
|
private _visibilityStateListener;
|
|
16
|
+
__request_queue: QueuedRequest[];
|
|
17
|
+
private _hasWarnedAboutConfig;
|
|
12
18
|
constructor(config?: Partial<VTiltConfig>);
|
|
13
19
|
/**
|
|
14
20
|
* Initializes a new instance of the VTilt tracking object.
|
|
@@ -44,23 +50,57 @@ export declare class VTilt {
|
|
|
44
50
|
/**
|
|
45
51
|
* Handles the actual initialization logic for a VTilt instance.
|
|
46
52
|
* This internal method should only be called by `init()`.
|
|
47
|
-
* Follows the PostHog convention of using a private `_init()` method for instance setup.
|
|
48
53
|
*/
|
|
49
54
|
private _init;
|
|
50
55
|
/**
|
|
51
|
-
* Returns a string representation of the instance name
|
|
56
|
+
* Returns a string representation of the instance name
|
|
52
57
|
* Used for debugging and logging
|
|
53
58
|
*
|
|
54
59
|
* @internal
|
|
55
60
|
*/
|
|
56
61
|
toString(): string;
|
|
57
62
|
/**
|
|
58
|
-
*
|
|
63
|
+
* Get current domain from location
|
|
64
|
+
* Returns full URL format for consistency with dashboard
|
|
65
|
+
*/
|
|
66
|
+
private getCurrentDomain;
|
|
67
|
+
/**
|
|
68
|
+
* Check if tracking is properly configured
|
|
69
|
+
* Returns true if projectId and token are present, false otherwise
|
|
70
|
+
* Logs a warning only once per instance if not configured
|
|
71
|
+
*/
|
|
72
|
+
private _isConfigured;
|
|
73
|
+
/**
|
|
74
|
+
* Build the tracking URL with token in query parameters
|
|
75
|
+
*/
|
|
76
|
+
private buildUrl;
|
|
77
|
+
/**
|
|
78
|
+
* Send HTTP request
|
|
79
|
+
* This is the central entry point for all tracking requests
|
|
80
|
+
*/
|
|
81
|
+
private sendRequest;
|
|
82
|
+
/**
|
|
83
|
+
* Send a queued request (called after DOM is loaded)
|
|
84
|
+
*/
|
|
85
|
+
_send_retriable_request(item: QueuedRequest): void;
|
|
86
|
+
/**
|
|
87
|
+
* Capture an event
|
|
88
|
+
* Automatically adds common properties to all events
|
|
89
|
+
* ($current_url, $host, $pathname, $referrer, $referring_domain, $browser_language, etc.)
|
|
90
|
+
* Also adds title property for $pageview events only
|
|
91
|
+
*
|
|
92
|
+
* @param name - Event name
|
|
93
|
+
* @param payload - Event payload
|
|
94
|
+
*/
|
|
95
|
+
capture(name: string, payload: EventPayload): void;
|
|
96
|
+
/**
|
|
97
|
+
* Track a custom event (alias for capture)
|
|
59
98
|
*/
|
|
60
99
|
trackEvent(name: string, payload?: EventPayload): void;
|
|
61
100
|
/**
|
|
62
|
-
* Identify a user with
|
|
63
|
-
*
|
|
101
|
+
* Identify a user with property operations
|
|
102
|
+
* Sends $identify event when transitioning from anonymous to identified
|
|
103
|
+
* Event's distinct_id is the previous/anonymous ID, new distinct_id is in payload
|
|
64
104
|
*
|
|
65
105
|
* @example
|
|
66
106
|
* ```js
|
|
@@ -77,9 +117,9 @@ export declare class VTilt {
|
|
|
77
117
|
* vTilt.identify('user_123', { name: 'John Doe', email: 'john@example.com' })
|
|
78
118
|
* ```
|
|
79
119
|
*/
|
|
80
|
-
identify(
|
|
120
|
+
identify(newDistinctId?: string, userPropertiesToSet?: Record<string, any>, userPropertiesToSetOnce?: Record<string, any>): void;
|
|
81
121
|
/**
|
|
82
|
-
* Set user properties
|
|
122
|
+
* Set user properties
|
|
83
123
|
* Sets properties on the person profile associated with the current distinct_id
|
|
84
124
|
*
|
|
85
125
|
* @example
|
|
@@ -103,7 +143,7 @@ export declare class VTilt {
|
|
|
103
143
|
setUserProperties(userPropertiesToSet?: Record<string, any>, userPropertiesToSetOnce?: Record<string, any>): void;
|
|
104
144
|
/**
|
|
105
145
|
* Reset user identity (logout)
|
|
106
|
-
*
|
|
146
|
+
* Clears all user data, generates new anonymous ID, resets session
|
|
107
147
|
*
|
|
108
148
|
* @param reset_device_id - If true, also resets device_id. Default: false
|
|
109
149
|
*
|
|
@@ -130,7 +170,7 @@ export declare class VTilt {
|
|
|
130
170
|
getUserState(): "anonymous" | "identified";
|
|
131
171
|
/**
|
|
132
172
|
* Create an alias to link two distinct IDs
|
|
133
|
-
*
|
|
173
|
+
* Links anonymous session to account on signup
|
|
134
174
|
*
|
|
135
175
|
* @param alias - A unique identifier that you want to use for this user in the future
|
|
136
176
|
* @param original - The current identifier being used for this user (optional, defaults to current distinct_id)
|
|
@@ -146,7 +186,6 @@ export declare class VTilt {
|
|
|
146
186
|
createAlias(alias: string, original?: string): void;
|
|
147
187
|
/**
|
|
148
188
|
* Capture initial pageview with visibility check
|
|
149
|
-
* Based on PostHog's _captureInitialPageview implementation
|
|
150
189
|
*/
|
|
151
190
|
private _captureInitialPageview;
|
|
152
191
|
/**
|
|
@@ -179,12 +218,12 @@ export declare class VTilt {
|
|
|
179
218
|
_dom_loaded(): void;
|
|
180
219
|
}
|
|
181
220
|
/**
|
|
182
|
-
* Initialize vTilt as a module
|
|
221
|
+
* Initialize vTilt as a module
|
|
183
222
|
* Returns an uninitialized vTilt instance that the user must call init() on
|
|
184
223
|
*/
|
|
185
224
|
export declare function init_as_module(): VTilt;
|
|
186
225
|
/**
|
|
187
|
-
* Initialize vTilt from snippet
|
|
226
|
+
* Initialize vTilt from snippet
|
|
188
227
|
* Processes queued calls from the snippet stub and replaces it with real instance
|
|
189
228
|
*
|
|
190
229
|
* The snippet uses some clever tricks to allow deferred loading of array.js (this code)
|
|
@@ -214,3 +253,4 @@ export declare function init_as_module(): VTilt;
|
|
|
214
253
|
* ]
|
|
215
254
|
*/
|
|
216
255
|
export declare function init_from_snippet(): void;
|
|
256
|
+
export {};
|
package/dist/web-vitals.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { VTiltConfig } from "./types";
|
|
2
|
-
import {
|
|
2
|
+
import { VTilt } from "./vtilt";
|
|
3
3
|
export declare class WebVitalsManager {
|
|
4
|
-
private
|
|
4
|
+
private instance;
|
|
5
5
|
private webVitals;
|
|
6
|
-
constructor(config: VTiltConfig,
|
|
6
|
+
constructor(config: VTiltConfig, instance: VTilt);
|
|
7
7
|
/**
|
|
8
8
|
* Initialize web vitals tracking
|
|
9
9
|
*/
|
package/lib/constants.d.ts
CHANGED
|
@@ -9,4 +9,3 @@ export declare const USER_PROPERTIES_KEY = "vt_user_properties";
|
|
|
9
9
|
export declare const USER_STATE_KEY = "vt_user_state";
|
|
10
10
|
export declare const STORAGE_METHODS: StorageMethods;
|
|
11
11
|
export declare const TIMEZONES: Record<string, string>;
|
|
12
|
-
export declare const ATTRIBUTES_TO_MASK: string[];
|
package/lib/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.TIMEZONES = exports.STORAGE_METHODS = exports.USER_STATE_KEY = exports.USER_PROPERTIES_KEY = exports.DEVICE_ID_KEY = exports.DISTINCT_ID_KEY = exports.ANONYMOUS_ID_KEY = exports.PRIMARY_WINDOW_EXISTS_KEY = exports.WINDOW_ID_KEY = exports.STORAGE_KEY = void 0;
|
|
4
4
|
exports.STORAGE_KEY = "vt_session_id";
|
|
5
5
|
exports.WINDOW_ID_KEY = "vt_window_id";
|
|
6
6
|
exports.PRIMARY_WINDOW_EXISTS_KEY = "vt_primary_window_exists";
|
|
@@ -441,25 +441,3 @@ exports.TIMEZONES = {
|
|
|
441
441
|
"Asia/Urumqi": "CN",
|
|
442
442
|
"Asia/Calcutta": "IN",
|
|
443
443
|
};
|
|
444
|
-
exports.ATTRIBUTES_TO_MASK = [
|
|
445
|
-
"username",
|
|
446
|
-
"user",
|
|
447
|
-
"user_id",
|
|
448
|
-
"userid",
|
|
449
|
-
"password",
|
|
450
|
-
"pass",
|
|
451
|
-
"pin",
|
|
452
|
-
"passcode",
|
|
453
|
-
"token",
|
|
454
|
-
"api_token",
|
|
455
|
-
"email",
|
|
456
|
-
"address",
|
|
457
|
-
"phone",
|
|
458
|
-
"sex",
|
|
459
|
-
"gender",
|
|
460
|
-
"order",
|
|
461
|
-
"order_id",
|
|
462
|
-
"orderid",
|
|
463
|
-
"payment",
|
|
464
|
-
"credit_card",
|
|
465
|
-
];
|
|
@@ -2,8 +2,6 @@ import { VTilt } from "../vtilt";
|
|
|
2
2
|
/**
|
|
3
3
|
* This class is used to capture pageview events when the user navigates using the history API (pushState, replaceState)
|
|
4
4
|
* and when the user navigates using the browser's back/forward buttons.
|
|
5
|
-
*
|
|
6
|
-
* Based on PostHog's HistoryAutocapture implementation
|
|
7
5
|
*/
|
|
8
6
|
export declare class HistoryAutocapture {
|
|
9
7
|
private _instance;
|
|
@@ -7,8 +7,6 @@ const patch_1 = require("../utils/patch");
|
|
|
7
7
|
/**
|
|
8
8
|
* This class is used to capture pageview events when the user navigates using the history API (pushState, replaceState)
|
|
9
9
|
* and when the user navigates using the browser's back/forward buttons.
|
|
10
|
-
*
|
|
11
|
-
* Based on PostHog's HistoryAutocapture implementation
|
|
12
10
|
*/
|
|
13
11
|
class HistoryAutocapture {
|
|
14
12
|
constructor(instance) {
|
|
@@ -40,7 +38,7 @@ class HistoryAutocapture {
|
|
|
40
38
|
}
|
|
41
39
|
// Initialize last pathname
|
|
42
40
|
this._lastPathname = globals_1.location.pathname || "";
|
|
43
|
-
// Track history API changes using patch
|
|
41
|
+
// Track history API changes using patch
|
|
44
42
|
if (globals_1.window.history) {
|
|
45
43
|
// Old fashioned, we could also use arrow functions but I think the closure for a patch is more reliable
|
|
46
44
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
@@ -77,11 +75,11 @@ class HistoryAutocapture {
|
|
|
77
75
|
// Only capture pageview if the pathname has changed and the feature is enabled
|
|
78
76
|
if (currentPathname !== this._lastPathname && this.isEnabled) {
|
|
79
77
|
// Note: $current_url, $host, $pathname, $referrer, $referring_domain, title
|
|
80
|
-
// are automatically added by
|
|
78
|
+
// are automatically added by capture() for all events (title only for $pageview)
|
|
81
79
|
const payload = {
|
|
82
80
|
navigation_type: navigationType,
|
|
83
81
|
};
|
|
84
|
-
this._instance.
|
|
82
|
+
this._instance.capture("$pageview", payload);
|
|
85
83
|
}
|
|
86
84
|
this._lastPathname = currentPathname;
|
|
87
85
|
}
|
package/lib/session.d.ts
CHANGED
|
@@ -38,7 +38,7 @@ export declare class SessionManager {
|
|
|
38
38
|
*/
|
|
39
39
|
private _getSessionIdRaw;
|
|
40
40
|
/**
|
|
41
|
-
* Get session ID (
|
|
41
|
+
* Get session ID (always returns a value, generates if needed)
|
|
42
42
|
*/
|
|
43
43
|
getSessionId(): string;
|
|
44
44
|
/**
|
|
@@ -51,17 +51,17 @@ export declare class SessionManager {
|
|
|
51
51
|
*/
|
|
52
52
|
private _clearSessionId;
|
|
53
53
|
/**
|
|
54
|
-
* Reset session ID (
|
|
54
|
+
* Reset session ID (generates new session on reset)
|
|
55
55
|
*/
|
|
56
56
|
resetSessionId(): void;
|
|
57
57
|
/**
|
|
58
|
-
* Get window ID
|
|
58
|
+
* Get window ID
|
|
59
59
|
* Window ID is unique per browser tab/window and persists across page reloads
|
|
60
60
|
* Always returns a window_id (generates one if not set)
|
|
61
61
|
*/
|
|
62
62
|
getWindowId(): string;
|
|
63
63
|
/**
|
|
64
|
-
* Set window ID
|
|
64
|
+
* Set window ID
|
|
65
65
|
* Stores in sessionStorage which is unique per tab
|
|
66
66
|
*/
|
|
67
67
|
private _setWindowId;
|
|
@@ -71,7 +71,7 @@ export declare class SessionManager {
|
|
|
71
71
|
*/
|
|
72
72
|
private _canUseSessionStorage;
|
|
73
73
|
/**
|
|
74
|
-
* Initialize window ID
|
|
74
|
+
* Initialize window ID
|
|
75
75
|
* Detects tab duplication and handles window_id persistence
|
|
76
76
|
*/
|
|
77
77
|
private _initializeWindowId;
|
package/lib/session.js
CHANGED
|
@@ -9,7 +9,7 @@ class SessionManager {
|
|
|
9
9
|
this.storageMethod = storageMethod;
|
|
10
10
|
this.domain = domain;
|
|
11
11
|
this._windowId = undefined;
|
|
12
|
-
// Initialize window_id
|
|
12
|
+
// Initialize window_id
|
|
13
13
|
this._initializeWindowId();
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
@@ -114,11 +114,11 @@ class SessionManager {
|
|
|
114
114
|
return this.getSessionIdFromCookie();
|
|
115
115
|
}
|
|
116
116
|
/**
|
|
117
|
-
* Get session ID (
|
|
117
|
+
* Get session ID (always returns a value, generates if needed)
|
|
118
118
|
*/
|
|
119
119
|
getSessionId() {
|
|
120
120
|
let sessionId = this._getSessionIdRaw();
|
|
121
|
-
// Generate and store session_id if not found (
|
|
121
|
+
// Generate and store session_id if not found (always ensure session_id exists)
|
|
122
122
|
if (!sessionId) {
|
|
123
123
|
sessionId = (0, utils_1.uuidv4)();
|
|
124
124
|
this._storeSessionId(sessionId);
|
|
@@ -157,7 +157,7 @@ class SessionManager {
|
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
/**
|
|
160
|
-
* Reset session ID (
|
|
160
|
+
* Reset session ID (generates new session on reset)
|
|
161
161
|
*/
|
|
162
162
|
resetSessionId() {
|
|
163
163
|
this._clearSessionId();
|
|
@@ -166,7 +166,7 @@ class SessionManager {
|
|
|
166
166
|
this._setWindowId((0, utils_1.uuidv4)());
|
|
167
167
|
}
|
|
168
168
|
/**
|
|
169
|
-
* Get window ID
|
|
169
|
+
* Get window ID
|
|
170
170
|
* Window ID is unique per browser tab/window and persists across page reloads
|
|
171
171
|
* Always returns a window_id (generates one if not set)
|
|
172
172
|
*/
|
|
@@ -182,13 +182,13 @@ class SessionManager {
|
|
|
182
182
|
return windowId;
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
|
-
// Generate and store window_id if not found (
|
|
185
|
+
// Generate and store window_id if not found (always ensure window_id exists)
|
|
186
186
|
const newWindowId = (0, utils_1.uuidv4)();
|
|
187
187
|
this._setWindowId(newWindowId);
|
|
188
188
|
return newWindowId;
|
|
189
189
|
}
|
|
190
190
|
/**
|
|
191
|
-
* Set window ID
|
|
191
|
+
* Set window ID
|
|
192
192
|
* Stores in sessionStorage which is unique per tab
|
|
193
193
|
*/
|
|
194
194
|
_setWindowId(windowId) {
|
|
@@ -218,7 +218,7 @@ class SessionManager {
|
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
220
|
/**
|
|
221
|
-
* Initialize window ID
|
|
221
|
+
* Initialize window ID
|
|
222
222
|
* Detects tab duplication and handles window_id persistence
|
|
223
223
|
*/
|
|
224
224
|
_initializeWindowId() {
|
package/lib/types.d.ts
CHANGED
|
@@ -36,10 +36,11 @@ export interface EventPayload {
|
|
|
36
36
|
export interface TrackingEvent {
|
|
37
37
|
timestamp: string;
|
|
38
38
|
event: string;
|
|
39
|
-
|
|
39
|
+
project_id: string;
|
|
40
40
|
domain: string;
|
|
41
41
|
payload: EventPayload;
|
|
42
42
|
distinct_id?: string;
|
|
43
|
+
anonymous_id?: string;
|
|
43
44
|
}
|
|
44
45
|
export type StorageMethod = "cookie" | "localStorage" | "sessionStorage";
|
|
45
46
|
export interface StorageMethods {
|
package/lib/user-manager.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UserIdentity, StorageMethod } from "./types";
|
|
1
|
+
import { UserIdentity, AliasEvent, StorageMethod } from "./types";
|
|
2
2
|
export declare class UserManager {
|
|
3
3
|
private storageMethod;
|
|
4
4
|
private domain?;
|
|
@@ -23,11 +23,10 @@ export declare class UserManager {
|
|
|
23
23
|
getUserProperties(): Record<string, any>;
|
|
24
24
|
/**
|
|
25
25
|
* Identify a user with distinct ID and properties
|
|
26
|
-
* Copied from PostHog's identify method implementation
|
|
27
26
|
*/
|
|
28
27
|
identify(newDistinctId?: string, userPropertiesToSet?: Record<string, any>, userPropertiesToSetOnce?: Record<string, any>): void;
|
|
29
28
|
/**
|
|
30
|
-
* Set user properties without changing distinct ID
|
|
29
|
+
* Set user properties without changing distinct ID
|
|
31
30
|
* Sets properties on the person profile associated with the current distinct_id
|
|
32
31
|
*
|
|
33
32
|
* @example
|
|
@@ -48,20 +47,15 @@ export declare class UserManager {
|
|
|
48
47
|
* @param userPropertiesToSet Optional: Properties to set (can be updated)
|
|
49
48
|
* @param userPropertiesToSetOnce Optional: Properties to set once (preserves first value)
|
|
50
49
|
*/
|
|
51
|
-
setUserProperties(userPropertiesToSet?: Record<string, any>, userPropertiesToSetOnce?: Record<string, any>):
|
|
50
|
+
setUserProperties(userPropertiesToSet?: Record<string, any>, userPropertiesToSetOnce?: Record<string, any>): boolean;
|
|
52
51
|
/**
|
|
53
|
-
* Get hash for person properties
|
|
52
|
+
* Get hash for person properties
|
|
54
53
|
* Used for deduplication of identical setUserProperties calls
|
|
55
54
|
*/
|
|
56
55
|
private getPersonPropertiesHash;
|
|
57
|
-
/**
|
|
58
|
-
* Send $set event for property updates (PostHog behavior)
|
|
59
|
-
* This notifies the server when user properties are updated
|
|
60
|
-
*/
|
|
61
|
-
private sendSetEvent;
|
|
62
56
|
/**
|
|
63
57
|
* Reset user identity (logout)
|
|
64
|
-
*
|
|
58
|
+
* Generates new anonymous ID, clears user data, optionally resets device ID
|
|
65
59
|
*
|
|
66
60
|
* @param reset_device_id - If true, also resets device_id. Default: false (preserves device_id)
|
|
67
61
|
*/
|
|
@@ -78,23 +72,43 @@ export declare class UserManager {
|
|
|
78
72
|
* Get current user state
|
|
79
73
|
*/
|
|
80
74
|
getUserState(): "anonymous" | "identified";
|
|
75
|
+
/**
|
|
76
|
+
* Update distinct ID (internal use - for VTilt)
|
|
77
|
+
*/
|
|
78
|
+
setDistinctId(distinctId: string): void;
|
|
79
|
+
/**
|
|
80
|
+
* Update user state (internal use - for VTilt)
|
|
81
|
+
*/
|
|
82
|
+
setUserState(state: "anonymous" | "identified"): void;
|
|
83
|
+
/**
|
|
84
|
+
* Update user properties (internal use - for VTilt)
|
|
85
|
+
*/
|
|
86
|
+
updateUserProperties(userPropertiesToSet?: Record<string, any>, userPropertiesToSetOnce?: Record<string, any>): void;
|
|
87
|
+
/**
|
|
88
|
+
* Set device ID if not already set (internal use - for VTilt)
|
|
89
|
+
*/
|
|
90
|
+
ensureDeviceId(deviceId: string): void;
|
|
91
|
+
/**
|
|
92
|
+
* Check if distinct ID is string-like (hardcoded string) - public for validation
|
|
93
|
+
* This is a wrapper to expose the private method
|
|
94
|
+
*/
|
|
95
|
+
isDistinctIdStringLikePublic(distinctId: string): boolean;
|
|
81
96
|
/**
|
|
82
97
|
* Create an alias to link two distinct IDs
|
|
83
|
-
*
|
|
84
|
-
* If alias matches original,
|
|
98
|
+
* If original is not provided, uses current distinct_id
|
|
99
|
+
* If alias matches original, returns null (caller should use identify instead)
|
|
85
100
|
*
|
|
86
101
|
* @param alias - A unique identifier that you want to use for this user in the future
|
|
87
102
|
* @param original - The current identifier being used for this user (optional, defaults to current distinct_id)
|
|
103
|
+
* @returns AliasEvent if alias was created, null if alias matches original or invalid
|
|
88
104
|
*/
|
|
89
|
-
createAlias(alias: string, original?: string):
|
|
105
|
+
createAlias(alias: string, original?: string): AliasEvent | null;
|
|
90
106
|
/**
|
|
91
107
|
* Validate distinct ID to prevent hardcoded strings
|
|
92
|
-
* Copied from PostHog's validation logic
|
|
93
108
|
*/
|
|
94
109
|
private isValidDistinctId;
|
|
95
110
|
/**
|
|
96
111
|
* Check if distinct ID is string-like (hardcoded string)
|
|
97
|
-
* Copied from PostHog's isDistinctIdStringLike function
|
|
98
112
|
*/
|
|
99
113
|
private isDistinctIdStringLike;
|
|
100
114
|
/**
|
|
@@ -113,10 +127,6 @@ export declare class UserManager {
|
|
|
113
127
|
* Generate a new device ID
|
|
114
128
|
*/
|
|
115
129
|
private generateDeviceId;
|
|
116
|
-
/**
|
|
117
|
-
* Send identify event for session merging
|
|
118
|
-
*/
|
|
119
|
-
private sendIdentifyEvent;
|
|
120
130
|
/**
|
|
121
131
|
* Get stored value from storage
|
|
122
132
|
*/
|