@v-tilt/browser 1.0.9 → 1.0.11
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 +1 -0
- package/dist/main.js +1 -1
- package/dist/main.js.map +1 -1
- package/dist/module.d.ts +3 -2
- package/dist/module.js +1 -1
- package/dist/module.js.map +1 -1
- package/dist/module.no-external.d.ts +3 -2
- package/dist/module.no-external.js +1 -1
- package/dist/module.no-external.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/user-manager.d.ts +21 -0
- package/dist/utils/event-utils.d.ts +35 -17
- package/dist/utils/index.d.ts +21 -0
- package/dist/utils/request-utils.d.ts +17 -0
- package/dist/vtilt.d.ts +2 -1
- package/lib/constants.d.ts +1 -0
- package/lib/constants.js +2 -1
- package/lib/types.d.ts +1 -1
- package/lib/user-manager.d.ts +21 -0
- package/lib/user-manager.js +66 -2
- package/lib/utils/event-utils.d.ts +35 -17
- package/lib/utils/event-utils.js +245 -122
- package/lib/utils/index.d.ts +21 -0
- package/lib/utils/index.js +58 -0
- package/lib/utils/request-utils.d.ts +17 -0
- package/lib/utils/request-utils.js +78 -0
- package/lib/vtilt.d.ts +2 -1
- package/lib/vtilt.js +29 -8
- package/package.json +1 -1
package/lib/vtilt.js
CHANGED
|
@@ -10,7 +10,6 @@ const web_vitals_1 = require("./web-vitals");
|
|
|
10
10
|
const history_autocapture_1 = require("./extensions/history-autocapture");
|
|
11
11
|
const utils_1 = require("./utils");
|
|
12
12
|
const event_utils_1 = require("./utils/event-utils");
|
|
13
|
-
const utils_2 = require("./utils");
|
|
14
13
|
const globals_1 = require("./utils/globals");
|
|
15
14
|
// Helper to check if value is an array
|
|
16
15
|
const isArray = Array.isArray;
|
|
@@ -94,6 +93,9 @@ class VTilt {
|
|
|
94
93
|
name: name,
|
|
95
94
|
});
|
|
96
95
|
this.__loaded = true;
|
|
96
|
+
// Set initial person info: stores referrer and URL on first visit
|
|
97
|
+
const fullConfig = this.configManager.getConfig();
|
|
98
|
+
this.userManager.set_initial_person_info(fullConfig.mask_personal_data_properties, fullConfig.custom_personal_data_properties);
|
|
97
99
|
// Initialize history autocapture
|
|
98
100
|
this.historyAutocapture = new history_autocapture_1.HistoryAutocapture(this);
|
|
99
101
|
this.historyAutocapture.startIfEnabled();
|
|
@@ -205,7 +207,8 @@ class VTilt {
|
|
|
205
207
|
/**
|
|
206
208
|
* Capture an event
|
|
207
209
|
* Automatically adds common properties to all events
|
|
208
|
-
* ($current_url, $host, $pathname, $referrer, $referring_domain, $
|
|
210
|
+
* ($current_url, $host, $pathname, $referrer, $referring_domain, $browser, $os, $device, $timezone, etc.)
|
|
211
|
+
* Only properties in EVENT_TO_PERSON_PROPERTIES are copied to person properties
|
|
209
212
|
* Also adds title property for $pageview events only
|
|
210
213
|
*
|
|
211
214
|
* @param name - Event name
|
|
@@ -222,11 +225,14 @@ class VTilt {
|
|
|
222
225
|
}
|
|
223
226
|
const url = this.buildUrl();
|
|
224
227
|
// Add properties to all events
|
|
225
|
-
// This includes: $current_url, $host, $pathname, $referrer, $referring_domain, $
|
|
228
|
+
// This includes: $current_url, $host, $pathname, $referrer, $referring_domain, $browser, $os, $device, $timezone, etc.
|
|
229
|
+
// (Only properties in EVENT_TO_PERSON_PROPERTIES are copied to person properties)
|
|
226
230
|
const eventProperties = (0, event_utils_1.getEventProperties)();
|
|
227
231
|
// Get person properties (includes $device_id and other user properties)
|
|
228
232
|
// These are automatically included in all events
|
|
229
233
|
const personProperties = this.userManager.getUserProperties();
|
|
234
|
+
// Get initial props: $initial_* properties from stored initial person info
|
|
235
|
+
const initialProps = this.userManager.get_initial_props();
|
|
230
236
|
// Get session and window IDs
|
|
231
237
|
// Both methods ensure IDs always exist (generate if needed)
|
|
232
238
|
const session_id = this.sessionManager.getSessionId();
|
|
@@ -235,6 +241,17 @@ class VTilt {
|
|
|
235
241
|
// This allows linking events with different distinct_ids that share the same anonymous_id
|
|
236
242
|
// This is especially important for handling race conditions when $identify events arrive
|
|
237
243
|
const anonymousId = this.userManager.getAnonymousId();
|
|
244
|
+
// Build $set and $set_once from initial props
|
|
245
|
+
// Initial props are added to $set_once (only first time, preserves first values)
|
|
246
|
+
// Regular event properties that match EVENT_TO_PERSON_PROPERTIES will be added to $set by server
|
|
247
|
+
const setOnce = {};
|
|
248
|
+
if (Object.keys(initialProps).length > 0) {
|
|
249
|
+
Object.assign(setOnce, initialProps);
|
|
250
|
+
}
|
|
251
|
+
// Merge with user-provided $set_once if present
|
|
252
|
+
if (payload.$set_once) {
|
|
253
|
+
Object.assign(setOnce, payload.$set_once);
|
|
254
|
+
}
|
|
238
255
|
const enrichedPayload = {
|
|
239
256
|
...eventProperties, // Base properties for all events
|
|
240
257
|
...personProperties, // Person properties (includes $device_id)
|
|
@@ -243,6 +260,10 @@ class VTilt {
|
|
|
243
260
|
// Always include $anon_distinct_id for identity linking (even for identified users)
|
|
244
261
|
// This allows the server to merge identities proactively when events arrive out of order
|
|
245
262
|
...(anonymousId ? { $anon_distinct_id: anonymousId } : {}),
|
|
263
|
+
// Add $set_once with initial props
|
|
264
|
+
...(Object.keys(setOnce).length > 0 ? { $set_once: setOnce } : {}),
|
|
265
|
+
// Merge user-provided $set if present
|
|
266
|
+
...(payload.$set ? { $set: payload.$set } : {}),
|
|
246
267
|
...payload, // User-provided payload (can override base and person properties)
|
|
247
268
|
};
|
|
248
269
|
// Add title only to $pageview events
|
|
@@ -282,7 +303,7 @@ class VTilt {
|
|
|
282
303
|
const trackingEvent = {
|
|
283
304
|
timestamp: new Date().toISOString(),
|
|
284
305
|
event: name,
|
|
285
|
-
|
|
306
|
+
project_id: config.projectId || "",
|
|
286
307
|
domain: config.domain || this.getCurrentDomain(), // Use config domain or current domain
|
|
287
308
|
payload: processedPayload,
|
|
288
309
|
distinct_id: distinct_id,
|
|
@@ -508,7 +529,7 @@ class VTilt {
|
|
|
508
529
|
this._visibilityStateListener = () => {
|
|
509
530
|
this._captureInitialPageview();
|
|
510
531
|
};
|
|
511
|
-
(0,
|
|
532
|
+
(0, utils_1.addEventListener)(globals_1.document, "visibilitychange", this._visibilityStateListener);
|
|
512
533
|
}
|
|
513
534
|
return;
|
|
514
535
|
}
|
|
@@ -636,7 +657,7 @@ const add_dom_loaded_handler = function () {
|
|
|
636
657
|
globals_1.window.__VTILT_ENQUEUE_REQUESTS = false;
|
|
637
658
|
}
|
|
638
659
|
// Process queued requests for all instances
|
|
639
|
-
(0,
|
|
660
|
+
(0, utils_1.each)(instances, function (inst) {
|
|
640
661
|
inst._dom_loaded();
|
|
641
662
|
});
|
|
642
663
|
}
|
|
@@ -649,7 +670,7 @@ const add_dom_loaded_handler = function () {
|
|
|
649
670
|
dom_loaded_handler();
|
|
650
671
|
}
|
|
651
672
|
else {
|
|
652
|
-
(0,
|
|
673
|
+
(0, utils_1.addEventListener)(globals_1.document, "DOMContentLoaded", dom_loaded_handler, {
|
|
653
674
|
capture: false,
|
|
654
675
|
});
|
|
655
676
|
}
|
|
@@ -734,7 +755,7 @@ function init_from_snippet() {
|
|
|
734
755
|
*
|
|
735
756
|
*/
|
|
736
757
|
// Call all pre-loaded init calls properly
|
|
737
|
-
(0,
|
|
758
|
+
(0, utils_1.each)(snippetVT["_i"], function (item) {
|
|
738
759
|
if (item && isArray(item)) {
|
|
739
760
|
const instance = vTiltMain.init(item[0], item[1], item[2]);
|
|
740
761
|
const instanceSnippet = snippetVT[item[2] || "vt"] || snippetVT;
|