@v-tilt/browser 1.1.1 → 1.1.3
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 +2 -2
- package/dist/main.js +1 -1
- package/dist/main.js.map +1 -1
- package/dist/module.d.ts +8 -8
- package/dist/module.js +1 -1
- package/dist/module.js.map +1 -1
- package/dist/module.no-external.d.ts +8 -8
- package/dist/module.no-external.js +1 -1
- package/dist/module.no-external.js.map +1 -1
- package/dist/session.d.ts +22 -41
- package/dist/storage.d.ts +95 -0
- package/dist/types.d.ts +8 -8
- package/dist/user-manager.d.ts +49 -92
- package/lib/config.js +4 -1
- package/lib/constants.d.ts +2 -2
- package/lib/constants.js +510 -510
- package/lib/session.d.ts +22 -41
- package/lib/session.js +104 -150
- package/lib/storage.d.ts +95 -0
- package/lib/storage.js +291 -0
- package/lib/types.d.ts +8 -8
- package/lib/user-manager.d.ts +49 -92
- package/lib/user-manager.js +183 -293
- package/lib/vtilt.js +4 -2
- package/package.json +1 -1
package/lib/storage.js
ADDED
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Unified Storage Manager - Following PostHog's PostHogPersistence pattern
|
|
4
|
+
*
|
|
5
|
+
* Single class handles all storage operations for both sessions and users.
|
|
6
|
+
* Reduces code duplication and ensures consistent cookie handling.
|
|
7
|
+
*
|
|
8
|
+
* Storage methods:
|
|
9
|
+
* - cookie: Browser cookies (cross-subdomain support)
|
|
10
|
+
* - localStorage: Persistent local storage
|
|
11
|
+
* - sessionStorage: Tab-specific storage (cleared on tab close)
|
|
12
|
+
* - localStorage+cookie: Both for redundancy
|
|
13
|
+
* - memory: In-memory only (no persistence)
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.StorageManager = exports.USER_COOKIE_MAX_AGE = exports.SESSION_COOKIE_MAX_AGE = void 0;
|
|
17
|
+
exports.createStorageManager = createStorageManager;
|
|
18
|
+
const constants_1 = require("./constants");
|
|
19
|
+
const globals_1 = require("./utils/globals");
|
|
20
|
+
// Default cookie TTLs
|
|
21
|
+
exports.SESSION_COOKIE_MAX_AGE = 1800; // 30 minutes
|
|
22
|
+
exports.USER_COOKIE_MAX_AGE = 31536000; // 1 year
|
|
23
|
+
/**
|
|
24
|
+
* Unified Storage Manager
|
|
25
|
+
* Provides consistent storage operations across all persistence methods
|
|
26
|
+
*/
|
|
27
|
+
class StorageManager {
|
|
28
|
+
constructor(options) {
|
|
29
|
+
var _a;
|
|
30
|
+
this.memoryStorage = new Map();
|
|
31
|
+
this.method = options.method;
|
|
32
|
+
this.domain = options.domain;
|
|
33
|
+
this.sameSite = options.sameSite || "Lax";
|
|
34
|
+
// Auto-detect secure flag from protocol
|
|
35
|
+
this.secure =
|
|
36
|
+
(_a = options.secure) !== null && _a !== void 0 ? _a : (typeof location !== "undefined" && location.protocol === "https:");
|
|
37
|
+
}
|
|
38
|
+
// ============================================================================
|
|
39
|
+
// Public API - Simple key-value operations
|
|
40
|
+
// ============================================================================
|
|
41
|
+
/**
|
|
42
|
+
* Get a value from storage
|
|
43
|
+
*/
|
|
44
|
+
get(key) {
|
|
45
|
+
var _a;
|
|
46
|
+
try {
|
|
47
|
+
if (this.method === constants_1.PERSISTENCE_METHODS.memory) {
|
|
48
|
+
return (_a = this.memoryStorage.get(key)) !== null && _a !== void 0 ? _a : null;
|
|
49
|
+
}
|
|
50
|
+
if (this.usesLocalStorage()) {
|
|
51
|
+
const value = localStorage.getItem(key);
|
|
52
|
+
if (value !== null)
|
|
53
|
+
return value;
|
|
54
|
+
// Fall back to cookie for localStorage+cookie mode
|
|
55
|
+
if (this.method === constants_1.PERSISTENCE_METHODS.localStoragePlusCookie) {
|
|
56
|
+
return this.getCookie(key);
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
if (this.usesSessionStorage()) {
|
|
61
|
+
return sessionStorage.getItem(key);
|
|
62
|
+
}
|
|
63
|
+
// Cookie-only mode
|
|
64
|
+
return this.getCookie(key);
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
console.warn(`[StorageManager] Failed to get "${key}":`, error);
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Set a value in storage
|
|
73
|
+
* @param maxAge - Cookie max age in seconds (ignored for localStorage/sessionStorage)
|
|
74
|
+
*/
|
|
75
|
+
set(key, value, maxAge) {
|
|
76
|
+
try {
|
|
77
|
+
if (this.method === constants_1.PERSISTENCE_METHODS.memory) {
|
|
78
|
+
this.memoryStorage.set(key, value);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (this.usesLocalStorage()) {
|
|
82
|
+
localStorage.setItem(key, value);
|
|
83
|
+
// Also set cookie for localStorage+cookie mode
|
|
84
|
+
if (this.method === constants_1.PERSISTENCE_METHODS.localStoragePlusCookie) {
|
|
85
|
+
this.setCookie(key, value, maxAge || exports.USER_COOKIE_MAX_AGE);
|
|
86
|
+
}
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (this.usesSessionStorage()) {
|
|
90
|
+
sessionStorage.setItem(key, value);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
// Cookie-only mode
|
|
94
|
+
this.setCookie(key, value, maxAge || exports.USER_COOKIE_MAX_AGE);
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
console.warn(`[StorageManager] Failed to set "${key}":`, error);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Remove a value from storage
|
|
102
|
+
*/
|
|
103
|
+
remove(key) {
|
|
104
|
+
try {
|
|
105
|
+
if (this.method === constants_1.PERSISTENCE_METHODS.memory) {
|
|
106
|
+
this.memoryStorage.delete(key);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (this.usesLocalStorage()) {
|
|
110
|
+
localStorage.removeItem(key);
|
|
111
|
+
if (this.method === constants_1.PERSISTENCE_METHODS.localStoragePlusCookie) {
|
|
112
|
+
this.removeCookie(key);
|
|
113
|
+
}
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (this.usesSessionStorage()) {
|
|
117
|
+
sessionStorage.removeItem(key);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
// Cookie-only mode
|
|
121
|
+
this.removeCookie(key);
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
console.warn(`[StorageManager] Failed to remove "${key}":`, error);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// ============================================================================
|
|
128
|
+
// JSON operations with optional expiry (for session data)
|
|
129
|
+
// ============================================================================
|
|
130
|
+
/**
|
|
131
|
+
* Get JSON value with expiry check
|
|
132
|
+
* Returns null if expired or not found
|
|
133
|
+
*/
|
|
134
|
+
getWithExpiry(key) {
|
|
135
|
+
const raw = this.get(key);
|
|
136
|
+
if (!raw)
|
|
137
|
+
return null;
|
|
138
|
+
try {
|
|
139
|
+
const item = JSON.parse(raw);
|
|
140
|
+
// Check expiry if set
|
|
141
|
+
if (item.expiry && Date.now() > item.expiry) {
|
|
142
|
+
this.remove(key);
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
return item.value;
|
|
146
|
+
}
|
|
147
|
+
catch (_a) {
|
|
148
|
+
// Not JSON or invalid format - return raw value if compatible
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Set JSON value with optional expiry
|
|
154
|
+
* @param ttlMs - Time to live in milliseconds
|
|
155
|
+
*/
|
|
156
|
+
setWithExpiry(key, value, ttlMs) {
|
|
157
|
+
const item = {
|
|
158
|
+
value,
|
|
159
|
+
...(ttlMs ? { expiry: Date.now() + ttlMs } : {}),
|
|
160
|
+
};
|
|
161
|
+
this.set(key, JSON.stringify(item));
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Get JSON value (no expiry check)
|
|
165
|
+
*/
|
|
166
|
+
getJSON(key) {
|
|
167
|
+
const raw = this.get(key);
|
|
168
|
+
if (!raw)
|
|
169
|
+
return null;
|
|
170
|
+
try {
|
|
171
|
+
return JSON.parse(raw);
|
|
172
|
+
}
|
|
173
|
+
catch (_a) {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Set JSON value
|
|
179
|
+
*/
|
|
180
|
+
setJSON(key, value, maxAge) {
|
|
181
|
+
this.set(key, JSON.stringify(value), maxAge);
|
|
182
|
+
}
|
|
183
|
+
// ============================================================================
|
|
184
|
+
// Cookie operations (internal)
|
|
185
|
+
// ============================================================================
|
|
186
|
+
getCookie(name) {
|
|
187
|
+
if (typeof document === "undefined")
|
|
188
|
+
return null;
|
|
189
|
+
const cookies = document.cookie.split(";");
|
|
190
|
+
for (const cookie of cookies) {
|
|
191
|
+
const [key, ...valueParts] = cookie.trim().split("=");
|
|
192
|
+
if (key === name) {
|
|
193
|
+
const value = valueParts.join("="); // Handle values with = in them
|
|
194
|
+
try {
|
|
195
|
+
return decodeURIComponent(value);
|
|
196
|
+
}
|
|
197
|
+
catch (_a) {
|
|
198
|
+
return value;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
setCookie(name, value, maxAge) {
|
|
205
|
+
if (typeof document === "undefined")
|
|
206
|
+
return;
|
|
207
|
+
let cookieString = `${name}=${encodeURIComponent(value)}`;
|
|
208
|
+
cookieString += `; Max-Age=${maxAge}`;
|
|
209
|
+
cookieString += `; path=/`;
|
|
210
|
+
cookieString += `; SameSite=${this.sameSite}`;
|
|
211
|
+
if (this.secure) {
|
|
212
|
+
cookieString += `; Secure`;
|
|
213
|
+
}
|
|
214
|
+
if (this.domain) {
|
|
215
|
+
cookieString += `; domain=${this.domain}`;
|
|
216
|
+
}
|
|
217
|
+
document.cookie = cookieString;
|
|
218
|
+
}
|
|
219
|
+
removeCookie(name) {
|
|
220
|
+
if (typeof document === "undefined")
|
|
221
|
+
return;
|
|
222
|
+
// Set cookie with expired date
|
|
223
|
+
let cookieString = `${name}=; Max-Age=0; path=/`;
|
|
224
|
+
if (this.domain) {
|
|
225
|
+
cookieString += `; domain=${this.domain}`;
|
|
226
|
+
}
|
|
227
|
+
document.cookie = cookieString;
|
|
228
|
+
// Also try without domain (in case it was set without)
|
|
229
|
+
document.cookie = `${name}=; Max-Age=0; path=/`;
|
|
230
|
+
}
|
|
231
|
+
// ============================================================================
|
|
232
|
+
// Helper methods
|
|
233
|
+
// ============================================================================
|
|
234
|
+
usesLocalStorage() {
|
|
235
|
+
return (this.method === constants_1.PERSISTENCE_METHODS.localStorage ||
|
|
236
|
+
this.method === constants_1.PERSISTENCE_METHODS.localStoragePlusCookie);
|
|
237
|
+
}
|
|
238
|
+
usesSessionStorage() {
|
|
239
|
+
return this.method === constants_1.PERSISTENCE_METHODS.sessionStorage;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Check if sessionStorage is available
|
|
243
|
+
*/
|
|
244
|
+
canUseSessionStorage() {
|
|
245
|
+
if (typeof globals_1.window === "undefined" || !(globals_1.window === null || globals_1.window === void 0 ? void 0 : globals_1.window.sessionStorage)) {
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
248
|
+
try {
|
|
249
|
+
const testKey = "__vt_storage_test__";
|
|
250
|
+
globals_1.window.sessionStorage.setItem(testKey, "test");
|
|
251
|
+
globals_1.window.sessionStorage.removeItem(testKey);
|
|
252
|
+
return true;
|
|
253
|
+
}
|
|
254
|
+
catch (_a) {
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Get direct access to sessionStorage (for window_id which always uses sessionStorage)
|
|
260
|
+
*/
|
|
261
|
+
getSessionStorage() {
|
|
262
|
+
var _a;
|
|
263
|
+
if (!this.canUseSessionStorage())
|
|
264
|
+
return null;
|
|
265
|
+
return (_a = globals_1.window === null || globals_1.window === void 0 ? void 0 : globals_1.window.sessionStorage) !== null && _a !== void 0 ? _a : null;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Update storage method at runtime
|
|
269
|
+
*/
|
|
270
|
+
setMethod(method) {
|
|
271
|
+
this.method = method;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Get current storage method
|
|
275
|
+
*/
|
|
276
|
+
getMethod() {
|
|
277
|
+
return this.method;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
exports.StorageManager = StorageManager;
|
|
281
|
+
/**
|
|
282
|
+
* Create a shared storage instance
|
|
283
|
+
* Use this for creating storage managers with consistent settings
|
|
284
|
+
*/
|
|
285
|
+
function createStorageManager(method, domain) {
|
|
286
|
+
return new StorageManager({
|
|
287
|
+
method,
|
|
288
|
+
domain,
|
|
289
|
+
sameSite: "Lax",
|
|
290
|
+
});
|
|
291
|
+
}
|
package/lib/types.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Type definitions for the VTilt tracking SDK.
|
|
5
5
|
* Following PostHog's patterns where applicable.
|
|
6
6
|
*/
|
|
7
|
-
import type { PersonProfilesMode } from
|
|
7
|
+
import type { PersonProfilesMode } from "./constants";
|
|
8
8
|
export interface VTiltConfig {
|
|
9
9
|
/** Project identifier (required) */
|
|
10
10
|
token: string;
|
|
@@ -42,9 +42,9 @@ export interface VTiltConfig {
|
|
|
42
42
|
/** Enable web vitals tracking */
|
|
43
43
|
capture_performance?: boolean;
|
|
44
44
|
/** Enable page view tracking */
|
|
45
|
-
capture_pageview?: boolean |
|
|
45
|
+
capture_pageview?: boolean | "auto";
|
|
46
46
|
/** Enable page leave tracking */
|
|
47
|
-
capture_pageleave?: boolean |
|
|
47
|
+
capture_pageleave?: boolean | "if_capture_pageview";
|
|
48
48
|
/** Disable compression */
|
|
49
49
|
disable_compression?: boolean;
|
|
50
50
|
/** Whether to stringify payload before sending */
|
|
@@ -124,7 +124,7 @@ export interface SessionData {
|
|
|
124
124
|
* - 'sessionStorage': Stores all data in sessionStorage
|
|
125
125
|
* - 'memory': Stores all data in memory only (no persistence)
|
|
126
126
|
*/
|
|
127
|
-
export type PersistenceMethod =
|
|
127
|
+
export type PersistenceMethod = "localStorage+cookie" | "cookie" | "localStorage" | "sessionStorage" | "memory";
|
|
128
128
|
/** User identity state */
|
|
129
129
|
export interface UserIdentity {
|
|
130
130
|
/** Current distinct ID (null if anonymous) */
|
|
@@ -136,7 +136,7 @@ export interface UserIdentity {
|
|
|
136
136
|
/** User properties */
|
|
137
137
|
properties: Properties;
|
|
138
138
|
/** Identity state */
|
|
139
|
-
user_state:
|
|
139
|
+
user_state: "anonymous" | "identified";
|
|
140
140
|
}
|
|
141
141
|
export interface UserProperties {
|
|
142
142
|
[key: string]: any;
|
|
@@ -149,7 +149,7 @@ export interface WebVitalMetric {
|
|
|
149
149
|
name: string;
|
|
150
150
|
value: number;
|
|
151
151
|
delta: number;
|
|
152
|
-
rating:
|
|
152
|
+
rating: "good" | "needs-improvement" | "poor";
|
|
153
153
|
id: string;
|
|
154
154
|
navigationType: string;
|
|
155
155
|
}
|
|
@@ -164,10 +164,10 @@ export interface FeatureFlagsConfig {
|
|
|
164
164
|
[flagKey: string]: boolean | string;
|
|
165
165
|
}
|
|
166
166
|
export type SessionIdChangedCallback = (newSessionId: string, previousSessionId: string | null, changeInfo: {
|
|
167
|
-
reason:
|
|
167
|
+
reason: "timeout" | "new_session" | "reset";
|
|
168
168
|
}) => void;
|
|
169
169
|
export interface RequestOptions {
|
|
170
|
-
method?:
|
|
170
|
+
method?: "POST" | "GET";
|
|
171
171
|
headers?: Record<string, string>;
|
|
172
172
|
timeout?: number;
|
|
173
173
|
retry?: boolean;
|
package/lib/user-manager.d.ts
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User Manager - Handles user identity and properties
|
|
3
|
+
*
|
|
4
|
+
* Uses shared StorageManager for consistent storage operations.
|
|
5
|
+
*
|
|
6
|
+
* Manages:
|
|
7
|
+
* - anonymous_id: Generated ID for anonymous users
|
|
8
|
+
* - distinct_id: User-provided ID after identification
|
|
9
|
+
* - device_id: Persistent device identifier
|
|
10
|
+
* - user_properties: Custom properties set via identify/setUserProperties
|
|
11
|
+
* - user_state: "anonymous" or "identified"
|
|
12
|
+
*/
|
|
1
13
|
import { UserIdentity, AliasEvent, PersistenceMethod } from "./types";
|
|
2
14
|
export declare class UserManager {
|
|
3
|
-
private
|
|
4
|
-
private domain?;
|
|
15
|
+
private storage;
|
|
5
16
|
private userIdentity;
|
|
6
17
|
private _cachedPersonProperties;
|
|
7
18
|
constructor(storageMethod?: PersistenceMethod, domain?: string);
|
|
@@ -21,57 +32,31 @@ export declare class UserManager {
|
|
|
21
32
|
* Get current user properties
|
|
22
33
|
*/
|
|
23
34
|
getUserProperties(): Record<string, any>;
|
|
35
|
+
/**
|
|
36
|
+
* Get the effective ID for event tracking
|
|
37
|
+
*/
|
|
38
|
+
getEffectiveId(): string;
|
|
39
|
+
/**
|
|
40
|
+
* Get current device ID
|
|
41
|
+
*/
|
|
42
|
+
getDeviceId(): string;
|
|
43
|
+
/**
|
|
44
|
+
* Get current user state
|
|
45
|
+
*/
|
|
46
|
+
getUserState(): "anonymous" | "identified";
|
|
24
47
|
/**
|
|
25
48
|
* Identify a user with distinct ID and properties
|
|
26
49
|
*/
|
|
27
50
|
identify(newDistinctId?: string, userPropertiesToSet?: Record<string, any>, userPropertiesToSetOnce?: Record<string, any>): void;
|
|
28
51
|
/**
|
|
29
52
|
* Set user properties without changing distinct ID
|
|
30
|
-
* Sets properties on the person profile associated with the current distinct_id
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```js
|
|
34
|
-
* // Set properties that can be updated
|
|
35
|
-
* vt.setUserProperties({ name: 'John Doe', email: 'john@example.com' })
|
|
36
|
-
* ```
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* ```js
|
|
40
|
-
* // Set properties with $set and $set_once operations
|
|
41
|
-
* vt.setUserProperties(
|
|
42
|
-
* { name: 'John Doe', last_login: new Date().toISOString() }, // $set properties
|
|
43
|
-
* { first_login: new Date().toISOString() } // $set_once properties
|
|
44
|
-
* )
|
|
45
|
-
* ```
|
|
46
|
-
*
|
|
47
|
-
* @param userPropertiesToSet Optional: Properties to set (can be updated)
|
|
48
|
-
* @param userPropertiesToSetOnce Optional: Properties to set once (preserves first value)
|
|
49
53
|
*/
|
|
50
54
|
setUserProperties(userPropertiesToSet?: Record<string, any>, userPropertiesToSetOnce?: Record<string, any>): boolean;
|
|
51
|
-
/**
|
|
52
|
-
* Get hash for person properties
|
|
53
|
-
* Used for deduplication of identical setUserProperties calls
|
|
54
|
-
*/
|
|
55
|
-
private getPersonPropertiesHash;
|
|
56
55
|
/**
|
|
57
56
|
* Reset user identity (logout)
|
|
58
57
|
* Generates new anonymous ID, clears user data, optionally resets device ID
|
|
59
|
-
*
|
|
60
|
-
* @param reset_device_id - If true, also resets device_id. Default: false (preserves device_id)
|
|
61
58
|
*/
|
|
62
59
|
reset(reset_device_id?: boolean): void;
|
|
63
|
-
/**
|
|
64
|
-
* Get the effective ID for event tracking
|
|
65
|
-
*/
|
|
66
|
-
getEffectiveId(): string;
|
|
67
|
-
/**
|
|
68
|
-
* Get current device ID
|
|
69
|
-
*/
|
|
70
|
-
getDeviceId(): string;
|
|
71
|
-
/**
|
|
72
|
-
* Get current user state
|
|
73
|
-
*/
|
|
74
|
-
getUserState(): "anonymous" | "identified";
|
|
75
60
|
/**
|
|
76
61
|
* Update distinct ID (internal use - for VTilt)
|
|
77
62
|
*/
|
|
@@ -88,29 +73,26 @@ export declare class UserManager {
|
|
|
88
73
|
* Set device ID if not already set (internal use - for VTilt)
|
|
89
74
|
*/
|
|
90
75
|
ensureDeviceId(deviceId: string): void;
|
|
76
|
+
/**
|
|
77
|
+
* Create an alias to link two distinct IDs
|
|
78
|
+
*/
|
|
79
|
+
createAlias(alias: string, original?: string): AliasEvent | null;
|
|
91
80
|
/**
|
|
92
81
|
* Check if distinct ID is string-like (hardcoded string) - public for validation
|
|
93
|
-
* This is a wrapper to expose the private method
|
|
94
82
|
*/
|
|
95
83
|
isDistinctIdStringLikePublic(distinctId: string): boolean;
|
|
96
84
|
/**
|
|
97
|
-
*
|
|
98
|
-
* If original is not provided, uses current distinct_id
|
|
99
|
-
* If alias matches original, returns null (caller should use identify instead)
|
|
100
|
-
*
|
|
101
|
-
* @param alias - A unique identifier that you want to use for this user in the future
|
|
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
|
|
85
|
+
* Set initial person info
|
|
104
86
|
*/
|
|
105
|
-
|
|
87
|
+
set_initial_person_info(maskPersonalDataProperties?: boolean, customPersonalDataProperties?: string[]): void;
|
|
106
88
|
/**
|
|
107
|
-
*
|
|
89
|
+
* Get initial props
|
|
108
90
|
*/
|
|
109
|
-
|
|
91
|
+
get_initial_props(): Record<string, any>;
|
|
110
92
|
/**
|
|
111
|
-
*
|
|
93
|
+
* Update referrer info
|
|
112
94
|
*/
|
|
113
|
-
|
|
95
|
+
update_referrer_info(): void;
|
|
114
96
|
/**
|
|
115
97
|
* Load user identity from storage
|
|
116
98
|
*/
|
|
@@ -119,26 +101,6 @@ export declare class UserManager {
|
|
|
119
101
|
* Save user identity to storage
|
|
120
102
|
*/
|
|
121
103
|
private saveUserIdentity;
|
|
122
|
-
/**
|
|
123
|
-
* Generate a new anonymous ID
|
|
124
|
-
*/
|
|
125
|
-
private generateAnonymousId;
|
|
126
|
-
/**
|
|
127
|
-
* Generate a new device ID
|
|
128
|
-
*/
|
|
129
|
-
private generateDeviceId;
|
|
130
|
-
/**
|
|
131
|
-
* Get stored value from storage
|
|
132
|
-
*/
|
|
133
|
-
private getStoredValue;
|
|
134
|
-
/**
|
|
135
|
-
* Set stored value in storage
|
|
136
|
-
*/
|
|
137
|
-
private setStoredValue;
|
|
138
|
-
/**
|
|
139
|
-
* Remove stored value from storage
|
|
140
|
-
*/
|
|
141
|
-
private removeStoredValue;
|
|
142
104
|
/**
|
|
143
105
|
* Get user properties from storage
|
|
144
106
|
*/
|
|
@@ -148,36 +110,31 @@ export declare class UserManager {
|
|
|
148
110
|
*/
|
|
149
111
|
private setStoredUserProperties;
|
|
150
112
|
/**
|
|
151
|
-
*
|
|
113
|
+
* Register a value once (only if not already set)
|
|
152
114
|
*/
|
|
153
|
-
private
|
|
115
|
+
private register_once;
|
|
154
116
|
/**
|
|
155
|
-
*
|
|
117
|
+
* Generate a new anonymous ID
|
|
156
118
|
*/
|
|
157
|
-
private
|
|
119
|
+
private generateAnonymousId;
|
|
158
120
|
/**
|
|
159
|
-
*
|
|
121
|
+
* Generate a new device ID
|
|
160
122
|
*/
|
|
161
|
-
private
|
|
123
|
+
private generateDeviceId;
|
|
162
124
|
/**
|
|
163
|
-
*
|
|
164
|
-
* Stores properties in localStorage only if they don't already exist
|
|
125
|
+
* Get hash for person properties (for deduplication)
|
|
165
126
|
*/
|
|
166
|
-
private
|
|
127
|
+
private getPersonPropertiesHash;
|
|
167
128
|
/**
|
|
168
|
-
*
|
|
169
|
-
* Stores referrer and URL info on first visit for generating $initial_* properties
|
|
129
|
+
* Validate distinct ID
|
|
170
130
|
*/
|
|
171
|
-
|
|
131
|
+
private isValidDistinctId;
|
|
172
132
|
/**
|
|
173
|
-
*
|
|
174
|
-
* Generates $initial_* properties from stored initial person info
|
|
175
|
-
* These are sent with events as $set_once to preserve first values
|
|
133
|
+
* Check if distinct ID is string-like (hardcoded string)
|
|
176
134
|
*/
|
|
177
|
-
|
|
135
|
+
private isDistinctIdStringLike;
|
|
178
136
|
/**
|
|
179
|
-
* Update
|
|
180
|
-
* Stores current referrer information if not already stored
|
|
137
|
+
* Update storage method at runtime
|
|
181
138
|
*/
|
|
182
|
-
|
|
139
|
+
updateStorageMethod(method: PersistenceMethod, domain?: string): void;
|
|
183
140
|
}
|