@v-tilt/browser 1.0.1
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 +2 -0
- package/dist/array.js.map +1 -0
- package/dist/array.no-external.js +2 -0
- package/dist/array.no-external.js.map +1 -0
- package/dist/config.d.ts +17 -0
- package/dist/constants.d.ts +10 -0
- package/dist/entrypoints/array.d.ts +1 -0
- package/dist/entrypoints/array.no-external.d.ts +1 -0
- package/dist/entrypoints/main.cjs.d.ts +4 -0
- package/dist/entrypoints/module.es.d.ts +3 -0
- package/dist/entrypoints/module.no-external.es.d.ts +4 -0
- package/dist/geolocation.d.ts +5 -0
- package/dist/main.js +2 -0
- package/dist/main.js.map +1 -0
- package/dist/module.d.ts +214 -0
- package/dist/module.js +2 -0
- package/dist/module.js.map +1 -0
- package/dist/module.no-external.d.ts +214 -0
- package/dist/module.no-external.js +2 -0
- package/dist/module.no-external.js.map +1 -0
- package/dist/session.d.ts +26 -0
- package/dist/tracking.d.ts +112 -0
- package/dist/types.d.ts +67 -0
- package/dist/user-manager.d.ts +152 -0
- package/dist/utils/globals.d.ts +4 -0
- package/dist/utils/index.d.ts +30 -0
- package/dist/utils.d.ts +21 -0
- package/dist/vtilt.d.ts +178 -0
- package/dist/web-vitals.d.ts +11 -0
- package/lib/config.d.ts +17 -0
- package/lib/config.js +76 -0
- package/lib/constants.d.ts +10 -0
- package/lib/constants.js +463 -0
- package/lib/entrypoints/array.d.ts +1 -0
- package/lib/entrypoints/array.js +3 -0
- package/lib/entrypoints/array.no-external.d.ts +1 -0
- package/lib/entrypoints/array.no-external.js +4 -0
- package/lib/entrypoints/main.cjs.d.ts +4 -0
- package/lib/entrypoints/main.cjs.js +29 -0
- package/lib/entrypoints/module.es.d.ts +3 -0
- package/lib/entrypoints/module.es.js +22 -0
- package/lib/entrypoints/module.no-external.es.d.ts +4 -0
- package/lib/entrypoints/module.no-external.es.js +23 -0
- package/lib/geolocation.d.ts +5 -0
- package/lib/geolocation.js +26 -0
- package/lib/session.d.ts +26 -0
- package/lib/session.js +115 -0
- package/lib/tracking.d.ts +112 -0
- package/lib/tracking.js +326 -0
- package/lib/types.d.ts +67 -0
- package/lib/types.js +2 -0
- package/lib/user-manager.d.ts +152 -0
- package/lib/user-manager.js +565 -0
- package/lib/utils/globals.d.ts +4 -0
- package/lib/utils/globals.js +5 -0
- package/lib/utils/index.d.ts +30 -0
- package/lib/utils/index.js +89 -0
- package/lib/utils.d.ts +21 -0
- package/lib/utils.js +57 -0
- package/lib/vtilt.d.ts +178 -0
- package/lib/vtilt.js +403 -0
- package/lib/web-vitals.d.ts +11 -0
- package/lib/web-vitals.js +67 -0
- package/package.json +61 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebVitalsManager = void 0;
|
|
4
|
+
const geolocation_1 = require("./geolocation");
|
|
5
|
+
class WebVitalsManager {
|
|
6
|
+
constructor(config, trackingManager) {
|
|
7
|
+
this.trackingManager = trackingManager;
|
|
8
|
+
// Load web-vitals if enabled
|
|
9
|
+
if (config.webVitals) {
|
|
10
|
+
try {
|
|
11
|
+
// Dynamically require web-vitals, ignore type error since it's a runtime import
|
|
12
|
+
// eslint-disable-next-line
|
|
13
|
+
this.webVitals = require("web-vitals");
|
|
14
|
+
this.initializeWebVitals();
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
console.warn("web-vitals library not found. Please install it to enable web vitals tracking.", error);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Initialize web vitals tracking
|
|
23
|
+
*/
|
|
24
|
+
initializeWebVitals() {
|
|
25
|
+
if (!this.webVitals) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const sendMetric = (metric) => {
|
|
29
|
+
try {
|
|
30
|
+
const { country, locale } = (0, geolocation_1.getCountryAndLocale)();
|
|
31
|
+
this.trackingManager.sendEvent("web_vital", {
|
|
32
|
+
name: metric.name,
|
|
33
|
+
value: metric.value,
|
|
34
|
+
delta: metric.delta,
|
|
35
|
+
rating: metric.rating,
|
|
36
|
+
id: metric.id,
|
|
37
|
+
navigationType: metric.navigationType,
|
|
38
|
+
pathname: window.location.pathname,
|
|
39
|
+
href: window.location.href,
|
|
40
|
+
"user-agent": window.navigator.userAgent,
|
|
41
|
+
locale,
|
|
42
|
+
location: country,
|
|
43
|
+
referrer: document.referrer,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
console.error("Error sending web vital:", error);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
if (this.webVitals.onCLS) {
|
|
51
|
+
this.webVitals.onCLS(sendMetric);
|
|
52
|
+
}
|
|
53
|
+
if (this.webVitals.onFCP) {
|
|
54
|
+
this.webVitals.onFCP(sendMetric);
|
|
55
|
+
}
|
|
56
|
+
if (this.webVitals.onLCP) {
|
|
57
|
+
this.webVitals.onLCP(sendMetric);
|
|
58
|
+
}
|
|
59
|
+
if (this.webVitals.onTTFB) {
|
|
60
|
+
this.webVitals.onTTFB(sendMetric);
|
|
61
|
+
}
|
|
62
|
+
if (this.webVitals.onINP) {
|
|
63
|
+
this.webVitals.onINP(sendMetric);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.WebVitalsManager = WebVitalsManager;
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@v-tilt/browser",
|
|
3
|
+
"version": "1.0.1",
|
|
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
|
+
"scripts": {
|
|
16
|
+
"build": "tsc -b && rollup -c",
|
|
17
|
+
"dev": "rollup -c -w",
|
|
18
|
+
"type-check": "tsc --noEmit",
|
|
19
|
+
"lint": "eslint src --ext .ts",
|
|
20
|
+
"lint:fix": "eslint src --ext .ts --fix",
|
|
21
|
+
"clean": "rimraf lib dist",
|
|
22
|
+
"prepublishOnly": "pnpm run build"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"analytics",
|
|
26
|
+
"tracking",
|
|
27
|
+
"web-vitals",
|
|
28
|
+
"performance"
|
|
29
|
+
],
|
|
30
|
+
"author": "vTilt",
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@babel/preset-env": "^7.28.3",
|
|
34
|
+
"@rollup/plugin-babel": "^6.0.4",
|
|
35
|
+
"@rollup/plugin-commonjs": "^25.0.8",
|
|
36
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
37
|
+
"@rollup/plugin-node-resolve": "^15.3.1",
|
|
38
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
39
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
|
40
|
+
"@types/node": "^20.10.5",
|
|
41
|
+
"@v-tilt/eslint-config": "workspace:*",
|
|
42
|
+
"eslint": "^9.0.0",
|
|
43
|
+
"rimraf": "^5.0.5",
|
|
44
|
+
"rollup": "^4.9.1",
|
|
45
|
+
"rollup-plugin-dts": "^6.2.3",
|
|
46
|
+
"rollup-plugin-terser": "^7.0.2",
|
|
47
|
+
"rollup-plugin-visualizer": "^6.0.3",
|
|
48
|
+
"typescript": "^5.3.3"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"web-vitals": "^3.5.0"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"web-vitals": "^3.0.0"
|
|
55
|
+
},
|
|
56
|
+
"peerDependenciesMeta": {
|
|
57
|
+
"web-vitals": {
|
|
58
|
+
"optional": true
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|