@v-tilt/browser 1.0.6 → 1.0.7
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/LICENSE +21 -0
- 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 -0
- package/dist/extensions/history-autocapture.d.ts +19 -0
- package/dist/main.js +1 -1
- package/dist/main.js.map +1 -1
- package/dist/module.d.ts +187 -24
- package/dist/module.js +1 -1
- package/dist/module.js.map +1 -1
- package/dist/module.no-external.d.ts +187 -24
- package/dist/module.no-external.js +1 -1
- package/dist/module.no-external.js.map +1 -1
- package/dist/session.d.ts +61 -4
- package/dist/tracking.d.ts +12 -7
- package/dist/types.d.ts +1 -1
- package/dist/utils/event-utils.d.ts +35 -0
- package/dist/utils/user-agent-utils.d.ts +18 -0
- package/dist/vtilt.d.ts +53 -26
- package/lib/constants.d.ts +2 -0
- package/lib/constants.js +3 -1
- package/lib/extensions/history-autocapture.d.ts +19 -0
- package/lib/extensions/history-autocapture.js +107 -0
- package/lib/session.d.ts +61 -4
- package/lib/session.js +197 -41
- package/lib/tracking.d.ts +12 -7
- package/lib/tracking.js +65 -79
- package/lib/types.d.ts +1 -1
- package/lib/utils/event-utils.d.ts +35 -0
- package/lib/utils/event-utils.js +178 -0
- package/lib/utils/user-agent-utils.d.ts +18 -0
- package/lib/utils/user-agent-utils.js +423 -0
- package/lib/vtilt.d.ts +53 -26
- package/lib/vtilt.js +145 -151
- package/package.json +60 -61
- package/dist/utils.d.ts +0 -21
- package/lib/utils.d.ts +0 -21
- package/lib/utils.js +0 -57
package/lib/vtilt.js
CHANGED
|
@@ -6,15 +6,14 @@ exports.init_from_snippet = init_from_snippet;
|
|
|
6
6
|
const config_1 = require("./config");
|
|
7
7
|
const tracking_1 = require("./tracking");
|
|
8
8
|
const web_vitals_1 = require("./web-vitals");
|
|
9
|
+
const history_autocapture_1 = require("./extensions/history-autocapture");
|
|
9
10
|
const utils_1 = require("./utils");
|
|
10
|
-
const patch_1 = require("./utils/patch");
|
|
11
11
|
const globals_1 = require("./utils/globals");
|
|
12
12
|
// Helper to check if value is an array
|
|
13
13
|
const isArray = Array.isArray;
|
|
14
14
|
class VTilt {
|
|
15
15
|
constructor(config = {}) {
|
|
16
|
-
this.
|
|
17
|
-
this._lastPathname = "";
|
|
16
|
+
this.__loaded = false; // Matches snippet's window.vt.__loaded check
|
|
18
17
|
this._initialPageviewCaptured = false;
|
|
19
18
|
this._visibilityStateListener = null;
|
|
20
19
|
this.configManager = new config_1.ConfigManager(config);
|
|
@@ -22,19 +21,89 @@ class VTilt {
|
|
|
22
21
|
this.webVitalsManager = new web_vitals_1.WebVitalsManager(this.configManager.getConfig(), this.trackingManager);
|
|
23
22
|
}
|
|
24
23
|
/**
|
|
25
|
-
*
|
|
24
|
+
* Initializes a new instance of the VTilt tracking object.
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
* All new instances are added to the main vt object as sub properties (such as
|
|
28
|
+
* `vt.library_name`) and also returned by this function.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```js
|
|
32
|
+
* // basic initialization
|
|
33
|
+
* vt.init('<project_id>', {
|
|
34
|
+
* api_host: '<client_api_host>'
|
|
35
|
+
* })
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```js
|
|
40
|
+
* // multiple instances
|
|
41
|
+
* vt.init('<project_id>', {}, 'project1')
|
|
42
|
+
* vt.init('<project_id>', {}, 'project2')
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @public
|
|
46
|
+
*
|
|
47
|
+
* @param projectId - Your VTilt project ID
|
|
48
|
+
* @param config - A dictionary of config options to override
|
|
49
|
+
* @param name - The name for the new VTilt instance that you want created
|
|
50
|
+
*
|
|
51
|
+
* @returns The newly initialized VTilt instance
|
|
26
52
|
*/
|
|
27
|
-
init() {
|
|
28
|
-
|
|
29
|
-
|
|
53
|
+
init(projectId, config, name) {
|
|
54
|
+
var _a;
|
|
55
|
+
if (!name || name === PRIMARY_INSTANCE_NAME) {
|
|
56
|
+
// This means we are initializing the primary instance (i.e. this)
|
|
57
|
+
return this._init(projectId, config, name);
|
|
30
58
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
59
|
+
else {
|
|
60
|
+
const namedVTilt = (_a = instances[name]) !== null && _a !== void 0 ? _a : new VTilt();
|
|
61
|
+
namedVTilt._init(projectId, config, name);
|
|
62
|
+
instances[name] = namedVTilt;
|
|
63
|
+
// Add as a property to the primary instance (this isn't type-safe but its how it was always done)
|
|
64
|
+
instances[PRIMARY_INSTANCE_NAME][name] = namedVTilt;
|
|
65
|
+
return namedVTilt;
|
|
35
66
|
}
|
|
36
|
-
|
|
37
|
-
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Handles the actual initialization logic for a VTilt instance.
|
|
70
|
+
* This internal method should only be called by `init()`.
|
|
71
|
+
* Follows the PostHog convention of using a private `_init()` method for instance setup.
|
|
72
|
+
*/
|
|
73
|
+
_init(projectId, config = {}, name) {
|
|
74
|
+
// Guard: prevent re-initialization (matches snippet's __loaded check)
|
|
75
|
+
if (this.__loaded) {
|
|
76
|
+
console.warn("vTilt: You have already initialized vTilt! Re-initializing is a no-op");
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
// Update config with projectId, token, and name (PostHog-style)
|
|
80
|
+
this.updateConfig({
|
|
81
|
+
...config,
|
|
82
|
+
projectId: projectId || config.projectId,
|
|
83
|
+
name: name,
|
|
84
|
+
});
|
|
85
|
+
this.__loaded = true;
|
|
86
|
+
// Initialize history autocapture (PostHog-style)
|
|
87
|
+
this.historyAutocapture = new history_autocapture_1.HistoryAutocapture(this);
|
|
88
|
+
this.historyAutocapture.startIfEnabled();
|
|
89
|
+
// Capture initial pageview (with visibility check)
|
|
90
|
+
this._captureInitialPageview();
|
|
91
|
+
return this;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Returns a string representation of the instance name (PostHog-style)
|
|
95
|
+
* Used for debugging and logging
|
|
96
|
+
*
|
|
97
|
+
* @internal
|
|
98
|
+
*/
|
|
99
|
+
toString() {
|
|
100
|
+
var _a;
|
|
101
|
+
const config = this.configManager.getConfig();
|
|
102
|
+
let name = (_a = config.name) !== null && _a !== void 0 ? _a : PRIMARY_INSTANCE_NAME;
|
|
103
|
+
if (name !== PRIMARY_INSTANCE_NAME) {
|
|
104
|
+
name = PRIMARY_INSTANCE_NAME + "." + name;
|
|
105
|
+
}
|
|
106
|
+
return name;
|
|
38
107
|
}
|
|
39
108
|
/**
|
|
40
109
|
* Track a custom event
|
|
@@ -142,51 +211,6 @@ class VTilt {
|
|
|
142
211
|
createAlias(alias, original) {
|
|
143
212
|
this.trackingManager.createAlias(alias, original);
|
|
144
213
|
}
|
|
145
|
-
/**
|
|
146
|
-
* Setup page tracking with history API support
|
|
147
|
-
* Based on PostHog's setupHistoryEventTracking implementation
|
|
148
|
-
*/
|
|
149
|
-
setupPageTracking() {
|
|
150
|
-
var _a, _b;
|
|
151
|
-
// Only setup page tracking in browser environment (not SSR)
|
|
152
|
-
if (!globals_1.window || !globals_1.document || !globals_1.location) {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
// Initialize last pathname
|
|
156
|
-
this._lastPathname = globals_1.location.pathname || "";
|
|
157
|
-
// Capture initial pageview (with visibility check)
|
|
158
|
-
this._captureInitialPageview();
|
|
159
|
-
// Track hash changes
|
|
160
|
-
(0, utils_1.addEventListener)(globals_1.window, "hashchange", () => {
|
|
161
|
-
this._capturePageview("hashchange");
|
|
162
|
-
});
|
|
163
|
-
// Track history API changes using patch (PostHog-style)
|
|
164
|
-
if (globals_1.window.history) {
|
|
165
|
-
// Old fashioned, we could also use arrow functions but I think the closure for a patch is more reliable
|
|
166
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
167
|
-
const self = this;
|
|
168
|
-
// Only patch if not already wrapped
|
|
169
|
-
if (!((_a = globals_1.window.history.pushState) === null || _a === void 0 ? void 0 : _a.__vtilt_wrapped__)) {
|
|
170
|
-
(0, patch_1.patch)(globals_1.window.history, "pushState", (originalPushState) => {
|
|
171
|
-
return function patchedPushState(state, title, url) {
|
|
172
|
-
originalPushState.call(this, state, title, url);
|
|
173
|
-
self._capturePageview("pushState");
|
|
174
|
-
};
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
// Only patch if not already wrapped
|
|
178
|
-
if (!((_b = globals_1.window.history.replaceState) === null || _b === void 0 ? void 0 : _b.__vtilt_wrapped__)) {
|
|
179
|
-
(0, patch_1.patch)(globals_1.window.history, "replaceState", (originalReplaceState) => {
|
|
180
|
-
return function patchedReplaceState(state, title, url) {
|
|
181
|
-
originalReplaceState.call(this, state, title, url);
|
|
182
|
-
self._capturePageview("replaceState");
|
|
183
|
-
};
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
// For popstate we need to listen to the event instead of overriding a method
|
|
187
|
-
this._setupPopstateListener();
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
214
|
/**
|
|
191
215
|
* Capture initial pageview with visibility check
|
|
192
216
|
* Based on PostHog's _captureInitialPageview implementation
|
|
@@ -211,7 +235,19 @@ class VTilt {
|
|
|
211
235
|
// Extra check here to guarantee we only ever trigger a single initial pageview event
|
|
212
236
|
if (!this._initialPageviewCaptured) {
|
|
213
237
|
this._initialPageviewCaptured = true;
|
|
214
|
-
|
|
238
|
+
// Wait a bit for SPA routers (PostHog-style delay)
|
|
239
|
+
setTimeout(() => {
|
|
240
|
+
// Double-check we're still in browser environment (defensive check)
|
|
241
|
+
if (!globals_1.document || !globals_1.location) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
// Note: $current_url, $host, $pathname, $referrer, $referring_domain, title
|
|
245
|
+
// are automatically added by sendEvent() for all events (title only for $pageview)
|
|
246
|
+
const payload = {
|
|
247
|
+
navigation_type: "initial_load",
|
|
248
|
+
};
|
|
249
|
+
this.trackingManager.sendEvent("$pageview", payload);
|
|
250
|
+
}, 300);
|
|
215
251
|
// After we've captured the initial pageview, we can remove the listener
|
|
216
252
|
if (this._visibilityStateListener) {
|
|
217
253
|
globals_1.document.removeEventListener("visibilitychange", this._visibilityStateListener);
|
|
@@ -219,39 +255,6 @@ class VTilt {
|
|
|
219
255
|
}
|
|
220
256
|
}
|
|
221
257
|
}
|
|
222
|
-
/**
|
|
223
|
-
* Capture pageview event for navigation changes
|
|
224
|
-
* Based on PostHog's captureNavigationEvent implementation
|
|
225
|
-
*/
|
|
226
|
-
_capturePageview(navigationType) {
|
|
227
|
-
if (!globals_1.window || !globals_1.location) {
|
|
228
|
-
return;
|
|
229
|
-
}
|
|
230
|
-
const currentPathname = globals_1.location.pathname || "";
|
|
231
|
-
// Only capture pageview if the pathname has changed (or it's the initial load)
|
|
232
|
-
if (navigationType === "initial_load" ||
|
|
233
|
-
currentPathname !== this._lastPathname) {
|
|
234
|
-
this.trackingManager.trackPageHit(navigationType);
|
|
235
|
-
this._lastPathname = currentPathname;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* Setup popstate listener for browser back/forward navigation
|
|
240
|
-
*/
|
|
241
|
-
_setupPopstateListener() {
|
|
242
|
-
if (this._popstateListener || !globals_1.window) {
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
245
|
-
const handler = () => {
|
|
246
|
-
this._capturePageview("popstate");
|
|
247
|
-
};
|
|
248
|
-
(0, utils_1.addEventListener)(globals_1.window, "popstate", handler);
|
|
249
|
-
this._popstateListener = () => {
|
|
250
|
-
if (globals_1.window) {
|
|
251
|
-
globals_1.window.removeEventListener("popstate", handler);
|
|
252
|
-
}
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
258
|
/**
|
|
256
259
|
* Get current configuration
|
|
257
260
|
*/
|
|
@@ -274,11 +277,11 @@ class VTilt {
|
|
|
274
277
|
this.webVitalsManager = new web_vitals_1.WebVitalsManager(this.configManager.getConfig(), this.trackingManager);
|
|
275
278
|
}
|
|
276
279
|
/**
|
|
277
|
-
* _execute_array() deals with processing any
|
|
278
|
-
* calls that were called before the
|
|
280
|
+
* _execute_array() deals with processing any vTilt function
|
|
281
|
+
* calls that were called before the vTilt library was loaded
|
|
279
282
|
* (and are thus stored in an array so they can be called later)
|
|
280
283
|
*
|
|
281
|
-
* Note: we fire off all the
|
|
284
|
+
* Note: we fire off all the vTilt function calls BEFORE we fire off
|
|
282
285
|
* tracking calls. This is so identify/setUserProperties/updateConfig calls
|
|
283
286
|
* can properly modify early tracking calls.
|
|
284
287
|
*
|
|
@@ -297,7 +300,7 @@ class VTilt {
|
|
|
297
300
|
this[methodName](...args);
|
|
298
301
|
}
|
|
299
302
|
catch (error) {
|
|
300
|
-
console.error(`
|
|
303
|
+
console.error(`vTilt: Error executing queued call ${methodName}:`, error);
|
|
301
304
|
}
|
|
302
305
|
}
|
|
303
306
|
}
|
|
@@ -319,7 +322,7 @@ class VTilt {
|
|
|
319
322
|
}
|
|
320
323
|
exports.VTilt = VTilt;
|
|
321
324
|
const instances = {};
|
|
322
|
-
const PRIMARY_INSTANCE_NAME = "
|
|
325
|
+
const PRIMARY_INSTANCE_NAME = "vt";
|
|
323
326
|
// Browser support detection for request queuing
|
|
324
327
|
// IE<10 does not support cross-origin XHR's but script tags
|
|
325
328
|
// with defer won't block window.onload; ENQUEUE_REQUESTS
|
|
@@ -370,15 +373,15 @@ const add_dom_loaded_handler = function () {
|
|
|
370
373
|
return;
|
|
371
374
|
}
|
|
372
375
|
// Only IE6-8 don't support `document.addEventListener` and we don't support them
|
|
373
|
-
// so let's simply log an error stating
|
|
376
|
+
// so let's simply log an error stating vTilt couldn't be initialized
|
|
374
377
|
// We're checking for `window` to avoid erroring out on a SSR context
|
|
375
378
|
if (globals_1.window) {
|
|
376
|
-
console.error("Browser doesn't support `document.addEventListener` so
|
|
379
|
+
console.error("Browser doesn't support `document.addEventListener` so vTilt couldn't be initialized");
|
|
377
380
|
}
|
|
378
381
|
};
|
|
379
382
|
/**
|
|
380
|
-
* Initialize
|
|
381
|
-
* Returns an uninitialized
|
|
383
|
+
* Initialize vTilt as a module (similar to PostHog's init_as_module)
|
|
384
|
+
* Returns an uninitialized vTilt instance that the user must call init() on
|
|
382
385
|
*/
|
|
383
386
|
function init_as_module() {
|
|
384
387
|
const vTiltMain = (instances[PRIMARY_INSTANCE_NAME] = new VTilt());
|
|
@@ -386,7 +389,7 @@ function init_as_module() {
|
|
|
386
389
|
return vTiltMain;
|
|
387
390
|
}
|
|
388
391
|
/**
|
|
389
|
-
* Initialize
|
|
392
|
+
* Initialize vTilt from snippet (similar to PostHog's init_from_snippet)
|
|
390
393
|
* Processes queued calls from the snippet stub and replaces it with real instance
|
|
391
394
|
*
|
|
392
395
|
* The snippet uses some clever tricks to allow deferred loading of array.js (this code)
|
|
@@ -416,58 +419,49 @@ function init_as_module() {
|
|
|
416
419
|
* ]
|
|
417
420
|
*/
|
|
418
421
|
function init_from_snippet() {
|
|
422
|
+
const vTiltMain = (instances[PRIMARY_INSTANCE_NAME] = new VTilt());
|
|
419
423
|
const snippetVT = globals_1.assignableWindow["vt"];
|
|
420
|
-
if (
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
// Add named instance as property to primary instance (for PostHog compatibility)
|
|
459
|
-
if (name !== PRIMARY_INSTANCE_NAME && instances[PRIMARY_INSTANCE_NAME]) {
|
|
460
|
-
instances[PRIMARY_INSTANCE_NAME][name] = instance;
|
|
424
|
+
if (snippetVT) {
|
|
425
|
+
/**
|
|
426
|
+
* The snippet uses some clever tricks to allow deferred loading of array.js (this code)
|
|
427
|
+
*
|
|
428
|
+
* window.vt is an array which the queue of calls made before the lib is loaded
|
|
429
|
+
* It has methods attached to it to simulate the vt object so for instance
|
|
430
|
+
*
|
|
431
|
+
* window.vt.init("projectId", {token: "token", host: "host"})
|
|
432
|
+
* window.vt.trackEvent("my-event", {foo: "bar"})
|
|
433
|
+
*
|
|
434
|
+
* ... will mean that window.vt will look like this:
|
|
435
|
+
* window.vt == [
|
|
436
|
+
* ["trackEvent", "my-event", {foo: "bar"}]
|
|
437
|
+
* ]
|
|
438
|
+
*
|
|
439
|
+
* window.vt._i == [
|
|
440
|
+
* ["projectId", {token: "token", host: "host"}, "vt"]
|
|
441
|
+
* ]
|
|
442
|
+
*
|
|
443
|
+
* If a name is given to the init function then the same as above is true but as a sub-property on the object:
|
|
444
|
+
*
|
|
445
|
+
* window.vt.init("projectId", {token: "token"}, "vt2")
|
|
446
|
+
* window.vt.vt2.trackEvent("my-event", {foo: "bar"})
|
|
447
|
+
*
|
|
448
|
+
* window.vt.vt2 == [
|
|
449
|
+
* ["trackEvent", "my-event", {foo: "bar"}]
|
|
450
|
+
* ]
|
|
451
|
+
*
|
|
452
|
+
*/
|
|
453
|
+
// Call all pre-loaded init calls properly
|
|
454
|
+
(0, utils_1.each)(snippetVT["_i"], function (item) {
|
|
455
|
+
if (item && isArray(item)) {
|
|
456
|
+
const instance = vTiltMain.init(item[0], item[1], item[2]);
|
|
457
|
+
const instanceSnippet = snippetVT[item[2] || "vt"] || snippetVT;
|
|
458
|
+
if (instance) {
|
|
459
|
+
// Execute all queued calls for this instance
|
|
460
|
+
instance._execute_array(instanceSnippet);
|
|
461
|
+
}
|
|
461
462
|
}
|
|
462
|
-
// Get the snippet queue for this instance name
|
|
463
|
-
const instanceSnippet = snippetVT[name] || snippetVT;
|
|
464
|
-
// Execute all queued calls for this instance
|
|
465
|
-
instance._execute_array(instanceSnippet);
|
|
466
463
|
});
|
|
467
464
|
}
|
|
468
|
-
|
|
469
|
-
if (instances[PRIMARY_INSTANCE_NAME] && globals_1.assignableWindow) {
|
|
470
|
-
globals_1.assignableWindow["vt"] = instances[PRIMARY_INSTANCE_NAME];
|
|
471
|
-
}
|
|
465
|
+
globals_1.assignableWindow["vt"] = vTiltMain;
|
|
472
466
|
add_dom_loaded_handler();
|
|
473
467
|
}
|
package/package.json
CHANGED
|
@@ -1,61 +1,60 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@v-tilt/browser",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "vTilt browser tracking library",
|
|
5
|
-
"main": "dist/main.js",
|
|
6
|
-
"module": "dist/module.js",
|
|
7
|
-
"types": "dist/module.d.ts",
|
|
8
|
-
"files": [
|
|
9
|
-
"lib/*",
|
|
10
|
-
"dist/*"
|
|
11
|
-
],
|
|
12
|
-
"publishConfig": {
|
|
13
|
-
"access": "public"
|
|
14
|
-
},
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"@
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
"
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
"
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
"
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@v-tilt/browser",
|
|
3
|
+
"version": "1.0.7",
|
|
4
|
+
"description": "vTilt browser tracking library",
|
|
5
|
+
"main": "dist/main.js",
|
|
6
|
+
"module": "dist/module.js",
|
|
7
|
+
"types": "dist/module.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"lib/*",
|
|
10
|
+
"dist/*"
|
|
11
|
+
],
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"analytics",
|
|
17
|
+
"tracking",
|
|
18
|
+
"web-vitals",
|
|
19
|
+
"performance"
|
|
20
|
+
],
|
|
21
|
+
"author": "vTilt",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@babel/preset-env": "^7.28.3",
|
|
25
|
+
"@rollup/plugin-babel": "^6.0.4",
|
|
26
|
+
"@rollup/plugin-commonjs": "^25.0.8",
|
|
27
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
28
|
+
"@rollup/plugin-node-resolve": "^15.3.1",
|
|
29
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
30
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
|
31
|
+
"@types/node": "^20.10.5",
|
|
32
|
+
"eslint": "^9.0.0",
|
|
33
|
+
"rimraf": "^5.0.5",
|
|
34
|
+
"rollup": "^4.9.1",
|
|
35
|
+
"rollup-plugin-dts": "^6.2.3",
|
|
36
|
+
"rollup-plugin-terser": "^7.0.2",
|
|
37
|
+
"rollup-plugin-visualizer": "^6.0.3",
|
|
38
|
+
"typescript": "^5.3.3",
|
|
39
|
+
"@v-tilt/eslint-config": "1.0.0"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"web-vitals": "^3.5.0"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"web-vitals": "^3.0.0"
|
|
46
|
+
},
|
|
47
|
+
"peerDependenciesMeta": {
|
|
48
|
+
"web-vitals": {
|
|
49
|
+
"optional": true
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"build": "tsc -b && rollup -c",
|
|
54
|
+
"dev": "rollup -c -w",
|
|
55
|
+
"type-check": "tsc --noEmit",
|
|
56
|
+
"lint": "eslint src --ext .ts",
|
|
57
|
+
"lint:fix": "eslint src --ext .ts --fix",
|
|
58
|
+
"clean": "rimraf lib dist"
|
|
59
|
+
}
|
|
60
|
+
}
|
package/dist/utils.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { EventPayload } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* Generate uuid to identify the session. Random, not data-derived
|
|
4
|
-
*/
|
|
5
|
-
export declare function uuidv4(): string;
|
|
6
|
-
/**
|
|
7
|
-
* Validate user agent string
|
|
8
|
-
*/
|
|
9
|
-
export declare function isValidUserAgent(userAgent: string): boolean;
|
|
10
|
-
/**
|
|
11
|
-
* Validate payload string
|
|
12
|
-
*/
|
|
13
|
-
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
|
-
/**
|
|
19
|
-
* Check if current environment is a test environment
|
|
20
|
-
*/
|
|
21
|
-
export declare function isTestEnvironment(): boolean;
|
package/lib/utils.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { EventPayload } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* Generate uuid to identify the session. Random, not data-derived
|
|
4
|
-
*/
|
|
5
|
-
export declare function uuidv4(): string;
|
|
6
|
-
/**
|
|
7
|
-
* Validate user agent string
|
|
8
|
-
*/
|
|
9
|
-
export declare function isValidUserAgent(userAgent: string): boolean;
|
|
10
|
-
/**
|
|
11
|
-
* Validate payload string
|
|
12
|
-
*/
|
|
13
|
-
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
|
-
/**
|
|
19
|
-
* Check if current environment is a test environment
|
|
20
|
-
*/
|
|
21
|
-
export declare function isTestEnvironment(): boolean;
|
package/lib/utils.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.uuidv4 = uuidv4;
|
|
4
|
-
exports.isValidUserAgent = isValidUserAgent;
|
|
5
|
-
exports.isValidPayload = isValidPayload;
|
|
6
|
-
exports.maskSuspiciousAttributes = maskSuspiciousAttributes;
|
|
7
|
-
exports.isTestEnvironment = isTestEnvironment;
|
|
8
|
-
const constants_1 = require("./constants");
|
|
9
|
-
/**
|
|
10
|
-
* Generate uuid to identify the session. Random, not data-derived
|
|
11
|
-
*/
|
|
12
|
-
function uuidv4() {
|
|
13
|
-
return (`${1e7}-${1e3}-${4e3}-${8e3}-${1e11}`).replace(/[018]/g, (c) => (+c ^
|
|
14
|
-
(crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (+c / 4)))).toString(16));
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Validate user agent string
|
|
18
|
-
*/
|
|
19
|
-
function isValidUserAgent(userAgent) {
|
|
20
|
-
// empty is fine
|
|
21
|
-
if (!userAgent || typeof userAgent !== 'string') {
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
if (userAgent.length > 500) {
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Validate payload string
|
|
31
|
-
*/
|
|
32
|
-
function isValidPayload(payloadStr) {
|
|
33
|
-
if (!payloadStr || typeof payloadStr !== 'string') {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
if (payloadStr.length < 2 || payloadStr.length > 10240) {
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Try to mask PPI and potential sensible attributes
|
|
43
|
-
*/
|
|
44
|
-
function maskSuspiciousAttributes(payload) {
|
|
45
|
-
// Deep copy
|
|
46
|
-
let _payload = JSON.stringify(payload);
|
|
47
|
-
constants_1.ATTRIBUTES_TO_MASK.forEach((attr) => {
|
|
48
|
-
_payload = _payload.replace(new RegExp(`("${attr}"):(".+?"|\\d+)`, 'gmi'), '$1:"********"');
|
|
49
|
-
});
|
|
50
|
-
return _payload;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Check if current environment is a test environment
|
|
54
|
-
*/
|
|
55
|
-
function isTestEnvironment() {
|
|
56
|
-
return !!(('__nightmare' in window) || window.navigator.webdriver || ('Cypress' in window));
|
|
57
|
-
}
|