@v-tilt/browser 1.1.3 → 1.1.5
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/main.js +1 -1
- package/dist/main.js.map +1 -1
- package/dist/module.d.ts +7 -3
- package/dist/module.js +1 -1
- package/dist/module.js.map +1 -1
- package/dist/module.no-external.d.ts +7 -3
- package/dist/module.no-external.js +1 -1
- package/dist/module.no-external.js.map +1 -1
- package/dist/session.d.ts +4 -2
- package/dist/storage.d.ts +8 -3
- package/dist/types.d.ts +7 -3
- package/dist/user-manager.d.ts +2 -2
- package/lib/session.d.ts +4 -2
- package/lib/session.js +7 -41
- package/lib/storage.d.ts +8 -3
- package/lib/storage.js +76 -16
- package/lib/types.d.ts +7 -3
- package/lib/user-manager.d.ts +2 -2
- package/lib/user-manager.js +4 -4
- package/lib/vtilt.js +4 -14
- package/package.json +1 -1
package/dist/session.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { PersistenceMethod } from "./types";
|
|
|
10
10
|
export declare class SessionManager {
|
|
11
11
|
private storage;
|
|
12
12
|
private _windowId;
|
|
13
|
-
constructor(storageMethod?: PersistenceMethod,
|
|
13
|
+
constructor(storageMethod?: PersistenceMethod, cross_subdomain?: boolean);
|
|
14
14
|
/**
|
|
15
15
|
* Get session ID (always returns a value, generates if needed)
|
|
16
16
|
*/
|
|
@@ -26,10 +26,12 @@ export declare class SessionManager {
|
|
|
26
26
|
resetSessionId(): void;
|
|
27
27
|
/**
|
|
28
28
|
* Get session ID from storage (raw, can return null)
|
|
29
|
+
* Cookie Max-Age handles expiration automatically
|
|
29
30
|
*/
|
|
30
31
|
private _getSessionIdRaw;
|
|
31
32
|
/**
|
|
32
33
|
* Store session ID
|
|
34
|
+
* Uses plain string format - cookie Max-Age handles expiration
|
|
33
35
|
*/
|
|
34
36
|
private _storeSessionId;
|
|
35
37
|
/**
|
|
@@ -60,5 +62,5 @@ export declare class SessionManager {
|
|
|
60
62
|
/**
|
|
61
63
|
* Update storage method at runtime
|
|
62
64
|
*/
|
|
63
|
-
updateStorageMethod(method: PersistenceMethod,
|
|
65
|
+
updateStorageMethod(method: PersistenceMethod, cross_subdomain?: boolean): void;
|
|
64
66
|
}
|
package/dist/storage.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export declare const SESSION_COOKIE_MAX_AGE = 1800;
|
|
|
16
16
|
export declare const USER_COOKIE_MAX_AGE = 31536000;
|
|
17
17
|
export interface StorageOptions {
|
|
18
18
|
method: PersistenceMethod;
|
|
19
|
-
|
|
19
|
+
cross_subdomain?: boolean;
|
|
20
20
|
secure?: boolean;
|
|
21
21
|
sameSite?: "Strict" | "Lax" | "None";
|
|
22
22
|
}
|
|
@@ -24,13 +24,18 @@ export interface StorageItem<T = string> {
|
|
|
24
24
|
value: T;
|
|
25
25
|
expiry?: number;
|
|
26
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Auto-detect if cross-subdomain cookies should be enabled
|
|
29
|
+
* Returns false for platforms like herokuapp.com, vercel.app, netlify.app
|
|
30
|
+
*/
|
|
31
|
+
export declare function shouldUseCrossSubdomainCookie(): boolean;
|
|
27
32
|
/**
|
|
28
33
|
* Unified Storage Manager
|
|
29
34
|
* Provides consistent storage operations across all persistence methods
|
|
30
35
|
*/
|
|
31
36
|
export declare class StorageManager {
|
|
32
37
|
private method;
|
|
33
|
-
private
|
|
38
|
+
private cross_subdomain;
|
|
34
39
|
private secure;
|
|
35
40
|
private sameSite;
|
|
36
41
|
private memoryStorage;
|
|
@@ -92,4 +97,4 @@ export declare class StorageManager {
|
|
|
92
97
|
* Create a shared storage instance
|
|
93
98
|
* Use this for creating storage managers with consistent settings
|
|
94
99
|
*/
|
|
95
|
-
export declare function createStorageManager(method: PersistenceMethod,
|
|
100
|
+
export declare function createStorageManager(method: PersistenceMethod, cross_subdomain?: boolean): StorageManager;
|
package/dist/types.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export interface VTiltConfig {
|
|
|
20
20
|
name?: string;
|
|
21
21
|
/** Project ID (set via init() first argument) */
|
|
22
22
|
projectId?: string;
|
|
23
|
-
/** Domain to track (auto-detected if not provided) */
|
|
23
|
+
/** Domain to track (auto-detected if not provided) - used in event properties */
|
|
24
24
|
domain?: string;
|
|
25
25
|
/** Storage method for session data */
|
|
26
26
|
storage?: PersistenceMethod;
|
|
@@ -28,7 +28,12 @@ export interface VTiltConfig {
|
|
|
28
28
|
persistence?: PersistenceMethod;
|
|
29
29
|
/** Persistence name prefix */
|
|
30
30
|
persistence_name?: string;
|
|
31
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* Enable cross-subdomain cookies.
|
|
33
|
+
* When true, cookies are shared across subdomains (e.g., app.example.com and www.example.com).
|
|
34
|
+
* Auto-detects false for platforms like herokuapp.com, vercel.app, netlify.app.
|
|
35
|
+
* @default true (except for excluded platforms)
|
|
36
|
+
*/
|
|
32
37
|
cross_subdomain_cookie?: boolean;
|
|
33
38
|
/**
|
|
34
39
|
* Person profiles mode:
|
|
@@ -97,7 +102,6 @@ export interface TrackingEvent {
|
|
|
97
102
|
timestamp: string;
|
|
98
103
|
event: string;
|
|
99
104
|
project_id: string;
|
|
100
|
-
domain: string;
|
|
101
105
|
distinct_id: string;
|
|
102
106
|
anonymous_id?: string;
|
|
103
107
|
payload: EventPayload;
|
package/dist/user-manager.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export declare class UserManager {
|
|
|
15
15
|
private storage;
|
|
16
16
|
private userIdentity;
|
|
17
17
|
private _cachedPersonProperties;
|
|
18
|
-
constructor(storageMethod?: PersistenceMethod,
|
|
18
|
+
constructor(storageMethod?: PersistenceMethod, cross_subdomain?: boolean);
|
|
19
19
|
/**
|
|
20
20
|
* Get current user identity
|
|
21
21
|
*/
|
|
@@ -136,5 +136,5 @@ export declare class UserManager {
|
|
|
136
136
|
/**
|
|
137
137
|
* Update storage method at runtime
|
|
138
138
|
*/
|
|
139
|
-
updateStorageMethod(method: PersistenceMethod,
|
|
139
|
+
updateStorageMethod(method: PersistenceMethod, cross_subdomain?: boolean): void;
|
|
140
140
|
}
|
package/lib/session.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { PersistenceMethod } from "./types";
|
|
|
10
10
|
export declare class SessionManager {
|
|
11
11
|
private storage;
|
|
12
12
|
private _windowId;
|
|
13
|
-
constructor(storageMethod?: PersistenceMethod,
|
|
13
|
+
constructor(storageMethod?: PersistenceMethod, cross_subdomain?: boolean);
|
|
14
14
|
/**
|
|
15
15
|
* Get session ID (always returns a value, generates if needed)
|
|
16
16
|
*/
|
|
@@ -26,10 +26,12 @@ export declare class SessionManager {
|
|
|
26
26
|
resetSessionId(): void;
|
|
27
27
|
/**
|
|
28
28
|
* Get session ID from storage (raw, can return null)
|
|
29
|
+
* Cookie Max-Age handles expiration automatically
|
|
29
30
|
*/
|
|
30
31
|
private _getSessionIdRaw;
|
|
31
32
|
/**
|
|
32
33
|
* Store session ID
|
|
34
|
+
* Uses plain string format - cookie Max-Age handles expiration
|
|
33
35
|
*/
|
|
34
36
|
private _storeSessionId;
|
|
35
37
|
/**
|
|
@@ -60,5 +62,5 @@ export declare class SessionManager {
|
|
|
60
62
|
/**
|
|
61
63
|
* Update storage method at runtime
|
|
62
64
|
*/
|
|
63
|
-
updateStorageMethod(method: PersistenceMethod,
|
|
65
|
+
updateStorageMethod(method: PersistenceMethod, cross_subdomain?: boolean): void;
|
|
64
66
|
}
|
package/lib/session.js
CHANGED
|
@@ -13,13 +13,11 @@ const constants_1 = require("./constants");
|
|
|
13
13
|
const utils_1 = require("./utils");
|
|
14
14
|
const globals_1 = require("./utils/globals");
|
|
15
15
|
const storage_1 = require("./storage");
|
|
16
|
-
// Session TTL in milliseconds (30 minutes)
|
|
17
|
-
const SESSION_TTL_MS = 30 * 60 * 1000;
|
|
18
16
|
class SessionManager {
|
|
19
|
-
constructor(storageMethod = "cookie",
|
|
17
|
+
constructor(storageMethod = "cookie", cross_subdomain) {
|
|
20
18
|
this.storage = new storage_1.StorageManager({
|
|
21
19
|
method: storageMethod,
|
|
22
|
-
|
|
20
|
+
cross_subdomain,
|
|
23
21
|
sameSite: "Lax",
|
|
24
22
|
});
|
|
25
23
|
this._windowId = undefined;
|
|
@@ -66,48 +64,16 @@ class SessionManager {
|
|
|
66
64
|
}
|
|
67
65
|
/**
|
|
68
66
|
* Get session ID from storage (raw, can return null)
|
|
67
|
+
* Cookie Max-Age handles expiration automatically
|
|
69
68
|
*/
|
|
70
69
|
_getSessionIdRaw() {
|
|
71
|
-
|
|
72
|
-
const sessionData = this.storage.getWithExpiry(constants_1.STORAGE_KEY);
|
|
73
|
-
if (sessionData) {
|
|
74
|
-
return sessionData;
|
|
75
|
-
}
|
|
76
|
-
// For cookie mode, the cookie itself handles expiry via Max-Age
|
|
77
|
-
// Just get the raw value
|
|
78
|
-
const rawValue = this.storage.get(constants_1.STORAGE_KEY);
|
|
79
|
-
if (rawValue) {
|
|
80
|
-
// Check if it's JSON format (from web storage) or plain string (from cookie)
|
|
81
|
-
try {
|
|
82
|
-
const parsed = JSON.parse(rawValue);
|
|
83
|
-
// If it's a StorageItem, extract value and check expiry
|
|
84
|
-
if (typeof parsed === "object" &&
|
|
85
|
-
parsed !== null &&
|
|
86
|
-
"value" in parsed) {
|
|
87
|
-
if (parsed.expiry && Date.now() > parsed.expiry) {
|
|
88
|
-
this.storage.remove(constants_1.STORAGE_KEY);
|
|
89
|
-
return null;
|
|
90
|
-
}
|
|
91
|
-
return parsed.value;
|
|
92
|
-
}
|
|
93
|
-
return rawValue;
|
|
94
|
-
}
|
|
95
|
-
catch (_a) {
|
|
96
|
-
// Plain string value (from cookie)
|
|
97
|
-
return rawValue;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return null;
|
|
70
|
+
return this.storage.get(constants_1.STORAGE_KEY);
|
|
101
71
|
}
|
|
102
72
|
/**
|
|
103
73
|
* Store session ID
|
|
74
|
+
* Uses plain string format - cookie Max-Age handles expiration
|
|
104
75
|
*/
|
|
105
76
|
_storeSessionId(sessionId) {
|
|
106
|
-
// Use setWithExpiry for localStorage/sessionStorage
|
|
107
|
-
// For cookies, the StorageManager handles Max-Age
|
|
108
|
-
this.storage.setWithExpiry(sessionId, sessionId, SESSION_TTL_MS);
|
|
109
|
-
// Also set as plain cookie for cookie mode (overwrites JSON format)
|
|
110
|
-
// This ensures cookies work properly with Max-Age
|
|
111
77
|
this.storage.set(constants_1.STORAGE_KEY, sessionId, storage_1.SESSION_COOKIE_MAX_AGE);
|
|
112
78
|
}
|
|
113
79
|
/**
|
|
@@ -214,10 +180,10 @@ class SessionManager {
|
|
|
214
180
|
/**
|
|
215
181
|
* Update storage method at runtime
|
|
216
182
|
*/
|
|
217
|
-
updateStorageMethod(method,
|
|
183
|
+
updateStorageMethod(method, cross_subdomain) {
|
|
218
184
|
this.storage = new storage_1.StorageManager({
|
|
219
185
|
method,
|
|
220
|
-
|
|
186
|
+
cross_subdomain,
|
|
221
187
|
sameSite: "Lax",
|
|
222
188
|
});
|
|
223
189
|
}
|
package/lib/storage.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export declare const SESSION_COOKIE_MAX_AGE = 1800;
|
|
|
16
16
|
export declare const USER_COOKIE_MAX_AGE = 31536000;
|
|
17
17
|
export interface StorageOptions {
|
|
18
18
|
method: PersistenceMethod;
|
|
19
|
-
|
|
19
|
+
cross_subdomain?: boolean;
|
|
20
20
|
secure?: boolean;
|
|
21
21
|
sameSite?: "Strict" | "Lax" | "None";
|
|
22
22
|
}
|
|
@@ -24,13 +24,18 @@ export interface StorageItem<T = string> {
|
|
|
24
24
|
value: T;
|
|
25
25
|
expiry?: number;
|
|
26
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Auto-detect if cross-subdomain cookies should be enabled
|
|
29
|
+
* Returns false for platforms like herokuapp.com, vercel.app, netlify.app
|
|
30
|
+
*/
|
|
31
|
+
export declare function shouldUseCrossSubdomainCookie(): boolean;
|
|
27
32
|
/**
|
|
28
33
|
* Unified Storage Manager
|
|
29
34
|
* Provides consistent storage operations across all persistence methods
|
|
30
35
|
*/
|
|
31
36
|
export declare class StorageManager {
|
|
32
37
|
private method;
|
|
33
|
-
private
|
|
38
|
+
private cross_subdomain;
|
|
34
39
|
private secure;
|
|
35
40
|
private sameSite;
|
|
36
41
|
private memoryStorage;
|
|
@@ -92,4 +97,4 @@ export declare class StorageManager {
|
|
|
92
97
|
* Create a shared storage instance
|
|
93
98
|
* Use this for creating storage managers with consistent settings
|
|
94
99
|
*/
|
|
95
|
-
export declare function createStorageManager(method: PersistenceMethod,
|
|
100
|
+
export declare function createStorageManager(method: PersistenceMethod, cross_subdomain?: boolean): StorageManager;
|
package/lib/storage.js
CHANGED
|
@@ -14,26 +14,75 @@
|
|
|
14
14
|
*/
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.StorageManager = exports.USER_COOKIE_MAX_AGE = exports.SESSION_COOKIE_MAX_AGE = void 0;
|
|
17
|
+
exports.shouldUseCrossSubdomainCookie = shouldUseCrossSubdomainCookie;
|
|
17
18
|
exports.createStorageManager = createStorageManager;
|
|
18
19
|
const constants_1 = require("./constants");
|
|
19
20
|
const globals_1 = require("./utils/globals");
|
|
20
21
|
// Default cookie TTLs
|
|
21
22
|
exports.SESSION_COOKIE_MAX_AGE = 1800; // 30 minutes
|
|
22
23
|
exports.USER_COOKIE_MAX_AGE = 31536000; // 1 year
|
|
24
|
+
// Platforms excluded from cross-subdomain cookies (following PostHog)
|
|
25
|
+
const EXCLUDED_FROM_CROSS_SUBDOMAIN = [
|
|
26
|
+
"herokuapp.com",
|
|
27
|
+
"vercel.app",
|
|
28
|
+
"netlify.app",
|
|
29
|
+
];
|
|
30
|
+
/**
|
|
31
|
+
* Auto-detect if cross-subdomain cookies should be enabled
|
|
32
|
+
* Returns false for platforms like herokuapp.com, vercel.app, netlify.app
|
|
33
|
+
*/
|
|
34
|
+
function shouldUseCrossSubdomainCookie() {
|
|
35
|
+
var _a;
|
|
36
|
+
if (typeof document === "undefined") {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
const hostname = (_a = document.location) === null || _a === void 0 ? void 0 : _a.hostname;
|
|
40
|
+
if (!hostname) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
const lastTwoParts = hostname.split(".").slice(-2).join(".");
|
|
44
|
+
for (const excluded of EXCLUDED_FROM_CROSS_SUBDOMAIN) {
|
|
45
|
+
if (lastTwoParts === excluded) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Get the cookie domain for cross-subdomain cookies
|
|
53
|
+
* Returns domain like ".example.com" or empty string for same-origin
|
|
54
|
+
*/
|
|
55
|
+
function getCookieDomain(cross_subdomain) {
|
|
56
|
+
var _a;
|
|
57
|
+
if (!cross_subdomain) {
|
|
58
|
+
return "";
|
|
59
|
+
}
|
|
60
|
+
if (typeof document === "undefined") {
|
|
61
|
+
return "";
|
|
62
|
+
}
|
|
63
|
+
const hostname = (_a = document.location) === null || _a === void 0 ? void 0 : _a.hostname;
|
|
64
|
+
if (!hostname) {
|
|
65
|
+
return "";
|
|
66
|
+
}
|
|
67
|
+
// Match domain pattern like "example.com" from "sub.example.com"
|
|
68
|
+
const matches = hostname.match(/[a-z0-9][a-z0-9-]+\.[a-z]{2,}$/i);
|
|
69
|
+
return matches ? `.${matches[0]}` : "";
|
|
70
|
+
}
|
|
23
71
|
/**
|
|
24
72
|
* Unified Storage Manager
|
|
25
73
|
* Provides consistent storage operations across all persistence methods
|
|
26
74
|
*/
|
|
27
75
|
class StorageManager {
|
|
28
76
|
constructor(options) {
|
|
29
|
-
var _a;
|
|
77
|
+
var _a, _b;
|
|
30
78
|
this.memoryStorage = new Map();
|
|
31
79
|
this.method = options.method;
|
|
32
|
-
this.
|
|
80
|
+
this.cross_subdomain =
|
|
81
|
+
(_a = options.cross_subdomain) !== null && _a !== void 0 ? _a : shouldUseCrossSubdomainCookie();
|
|
33
82
|
this.sameSite = options.sameSite || "Lax";
|
|
34
83
|
// Auto-detect secure flag from protocol
|
|
35
84
|
this.secure =
|
|
36
|
-
(
|
|
85
|
+
(_b = options.secure) !== null && _b !== void 0 ? _b : (typeof location !== "undefined" && location.protocol === "https:");
|
|
37
86
|
}
|
|
38
87
|
// ============================================================================
|
|
39
88
|
// Public API - Simple key-value operations
|
|
@@ -49,8 +98,9 @@ class StorageManager {
|
|
|
49
98
|
}
|
|
50
99
|
if (this.usesLocalStorage()) {
|
|
51
100
|
const value = localStorage.getItem(key);
|
|
52
|
-
if (value !== null)
|
|
101
|
+
if (value !== null) {
|
|
53
102
|
return value;
|
|
103
|
+
}
|
|
54
104
|
// Fall back to cookie for localStorage+cookie mode
|
|
55
105
|
if (this.method === constants_1.PERSISTENCE_METHODS.localStoragePlusCookie) {
|
|
56
106
|
return this.getCookie(key);
|
|
@@ -133,8 +183,9 @@ class StorageManager {
|
|
|
133
183
|
*/
|
|
134
184
|
getWithExpiry(key) {
|
|
135
185
|
const raw = this.get(key);
|
|
136
|
-
if (!raw)
|
|
186
|
+
if (!raw) {
|
|
137
187
|
return null;
|
|
188
|
+
}
|
|
138
189
|
try {
|
|
139
190
|
const item = JSON.parse(raw);
|
|
140
191
|
// Check expiry if set
|
|
@@ -165,8 +216,9 @@ class StorageManager {
|
|
|
165
216
|
*/
|
|
166
217
|
getJSON(key) {
|
|
167
218
|
const raw = this.get(key);
|
|
168
|
-
if (!raw)
|
|
219
|
+
if (!raw) {
|
|
169
220
|
return null;
|
|
221
|
+
}
|
|
170
222
|
try {
|
|
171
223
|
return JSON.parse(raw);
|
|
172
224
|
}
|
|
@@ -184,8 +236,9 @@ class StorageManager {
|
|
|
184
236
|
// Cookie operations (internal)
|
|
185
237
|
// ============================================================================
|
|
186
238
|
getCookie(name) {
|
|
187
|
-
if (typeof document === "undefined")
|
|
239
|
+
if (typeof document === "undefined") {
|
|
188
240
|
return null;
|
|
241
|
+
}
|
|
189
242
|
const cookies = document.cookie.split(";");
|
|
190
243
|
for (const cookie of cookies) {
|
|
191
244
|
const [key, ...valueParts] = cookie.trim().split("=");
|
|
@@ -202,8 +255,9 @@ class StorageManager {
|
|
|
202
255
|
return null;
|
|
203
256
|
}
|
|
204
257
|
setCookie(name, value, maxAge) {
|
|
205
|
-
if (typeof document === "undefined")
|
|
258
|
+
if (typeof document === "undefined") {
|
|
206
259
|
return;
|
|
260
|
+
}
|
|
207
261
|
let cookieString = `${name}=${encodeURIComponent(value)}`;
|
|
208
262
|
cookieString += `; Max-Age=${maxAge}`;
|
|
209
263
|
cookieString += `; path=/`;
|
|
@@ -211,18 +265,23 @@ class StorageManager {
|
|
|
211
265
|
if (this.secure) {
|
|
212
266
|
cookieString += `; Secure`;
|
|
213
267
|
}
|
|
214
|
-
|
|
215
|
-
|
|
268
|
+
// Auto-detect domain for cross-subdomain cookies
|
|
269
|
+
const domain = getCookieDomain(this.cross_subdomain);
|
|
270
|
+
if (domain) {
|
|
271
|
+
cookieString += `; domain=${domain}`;
|
|
216
272
|
}
|
|
217
273
|
document.cookie = cookieString;
|
|
218
274
|
}
|
|
219
275
|
removeCookie(name) {
|
|
220
|
-
if (typeof document === "undefined")
|
|
276
|
+
if (typeof document === "undefined") {
|
|
221
277
|
return;
|
|
278
|
+
}
|
|
279
|
+
// Auto-detect domain for cross-subdomain cookies
|
|
280
|
+
const domain = getCookieDomain(this.cross_subdomain);
|
|
222
281
|
// Set cookie with expired date
|
|
223
282
|
let cookieString = `${name}=; Max-Age=0; path=/`;
|
|
224
|
-
if (
|
|
225
|
-
cookieString += `; domain=${
|
|
283
|
+
if (domain) {
|
|
284
|
+
cookieString += `; domain=${domain}`;
|
|
226
285
|
}
|
|
227
286
|
document.cookie = cookieString;
|
|
228
287
|
// Also try without domain (in case it was set without)
|
|
@@ -260,8 +319,9 @@ class StorageManager {
|
|
|
260
319
|
*/
|
|
261
320
|
getSessionStorage() {
|
|
262
321
|
var _a;
|
|
263
|
-
if (!this.canUseSessionStorage())
|
|
322
|
+
if (!this.canUseSessionStorage()) {
|
|
264
323
|
return null;
|
|
324
|
+
}
|
|
265
325
|
return (_a = globals_1.window === null || globals_1.window === void 0 ? void 0 : globals_1.window.sessionStorage) !== null && _a !== void 0 ? _a : null;
|
|
266
326
|
}
|
|
267
327
|
/**
|
|
@@ -282,10 +342,10 @@ exports.StorageManager = StorageManager;
|
|
|
282
342
|
* Create a shared storage instance
|
|
283
343
|
* Use this for creating storage managers with consistent settings
|
|
284
344
|
*/
|
|
285
|
-
function createStorageManager(method,
|
|
345
|
+
function createStorageManager(method, cross_subdomain) {
|
|
286
346
|
return new StorageManager({
|
|
287
347
|
method,
|
|
288
|
-
|
|
348
|
+
cross_subdomain,
|
|
289
349
|
sameSite: "Lax",
|
|
290
350
|
});
|
|
291
351
|
}
|
package/lib/types.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export interface VTiltConfig {
|
|
|
20
20
|
name?: string;
|
|
21
21
|
/** Project ID (set via init() first argument) */
|
|
22
22
|
projectId?: string;
|
|
23
|
-
/** Domain to track (auto-detected if not provided) */
|
|
23
|
+
/** Domain to track (auto-detected if not provided) - used in event properties */
|
|
24
24
|
domain?: string;
|
|
25
25
|
/** Storage method for session data */
|
|
26
26
|
storage?: PersistenceMethod;
|
|
@@ -28,7 +28,12 @@ export interface VTiltConfig {
|
|
|
28
28
|
persistence?: PersistenceMethod;
|
|
29
29
|
/** Persistence name prefix */
|
|
30
30
|
persistence_name?: string;
|
|
31
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* Enable cross-subdomain cookies.
|
|
33
|
+
* When true, cookies are shared across subdomains (e.g., app.example.com and www.example.com).
|
|
34
|
+
* Auto-detects false for platforms like herokuapp.com, vercel.app, netlify.app.
|
|
35
|
+
* @default true (except for excluded platforms)
|
|
36
|
+
*/
|
|
32
37
|
cross_subdomain_cookie?: boolean;
|
|
33
38
|
/**
|
|
34
39
|
* Person profiles mode:
|
|
@@ -97,7 +102,6 @@ export interface TrackingEvent {
|
|
|
97
102
|
timestamp: string;
|
|
98
103
|
event: string;
|
|
99
104
|
project_id: string;
|
|
100
|
-
domain: string;
|
|
101
105
|
distinct_id: string;
|
|
102
106
|
anonymous_id?: string;
|
|
103
107
|
payload: EventPayload;
|
package/lib/user-manager.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export declare class UserManager {
|
|
|
15
15
|
private storage;
|
|
16
16
|
private userIdentity;
|
|
17
17
|
private _cachedPersonProperties;
|
|
18
|
-
constructor(storageMethod?: PersistenceMethod,
|
|
18
|
+
constructor(storageMethod?: PersistenceMethod, cross_subdomain?: boolean);
|
|
19
19
|
/**
|
|
20
20
|
* Get current user identity
|
|
21
21
|
*/
|
|
@@ -136,5 +136,5 @@ export declare class UserManager {
|
|
|
136
136
|
/**
|
|
137
137
|
* Update storage method at runtime
|
|
138
138
|
*/
|
|
139
|
-
updateStorageMethod(method: PersistenceMethod,
|
|
139
|
+
updateStorageMethod(method: PersistenceMethod, cross_subdomain?: boolean): void;
|
|
140
140
|
}
|
package/lib/user-manager.js
CHANGED
|
@@ -18,11 +18,11 @@ const utils_1 = require("./utils");
|
|
|
18
18
|
const event_utils_1 = require("./utils/event-utils");
|
|
19
19
|
const storage_1 = require("./storage");
|
|
20
20
|
class UserManager {
|
|
21
|
-
constructor(storageMethod = "localStorage",
|
|
21
|
+
constructor(storageMethod = "localStorage", cross_subdomain) {
|
|
22
22
|
this._cachedPersonProperties = null; // Cache for deduplication
|
|
23
23
|
this.storage = new storage_1.StorageManager({
|
|
24
24
|
method: storageMethod,
|
|
25
|
-
|
|
25
|
+
cross_subdomain,
|
|
26
26
|
sameSite: "Lax",
|
|
27
27
|
});
|
|
28
28
|
this.userIdentity = this.loadUserIdentity();
|
|
@@ -544,10 +544,10 @@ class UserManager {
|
|
|
544
544
|
/**
|
|
545
545
|
* Update storage method at runtime
|
|
546
546
|
*/
|
|
547
|
-
updateStorageMethod(method,
|
|
547
|
+
updateStorageMethod(method, cross_subdomain) {
|
|
548
548
|
this.storage = new storage_1.StorageManager({
|
|
549
549
|
method,
|
|
550
|
-
|
|
550
|
+
cross_subdomain,
|
|
551
551
|
sameSite: "Lax",
|
|
552
552
|
});
|
|
553
553
|
// Reload identity from new storage
|
package/lib/vtilt.js
CHANGED
|
@@ -39,13 +39,8 @@ class VTilt {
|
|
|
39
39
|
this._set_once_properties_sent = false; // Track if $set_once with initial props has been sent (only send once per page load)
|
|
40
40
|
this.configManager = new config_1.ConfigManager(config);
|
|
41
41
|
const fullConfig = this.configManager.getConfig();
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (!domain && globals_1.location) {
|
|
45
|
-
domain = this.getCurrentDomain();
|
|
46
|
-
}
|
|
47
|
-
this.sessionManager = new session_1.SessionManager(fullConfig.storage || "cookie", domain);
|
|
48
|
-
this.userManager = new user_manager_1.UserManager(fullConfig.persistence || "localStorage", domain);
|
|
42
|
+
this.sessionManager = new session_1.SessionManager(fullConfig.storage || "cookie", fullConfig.cross_subdomain_cookie);
|
|
43
|
+
this.userManager = new user_manager_1.UserManager(fullConfig.persistence || "localStorage", fullConfig.cross_subdomain_cookie);
|
|
49
44
|
this.webVitalsManager = new web_vitals_1.WebVitalsManager(fullConfig, this);
|
|
50
45
|
// Initialize rate limiter to prevent flooding
|
|
51
46
|
// Default: 10 events/second with burst of 100
|
|
@@ -453,7 +448,6 @@ class VTilt {
|
|
|
453
448
|
timestamp: new Date().toISOString(),
|
|
454
449
|
event: name,
|
|
455
450
|
project_id: config.projectId || "",
|
|
456
|
-
domain: config.domain || this.getCurrentDomain(), // Use config domain or current domain
|
|
457
451
|
payload: processedPayload,
|
|
458
452
|
distinct_id: distinct_id,
|
|
459
453
|
// Always include anonymous_id in the event for identity linking
|
|
@@ -732,12 +726,8 @@ class VTilt {
|
|
|
732
726
|
this.configManager.updateConfig(config);
|
|
733
727
|
const fullConfig = this.configManager.getConfig();
|
|
734
728
|
// Recreate managers with new config
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
domain = this.getCurrentDomain();
|
|
738
|
-
}
|
|
739
|
-
this.sessionManager = new session_1.SessionManager(fullConfig.storage || "cookie", domain);
|
|
740
|
-
this.userManager = new user_manager_1.UserManager(fullConfig.persistence || "localStorage", domain);
|
|
729
|
+
this.sessionManager = new session_1.SessionManager(fullConfig.storage || "cookie", fullConfig.cross_subdomain_cookie);
|
|
730
|
+
this.userManager = new user_manager_1.UserManager(fullConfig.persistence || "localStorage", fullConfig.cross_subdomain_cookie);
|
|
741
731
|
this.webVitalsManager = new web_vitals_1.WebVitalsManager(fullConfig, this);
|
|
742
732
|
}
|
|
743
733
|
/**
|