@vercel/analytics 0.1.9-beta.4 → 0.1.10
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/index.cjs +11 -74
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -9
- package/dist/index.js +10 -72
- package/dist/index.js.map +1 -1
- package/dist/react/index.cjs +12 -74
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.ts +2 -11
- package/dist/react/index.js +12 -72
- package/dist/react/index.js.map +1 -1
- package/package.json +8 -6
- package/tsup.config.js +6 -0
package/dist/index.cjs
CHANGED
|
@@ -20,9 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/generic.ts
|
|
21
21
|
var generic_exports = {};
|
|
22
22
|
__export(generic_exports, {
|
|
23
|
-
|
|
24
|
-
inject: () => inject,
|
|
25
|
-
track: () => track
|
|
23
|
+
inject: () => inject
|
|
26
24
|
});
|
|
27
25
|
module.exports = __toCommonJS(generic_exports);
|
|
28
26
|
|
|
@@ -39,50 +37,16 @@ var initQueue = () => {
|
|
|
39
37
|
function isBrowser() {
|
|
40
38
|
return typeof window !== "undefined";
|
|
41
39
|
}
|
|
42
|
-
function
|
|
40
|
+
function isDevelopment() {
|
|
43
41
|
if (typeof process === "undefined")
|
|
44
|
-
return
|
|
45
|
-
|
|
46
|
-
return "development";
|
|
47
|
-
return "production";
|
|
42
|
+
return false;
|
|
43
|
+
return process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
|
|
48
44
|
}
|
|
49
|
-
function
|
|
45
|
+
function getMode(mode = "auto") {
|
|
50
46
|
if (mode === "auto") {
|
|
51
|
-
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
window.vam = mode;
|
|
55
|
-
}
|
|
56
|
-
function getMode() {
|
|
57
|
-
return window.vam || "production";
|
|
58
|
-
}
|
|
59
|
-
function isProduction() {
|
|
60
|
-
return getMode() === "production";
|
|
61
|
-
}
|
|
62
|
-
function isDevelopment() {
|
|
63
|
-
return getMode() === "development";
|
|
64
|
-
}
|
|
65
|
-
var removeKey = (key, { [key]: _, ...rest }) => rest;
|
|
66
|
-
function parseProperties(properties, options) {
|
|
67
|
-
let props = properties;
|
|
68
|
-
const errorProperties = [];
|
|
69
|
-
for (const [key, value] of Object.entries(properties)) {
|
|
70
|
-
if (typeof value === "object" && value !== null) {
|
|
71
|
-
if (options.strip) {
|
|
72
|
-
props = removeKey(key, props);
|
|
73
|
-
} else {
|
|
74
|
-
errorProperties.push(key);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
47
|
+
return isDevelopment() ? "development" : "production";
|
|
77
48
|
}
|
|
78
|
-
|
|
79
|
-
throw Error(
|
|
80
|
-
`The following properties are not valid: ${errorProperties.join(
|
|
81
|
-
", "
|
|
82
|
-
)}. Only strings, numbers, booleans, and null are allowed.`
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
return props;
|
|
49
|
+
return mode;
|
|
86
50
|
}
|
|
87
51
|
|
|
88
52
|
// src/generic.ts
|
|
@@ -92,51 +56,24 @@ var inject = (props = {
|
|
|
92
56
|
var _a;
|
|
93
57
|
if (!isBrowser())
|
|
94
58
|
return;
|
|
95
|
-
|
|
59
|
+
const mode = getMode(props.mode);
|
|
96
60
|
initQueue();
|
|
97
61
|
if (props.beforeSend) {
|
|
98
62
|
(_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", props.beforeSend);
|
|
99
63
|
}
|
|
100
|
-
const src =
|
|
64
|
+
const src = mode === "development" ? "https://cdn.vercel-insights.com/v1/script.debug.js" : "/_vercel/insights/script.js";
|
|
101
65
|
if (document.head.querySelector(`script[src*="${src}"]`))
|
|
102
66
|
return;
|
|
103
67
|
const script = document.createElement("script");
|
|
104
68
|
script.src = src;
|
|
105
69
|
script.defer = true;
|
|
106
|
-
if (
|
|
70
|
+
if (mode === "development" && props.debug === false) {
|
|
107
71
|
script.setAttribute("data-debug", "false");
|
|
108
72
|
}
|
|
109
73
|
document.head.appendChild(script);
|
|
110
74
|
};
|
|
111
|
-
var track = (name, properties) => {
|
|
112
|
-
var _a, _b;
|
|
113
|
-
if (!isBrowser())
|
|
114
|
-
return;
|
|
115
|
-
if (!properties) {
|
|
116
|
-
(_a = window.va) == null ? void 0 : _a.call(window, "event", { name });
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
try {
|
|
120
|
-
const props = parseProperties(properties, {
|
|
121
|
-
strip: isProduction()
|
|
122
|
-
});
|
|
123
|
-
(_b = window.va) == null ? void 0 : _b.call(window, "event", {
|
|
124
|
-
name,
|
|
125
|
-
data: props
|
|
126
|
-
});
|
|
127
|
-
} catch (err) {
|
|
128
|
-
if (err instanceof Error && isDevelopment()) {
|
|
129
|
-
console.error(err);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
var generic_default = {
|
|
134
|
-
inject,
|
|
135
|
-
track
|
|
136
|
-
};
|
|
137
75
|
// Annotate the CommonJS export names for ESM import in node:
|
|
138
76
|
0 && (module.exports = {
|
|
139
|
-
inject
|
|
140
|
-
track
|
|
77
|
+
inject
|
|
141
78
|
});
|
|
142
79
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/generic.ts","../src/queue.ts","../src/utils.ts"],"sourcesContent":["import { initQueue } from './queue';\nimport type {
|
|
1
|
+
{"version":3,"sources":["../src/generic.ts","../src/queue.ts","../src/utils.ts"],"sourcesContent":["import { initQueue } from './queue';\nimport type { AnalyticsProps } from './types';\nimport { isBrowser, getMode } from './utils';\n\nexport const inject = (\n props: AnalyticsProps = {\n debug: true,\n },\n): void => {\n if (!isBrowser()) return;\n\n const mode = getMode(props.mode);\n\n initQueue();\n\n if (props.beforeSend) {\n window.va?.('beforeSend', props.beforeSend);\n }\n\n const src =\n mode === 'development'\n ? 'https://cdn.vercel-insights.com/v1/script.debug.js'\n : '/_vercel/insights/script.js';\n\n if (document.head.querySelector(`script[src*=\"${src}\"]`)) return;\n\n const script = document.createElement('script');\n script.src = src;\n script.defer = true;\n\n if (mode === 'development' && props.debug === false) {\n script.setAttribute('data-debug', 'false');\n }\n\n document.head.appendChild(script);\n};\n","export const initQueue = (): void => {\n // initialize va until script is loaded\n if (window.va) return;\n\n window.va = function a(...params): void {\n (window.vaq = window.vaq || []).push(params);\n };\n};\n","import type { Mode } from './types';\n\nexport function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nexport function isDevelopment(): boolean {\n if (typeof process === 'undefined') return false;\n return (\n process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test'\n );\n}\n\nexport function getMode(mode: Mode = 'auto'): Mode {\n if (mode === 'auto') {\n return isDevelopment() ? 'development' : 'production';\n }\n\n return mode;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO;AAAI;AAEf,SAAO,KAAK,SAAS,KAAK,QAAc;AACtC,KAAC,OAAO,MAAM,OAAO,OAAO,CAAC,GAAG,KAAK,MAAM;AAAA,EAC7C;AACF;;;ACLO,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;AAEO,SAAS,gBAAyB;AACvC,MAAI,OAAO,YAAY;AAAa,WAAO;AAC3C,SACE,QAAQ,IAAI,aAAa,iBAAiB,QAAQ,IAAI,aAAa;AAEvE;AAEO,SAAS,QAAQ,OAAa,QAAc;AACjD,MAAI,SAAS,QAAQ;AACnB,WAAO,cAAc,IAAI,gBAAgB;AAAA,EAC3C;AAEA,SAAO;AACT;;;AFfO,IAAM,SAAS,CACpB,QAAwB;AAAA,EACtB,OAAO;AACT,MACS;AARX;AASE,MAAI,CAAC,UAAU;AAAG;AAElB,QAAM,OAAO,QAAQ,MAAM,IAAI;AAE/B,YAAU;AAEV,MAAI,MAAM,YAAY;AACpB,iBAAO,OAAP,gCAAY,cAAc,MAAM;AAAA,EAClC;AAEA,QAAM,MACJ,SAAS,gBACL,uDACA;AAEN,MAAI,SAAS,KAAK,cAAc,gBAAgB,OAAO;AAAG;AAE1D,QAAM,SAAS,SAAS,cAAc,QAAQ;AAC9C,SAAO,MAAM;AACb,SAAO,QAAQ;AAEf,MAAI,SAAS,iBAAiB,MAAM,UAAU,OAAO;AACnD,WAAO,aAAa,cAAc,OAAO;AAAA,EAC3C;AAEA,WAAS,KAAK,YAAY,MAAM;AAClC;","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,6 @@ interface PageViewEvent {
|
|
|
4
4
|
}
|
|
5
5
|
declare type Event = PageViewEvent;
|
|
6
6
|
declare type Mode = 'auto' | 'development' | 'production';
|
|
7
|
-
declare type AllowedPropertyValues = string | number | boolean | null;
|
|
8
7
|
declare type BeforeSend = (event: Event) => Event | null;
|
|
9
8
|
interface AnalyticsProps {
|
|
10
9
|
beforeSend?: BeforeSend;
|
|
@@ -13,18 +12,12 @@ interface AnalyticsProps {
|
|
|
13
12
|
}
|
|
14
13
|
declare global {
|
|
15
14
|
interface Window {
|
|
16
|
-
va?: (event:
|
|
15
|
+
va?: (event: string, properties?: unknown) => void;
|
|
17
16
|
vaq?: [string, unknown?][];
|
|
18
17
|
vai?: boolean;
|
|
19
|
-
vam?: Mode;
|
|
20
18
|
}
|
|
21
19
|
}
|
|
22
20
|
|
|
23
21
|
declare const inject: (props?: AnalyticsProps) => void;
|
|
24
|
-
declare const track: (name: string, properties?: Record<string, AllowedPropertyValues>) => void;
|
|
25
|
-
declare const _default: {
|
|
26
|
-
inject: (props?: AnalyticsProps) => void;
|
|
27
|
-
track: (name: string, properties?: Record<string, AllowedPropertyValues> | undefined) => void;
|
|
28
|
-
};
|
|
29
22
|
|
|
30
|
-
export {
|
|
23
|
+
export { inject };
|
package/dist/index.js
CHANGED
|
@@ -11,50 +11,16 @@ var initQueue = () => {
|
|
|
11
11
|
function isBrowser() {
|
|
12
12
|
return typeof window !== "undefined";
|
|
13
13
|
}
|
|
14
|
-
function
|
|
14
|
+
function isDevelopment() {
|
|
15
15
|
if (typeof process === "undefined")
|
|
16
|
-
return
|
|
17
|
-
|
|
18
|
-
return "development";
|
|
19
|
-
return "production";
|
|
16
|
+
return false;
|
|
17
|
+
return process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
|
|
20
18
|
}
|
|
21
|
-
function
|
|
19
|
+
function getMode(mode = "auto") {
|
|
22
20
|
if (mode === "auto") {
|
|
23
|
-
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
window.vam = mode;
|
|
27
|
-
}
|
|
28
|
-
function getMode() {
|
|
29
|
-
return window.vam || "production";
|
|
30
|
-
}
|
|
31
|
-
function isProduction() {
|
|
32
|
-
return getMode() === "production";
|
|
33
|
-
}
|
|
34
|
-
function isDevelopment() {
|
|
35
|
-
return getMode() === "development";
|
|
36
|
-
}
|
|
37
|
-
var removeKey = (key, { [key]: _, ...rest }) => rest;
|
|
38
|
-
function parseProperties(properties, options) {
|
|
39
|
-
let props = properties;
|
|
40
|
-
const errorProperties = [];
|
|
41
|
-
for (const [key, value] of Object.entries(properties)) {
|
|
42
|
-
if (typeof value === "object" && value !== null) {
|
|
43
|
-
if (options.strip) {
|
|
44
|
-
props = removeKey(key, props);
|
|
45
|
-
} else {
|
|
46
|
-
errorProperties.push(key);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
21
|
+
return isDevelopment() ? "development" : "production";
|
|
49
22
|
}
|
|
50
|
-
|
|
51
|
-
throw Error(
|
|
52
|
-
`The following properties are not valid: ${errorProperties.join(
|
|
53
|
-
", "
|
|
54
|
-
)}. Only strings, numbers, booleans, and null are allowed.`
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
return props;
|
|
23
|
+
return mode;
|
|
58
24
|
}
|
|
59
25
|
|
|
60
26
|
// src/generic.ts
|
|
@@ -64,51 +30,23 @@ var inject = (props = {
|
|
|
64
30
|
var _a;
|
|
65
31
|
if (!isBrowser())
|
|
66
32
|
return;
|
|
67
|
-
|
|
33
|
+
const mode = getMode(props.mode);
|
|
68
34
|
initQueue();
|
|
69
35
|
if (props.beforeSend) {
|
|
70
36
|
(_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", props.beforeSend);
|
|
71
37
|
}
|
|
72
|
-
const src =
|
|
38
|
+
const src = mode === "development" ? "https://cdn.vercel-insights.com/v1/script.debug.js" : "/_vercel/insights/script.js";
|
|
73
39
|
if (document.head.querySelector(`script[src*="${src}"]`))
|
|
74
40
|
return;
|
|
75
41
|
const script = document.createElement("script");
|
|
76
42
|
script.src = src;
|
|
77
43
|
script.defer = true;
|
|
78
|
-
if (
|
|
44
|
+
if (mode === "development" && props.debug === false) {
|
|
79
45
|
script.setAttribute("data-debug", "false");
|
|
80
46
|
}
|
|
81
47
|
document.head.appendChild(script);
|
|
82
48
|
};
|
|
83
|
-
var track = (name, properties) => {
|
|
84
|
-
var _a, _b;
|
|
85
|
-
if (!isBrowser())
|
|
86
|
-
return;
|
|
87
|
-
if (!properties) {
|
|
88
|
-
(_a = window.va) == null ? void 0 : _a.call(window, "event", { name });
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
try {
|
|
92
|
-
const props = parseProperties(properties, {
|
|
93
|
-
strip: isProduction()
|
|
94
|
-
});
|
|
95
|
-
(_b = window.va) == null ? void 0 : _b.call(window, "event", {
|
|
96
|
-
name,
|
|
97
|
-
data: props
|
|
98
|
-
});
|
|
99
|
-
} catch (err) {
|
|
100
|
-
if (err instanceof Error && isDevelopment()) {
|
|
101
|
-
console.error(err);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
var generic_default = {
|
|
106
|
-
inject,
|
|
107
|
-
track
|
|
108
|
-
};
|
|
109
49
|
export {
|
|
110
|
-
|
|
111
|
-
inject,
|
|
112
|
-
track
|
|
50
|
+
inject
|
|
113
51
|
};
|
|
114
52
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/queue.ts","../src/utils.ts","../src/generic.ts"],"sourcesContent":["export const initQueue = (): void => {\n // initialize va until script is loaded\n if (window.va) return;\n\n window.va = function a(...params): void {\n (window.vaq = window.vaq || []).push(params);\n };\n};\n","import type {
|
|
1
|
+
{"version":3,"sources":["../src/queue.ts","../src/utils.ts","../src/generic.ts"],"sourcesContent":["export const initQueue = (): void => {\n // initialize va until script is loaded\n if (window.va) return;\n\n window.va = function a(...params): void {\n (window.vaq = window.vaq || []).push(params);\n };\n};\n","import type { Mode } from './types';\n\nexport function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nexport function isDevelopment(): boolean {\n if (typeof process === 'undefined') return false;\n return (\n process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test'\n );\n}\n\nexport function getMode(mode: Mode = 'auto'): Mode {\n if (mode === 'auto') {\n return isDevelopment() ? 'development' : 'production';\n }\n\n return mode;\n}\n","import { initQueue } from './queue';\nimport type { AnalyticsProps } from './types';\nimport { isBrowser, getMode } from './utils';\n\nexport const inject = (\n props: AnalyticsProps = {\n debug: true,\n },\n): void => {\n if (!isBrowser()) return;\n\n const mode = getMode(props.mode);\n\n initQueue();\n\n if (props.beforeSend) {\n window.va?.('beforeSend', props.beforeSend);\n }\n\n const src =\n mode === 'development'\n ? 'https://cdn.vercel-insights.com/v1/script.debug.js'\n : '/_vercel/insights/script.js';\n\n if (document.head.querySelector(`script[src*=\"${src}\"]`)) return;\n\n const script = document.createElement('script');\n script.src = src;\n script.defer = true;\n\n if (mode === 'development' && props.debug === false) {\n script.setAttribute('data-debug', 'false');\n }\n\n document.head.appendChild(script);\n};\n"],"mappings":";AAAO,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO;AAAI;AAEf,SAAO,KAAK,SAAS,KAAK,QAAc;AACtC,KAAC,OAAO,MAAM,OAAO,OAAO,CAAC,GAAG,KAAK,MAAM;AAAA,EAC7C;AACF;;;ACLO,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;AAEO,SAAS,gBAAyB;AACvC,MAAI,OAAO,YAAY;AAAa,WAAO;AAC3C,SACE,QAAQ,IAAI,aAAa,iBAAiB,QAAQ,IAAI,aAAa;AAEvE;AAEO,SAAS,QAAQ,OAAa,QAAc;AACjD,MAAI,SAAS,QAAQ;AACnB,WAAO,cAAc,IAAI,gBAAgB;AAAA,EAC3C;AAEA,SAAO;AACT;;;ACfO,IAAM,SAAS,CACpB,QAAwB;AAAA,EACtB,OAAO;AACT,MACS;AARX;AASE,MAAI,CAAC,UAAU;AAAG;AAElB,QAAM,OAAO,QAAQ,MAAM,IAAI;AAE/B,YAAU;AAEV,MAAI,MAAM,YAAY;AACpB,iBAAO,OAAP,gCAAY,cAAc,MAAM;AAAA,EAClC;AAEA,QAAM,MACJ,SAAS,gBACL,uDACA;AAEN,MAAI,SAAS,KAAK,cAAc,gBAAgB,OAAO;AAAG;AAE1D,QAAM,SAAS,SAAS,cAAc,QAAQ;AAC9C,SAAO,MAAM;AACb,SAAO,QAAQ;AAEf,MAAI,SAAS,iBAAiB,MAAM,UAAU,OAAO;AACnD,WAAO,aAAa,cAAc,OAAO;AAAA,EAC3C;AAEA,WAAS,KAAK,YAAY,MAAM;AAClC;","names":[]}
|
package/dist/react/index.cjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use client";
|
|
1
2
|
"use strict";
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -20,9 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
21
|
// src/react.tsx
|
|
21
22
|
var react_exports = {};
|
|
22
23
|
__export(react_exports, {
|
|
23
|
-
Analytics: () => Analytics
|
|
24
|
-
default: () => react_default,
|
|
25
|
-
track: () => track
|
|
24
|
+
Analytics: () => Analytics
|
|
26
25
|
});
|
|
27
26
|
module.exports = __toCommonJS(react_exports);
|
|
28
27
|
var import_react = require("react");
|
|
@@ -40,50 +39,16 @@ var initQueue = () => {
|
|
|
40
39
|
function isBrowser() {
|
|
41
40
|
return typeof window !== "undefined";
|
|
42
41
|
}
|
|
43
|
-
function
|
|
42
|
+
function isDevelopment() {
|
|
44
43
|
if (typeof process === "undefined")
|
|
45
|
-
return
|
|
46
|
-
|
|
47
|
-
return "development";
|
|
48
|
-
return "production";
|
|
44
|
+
return false;
|
|
45
|
+
return process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
|
|
49
46
|
}
|
|
50
|
-
function
|
|
47
|
+
function getMode(mode = "auto") {
|
|
51
48
|
if (mode === "auto") {
|
|
52
|
-
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
window.vam = mode;
|
|
56
|
-
}
|
|
57
|
-
function getMode() {
|
|
58
|
-
return window.vam || "production";
|
|
59
|
-
}
|
|
60
|
-
function isProduction() {
|
|
61
|
-
return getMode() === "production";
|
|
62
|
-
}
|
|
63
|
-
function isDevelopment() {
|
|
64
|
-
return getMode() === "development";
|
|
65
|
-
}
|
|
66
|
-
var removeKey = (key, { [key]: _, ...rest }) => rest;
|
|
67
|
-
function parseProperties(properties, options) {
|
|
68
|
-
let props = properties;
|
|
69
|
-
const errorProperties = [];
|
|
70
|
-
for (const [key, value] of Object.entries(properties)) {
|
|
71
|
-
if (typeof value === "object" && value !== null) {
|
|
72
|
-
if (options.strip) {
|
|
73
|
-
props = removeKey(key, props);
|
|
74
|
-
} else {
|
|
75
|
-
errorProperties.push(key);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
49
|
+
return isDevelopment() ? "development" : "production";
|
|
78
50
|
}
|
|
79
|
-
|
|
80
|
-
throw Error(
|
|
81
|
-
`The following properties are not valid: ${errorProperties.join(
|
|
82
|
-
", "
|
|
83
|
-
)}. Only strings, numbers, booleans, and null are allowed.`
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
return props;
|
|
51
|
+
return mode;
|
|
87
52
|
}
|
|
88
53
|
|
|
89
54
|
// src/generic.ts
|
|
@@ -93,44 +58,22 @@ var inject = (props = {
|
|
|
93
58
|
var _a;
|
|
94
59
|
if (!isBrowser())
|
|
95
60
|
return;
|
|
96
|
-
|
|
61
|
+
const mode = getMode(props.mode);
|
|
97
62
|
initQueue();
|
|
98
63
|
if (props.beforeSend) {
|
|
99
64
|
(_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", props.beforeSend);
|
|
100
65
|
}
|
|
101
|
-
const src =
|
|
66
|
+
const src = mode === "development" ? "https://cdn.vercel-insights.com/v1/script.debug.js" : "/_vercel/insights/script.js";
|
|
102
67
|
if (document.head.querySelector(`script[src*="${src}"]`))
|
|
103
68
|
return;
|
|
104
69
|
const script = document.createElement("script");
|
|
105
70
|
script.src = src;
|
|
106
71
|
script.defer = true;
|
|
107
|
-
if (
|
|
72
|
+
if (mode === "development" && props.debug === false) {
|
|
108
73
|
script.setAttribute("data-debug", "false");
|
|
109
74
|
}
|
|
110
75
|
document.head.appendChild(script);
|
|
111
76
|
};
|
|
112
|
-
var track = (name, properties) => {
|
|
113
|
-
var _a, _b;
|
|
114
|
-
if (!isBrowser())
|
|
115
|
-
return;
|
|
116
|
-
if (!properties) {
|
|
117
|
-
(_a = window.va) == null ? void 0 : _a.call(window, "event", { name });
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
try {
|
|
121
|
-
const props = parseProperties(properties, {
|
|
122
|
-
strip: isProduction()
|
|
123
|
-
});
|
|
124
|
-
(_b = window.va) == null ? void 0 : _b.call(window, "event", {
|
|
125
|
-
name,
|
|
126
|
-
data: props
|
|
127
|
-
});
|
|
128
|
-
} catch (err) {
|
|
129
|
-
if (err instanceof Error && isDevelopment()) {
|
|
130
|
-
console.error(err);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
77
|
|
|
135
78
|
// src/react.tsx
|
|
136
79
|
function Analytics({
|
|
@@ -143,13 +86,8 @@ function Analytics({
|
|
|
143
86
|
}, [beforeSend, debug, mode]);
|
|
144
87
|
return null;
|
|
145
88
|
}
|
|
146
|
-
var react_default = {
|
|
147
|
-
Analytics,
|
|
148
|
-
track
|
|
149
|
-
};
|
|
150
89
|
// Annotate the CommonJS export names for ESM import in node:
|
|
151
90
|
0 && (module.exports = {
|
|
152
|
-
Analytics
|
|
153
|
-
track
|
|
91
|
+
Analytics
|
|
154
92
|
});
|
|
155
93
|
//# sourceMappingURL=index.cjs.map
|
package/dist/react/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/react.tsx","../../src/queue.ts","../../src/utils.ts","../../src/generic.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport { inject
|
|
1
|
+
{"version":3,"sources":["../../src/react.tsx","../../src/queue.ts","../../src/utils.ts","../../src/generic.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport { inject } from './generic';\nimport type { AnalyticsProps } from './types';\n\nexport type { AnalyticsProps } from './types';\n\nexport function Analytics({\n beforeSend,\n debug = true,\n mode = 'auto',\n}: AnalyticsProps): null {\n useEffect(() => {\n inject({ beforeSend, debug, mode });\n }, [beforeSend, debug, mode]);\n\n return null;\n}\n","export const initQueue = (): void => {\n // initialize va until script is loaded\n if (window.va) return;\n\n window.va = function a(...params): void {\n (window.vaq = window.vaq || []).push(params);\n };\n};\n","import type { Mode } from './types';\n\nexport function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nexport function isDevelopment(): boolean {\n if (typeof process === 'undefined') return false;\n return (\n process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test'\n );\n}\n\nexport function getMode(mode: Mode = 'auto'): Mode {\n if (mode === 'auto') {\n return isDevelopment() ? 'development' : 'production';\n }\n\n return mode;\n}\n","import { initQueue } from './queue';\nimport type { AnalyticsProps } from './types';\nimport { isBrowser, getMode } from './utils';\n\nexport const inject = (\n props: AnalyticsProps = {\n debug: true,\n },\n): void => {\n if (!isBrowser()) return;\n\n const mode = getMode(props.mode);\n\n initQueue();\n\n if (props.beforeSend) {\n window.va?.('beforeSend', props.beforeSend);\n }\n\n const src =\n mode === 'development'\n ? 'https://cdn.vercel-insights.com/v1/script.debug.js'\n : '/_vercel/insights/script.js';\n\n if (document.head.querySelector(`script[src*=\"${src}\"]`)) return;\n\n const script = document.createElement('script');\n script.src = src;\n script.defer = true;\n\n if (mode === 'development' && props.debug === false) {\n script.setAttribute('data-debug', 'false');\n }\n\n document.head.appendChild(script);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;;;ACAnB,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO;AAAI;AAEf,SAAO,KAAK,SAAS,KAAK,QAAc;AACtC,KAAC,OAAO,MAAM,OAAO,OAAO,CAAC,GAAG,KAAK,MAAM;AAAA,EAC7C;AACF;;;ACLO,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;AAEO,SAAS,gBAAyB;AACvC,MAAI,OAAO,YAAY;AAAa,WAAO;AAC3C,SACE,QAAQ,IAAI,aAAa,iBAAiB,QAAQ,IAAI,aAAa;AAEvE;AAEO,SAAS,QAAQ,OAAa,QAAc;AACjD,MAAI,SAAS,QAAQ;AACnB,WAAO,cAAc,IAAI,gBAAgB;AAAA,EAC3C;AAEA,SAAO;AACT;;;ACfO,IAAM,SAAS,CACpB,QAAwB;AAAA,EACtB,OAAO;AACT,MACS;AARX;AASE,MAAI,CAAC,UAAU;AAAG;AAElB,QAAM,OAAO,QAAQ,MAAM,IAAI;AAE/B,YAAU;AAEV,MAAI,MAAM,YAAY;AACpB,iBAAO,OAAP,gCAAY,cAAc,MAAM;AAAA,EAClC;AAEA,QAAM,MACJ,SAAS,gBACL,uDACA;AAEN,MAAI,SAAS,KAAK,cAAc,gBAAgB,OAAO;AAAG;AAE1D,QAAM,SAAS,SAAS,cAAc,QAAQ;AAC9C,SAAO,MAAM;AACb,SAAO,QAAQ;AAEf,MAAI,SAAS,iBAAiB,MAAM,UAAU,OAAO;AACnD,WAAO,aAAa,cAAc,OAAO;AAAA,EAC3C;AAEA,WAAS,KAAK,YAAY,MAAM;AAClC;;;AH7BO,SAAS,UAAU;AAAA,EACxB;AAAA,EACA,QAAQ;AAAA,EACR,OAAO;AACT,GAAyB;AACvB,8BAAU,MAAM;AACd,WAAO,EAAE,YAAY,OAAO,KAAK,CAAC;AAAA,EACpC,GAAG,CAAC,YAAY,OAAO,IAAI,CAAC;AAE5B,SAAO;AACT;","names":[]}
|
package/dist/react/index.d.ts
CHANGED
|
@@ -4,7 +4,6 @@ interface PageViewEvent {
|
|
|
4
4
|
}
|
|
5
5
|
declare type Event = PageViewEvent;
|
|
6
6
|
declare type Mode = 'auto' | 'development' | 'production';
|
|
7
|
-
declare type AllowedPropertyValues = string | number | boolean | null;
|
|
8
7
|
declare type BeforeSend = (event: Event) => Event | null;
|
|
9
8
|
interface AnalyticsProps {
|
|
10
9
|
beforeSend?: BeforeSend;
|
|
@@ -13,20 +12,12 @@ interface AnalyticsProps {
|
|
|
13
12
|
}
|
|
14
13
|
declare global {
|
|
15
14
|
interface Window {
|
|
16
|
-
va?: (event:
|
|
15
|
+
va?: (event: string, properties?: unknown) => void;
|
|
17
16
|
vaq?: [string, unknown?][];
|
|
18
17
|
vai?: boolean;
|
|
19
|
-
vam?: Mode;
|
|
20
18
|
}
|
|
21
19
|
}
|
|
22
20
|
|
|
23
|
-
declare const track: (name: string, properties?: Record<string, AllowedPropertyValues>) => void;
|
|
24
|
-
|
|
25
21
|
declare function Analytics({ beforeSend, debug, mode, }: AnalyticsProps): null;
|
|
26
22
|
|
|
27
|
-
|
|
28
|
-
Analytics: typeof Analytics;
|
|
29
|
-
track: (name: string, properties?: Record<string, AllowedPropertyValues> | undefined) => void;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export { Analytics, AnalyticsProps, _default as default, track };
|
|
23
|
+
export { Analytics, AnalyticsProps };
|
package/dist/react/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
1
3
|
// src/react.tsx
|
|
2
4
|
import { useEffect } from "react";
|
|
3
5
|
|
|
@@ -14,50 +16,16 @@ var initQueue = () => {
|
|
|
14
16
|
function isBrowser() {
|
|
15
17
|
return typeof window !== "undefined";
|
|
16
18
|
}
|
|
17
|
-
function
|
|
19
|
+
function isDevelopment() {
|
|
18
20
|
if (typeof process === "undefined")
|
|
19
|
-
return
|
|
20
|
-
|
|
21
|
-
return "development";
|
|
22
|
-
return "production";
|
|
21
|
+
return false;
|
|
22
|
+
return process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
|
|
23
23
|
}
|
|
24
|
-
function
|
|
24
|
+
function getMode(mode = "auto") {
|
|
25
25
|
if (mode === "auto") {
|
|
26
|
-
|
|
27
|
-
return;
|
|
26
|
+
return isDevelopment() ? "development" : "production";
|
|
28
27
|
}
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
function getMode() {
|
|
32
|
-
return window.vam || "production";
|
|
33
|
-
}
|
|
34
|
-
function isProduction() {
|
|
35
|
-
return getMode() === "production";
|
|
36
|
-
}
|
|
37
|
-
function isDevelopment() {
|
|
38
|
-
return getMode() === "development";
|
|
39
|
-
}
|
|
40
|
-
var removeKey = (key, { [key]: _, ...rest }) => rest;
|
|
41
|
-
function parseProperties(properties, options) {
|
|
42
|
-
let props = properties;
|
|
43
|
-
const errorProperties = [];
|
|
44
|
-
for (const [key, value] of Object.entries(properties)) {
|
|
45
|
-
if (typeof value === "object" && value !== null) {
|
|
46
|
-
if (options.strip) {
|
|
47
|
-
props = removeKey(key, props);
|
|
48
|
-
} else {
|
|
49
|
-
errorProperties.push(key);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
if (errorProperties.length > 0 && !options.strip) {
|
|
54
|
-
throw Error(
|
|
55
|
-
`The following properties are not valid: ${errorProperties.join(
|
|
56
|
-
", "
|
|
57
|
-
)}. Only strings, numbers, booleans, and null are allowed.`
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
return props;
|
|
28
|
+
return mode;
|
|
61
29
|
}
|
|
62
30
|
|
|
63
31
|
// src/generic.ts
|
|
@@ -67,44 +35,22 @@ var inject = (props = {
|
|
|
67
35
|
var _a;
|
|
68
36
|
if (!isBrowser())
|
|
69
37
|
return;
|
|
70
|
-
|
|
38
|
+
const mode = getMode(props.mode);
|
|
71
39
|
initQueue();
|
|
72
40
|
if (props.beforeSend) {
|
|
73
41
|
(_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", props.beforeSend);
|
|
74
42
|
}
|
|
75
|
-
const src =
|
|
43
|
+
const src = mode === "development" ? "https://cdn.vercel-insights.com/v1/script.debug.js" : "/_vercel/insights/script.js";
|
|
76
44
|
if (document.head.querySelector(`script[src*="${src}"]`))
|
|
77
45
|
return;
|
|
78
46
|
const script = document.createElement("script");
|
|
79
47
|
script.src = src;
|
|
80
48
|
script.defer = true;
|
|
81
|
-
if (
|
|
49
|
+
if (mode === "development" && props.debug === false) {
|
|
82
50
|
script.setAttribute("data-debug", "false");
|
|
83
51
|
}
|
|
84
52
|
document.head.appendChild(script);
|
|
85
53
|
};
|
|
86
|
-
var track = (name, properties) => {
|
|
87
|
-
var _a, _b;
|
|
88
|
-
if (!isBrowser())
|
|
89
|
-
return;
|
|
90
|
-
if (!properties) {
|
|
91
|
-
(_a = window.va) == null ? void 0 : _a.call(window, "event", { name });
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
try {
|
|
95
|
-
const props = parseProperties(properties, {
|
|
96
|
-
strip: isProduction()
|
|
97
|
-
});
|
|
98
|
-
(_b = window.va) == null ? void 0 : _b.call(window, "event", {
|
|
99
|
-
name,
|
|
100
|
-
data: props
|
|
101
|
-
});
|
|
102
|
-
} catch (err) {
|
|
103
|
-
if (err instanceof Error && isDevelopment()) {
|
|
104
|
-
console.error(err);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
54
|
|
|
109
55
|
// src/react.tsx
|
|
110
56
|
function Analytics({
|
|
@@ -117,13 +63,7 @@ function Analytics({
|
|
|
117
63
|
}, [beforeSend, debug, mode]);
|
|
118
64
|
return null;
|
|
119
65
|
}
|
|
120
|
-
var react_default = {
|
|
121
|
-
Analytics,
|
|
122
|
-
track
|
|
123
|
-
};
|
|
124
66
|
export {
|
|
125
|
-
Analytics
|
|
126
|
-
react_default as default,
|
|
127
|
-
track
|
|
67
|
+
Analytics
|
|
128
68
|
};
|
|
129
69
|
//# sourceMappingURL=index.js.map
|
package/dist/react/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/react.tsx","../../src/queue.ts","../../src/utils.ts","../../src/generic.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport { inject
|
|
1
|
+
{"version":3,"sources":["../../src/react.tsx","../../src/queue.ts","../../src/utils.ts","../../src/generic.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport { inject } from './generic';\nimport type { AnalyticsProps } from './types';\n\nexport type { AnalyticsProps } from './types';\n\nexport function Analytics({\n beforeSend,\n debug = true,\n mode = 'auto',\n}: AnalyticsProps): null {\n useEffect(() => {\n inject({ beforeSend, debug, mode });\n }, [beforeSend, debug, mode]);\n\n return null;\n}\n","export const initQueue = (): void => {\n // initialize va until script is loaded\n if (window.va) return;\n\n window.va = function a(...params): void {\n (window.vaq = window.vaq || []).push(params);\n };\n};\n","import type { Mode } from './types';\n\nexport function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nexport function isDevelopment(): boolean {\n if (typeof process === 'undefined') return false;\n return (\n process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test'\n );\n}\n\nexport function getMode(mode: Mode = 'auto'): Mode {\n if (mode === 'auto') {\n return isDevelopment() ? 'development' : 'production';\n }\n\n return mode;\n}\n","import { initQueue } from './queue';\nimport type { AnalyticsProps } from './types';\nimport { isBrowser, getMode } from './utils';\n\nexport const inject = (\n props: AnalyticsProps = {\n debug: true,\n },\n): void => {\n if (!isBrowser()) return;\n\n const mode = getMode(props.mode);\n\n initQueue();\n\n if (props.beforeSend) {\n window.va?.('beforeSend', props.beforeSend);\n }\n\n const src =\n mode === 'development'\n ? 'https://cdn.vercel-insights.com/v1/script.debug.js'\n : '/_vercel/insights/script.js';\n\n if (document.head.querySelector(`script[src*=\"${src}\"]`)) return;\n\n const script = document.createElement('script');\n script.src = src;\n script.defer = true;\n\n if (mode === 'development' && props.debug === false) {\n script.setAttribute('data-debug', 'false');\n }\n\n document.head.appendChild(script);\n};\n"],"mappings":";;;AAAA,SAAS,iBAAiB;;;ACAnB,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO;AAAI;AAEf,SAAO,KAAK,SAAS,KAAK,QAAc;AACtC,KAAC,OAAO,MAAM,OAAO,OAAO,CAAC,GAAG,KAAK,MAAM;AAAA,EAC7C;AACF;;;ACLO,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;AAEO,SAAS,gBAAyB;AACvC,MAAI,OAAO,YAAY;AAAa,WAAO;AAC3C,SACE,QAAQ,IAAI,aAAa,iBAAiB,QAAQ,IAAI,aAAa;AAEvE;AAEO,SAAS,QAAQ,OAAa,QAAc;AACjD,MAAI,SAAS,QAAQ;AACnB,WAAO,cAAc,IAAI,gBAAgB;AAAA,EAC3C;AAEA,SAAO;AACT;;;ACfO,IAAM,SAAS,CACpB,QAAwB;AAAA,EACtB,OAAO;AACT,MACS;AARX;AASE,MAAI,CAAC,UAAU;AAAG;AAElB,QAAM,OAAO,QAAQ,MAAM,IAAI;AAE/B,YAAU;AAEV,MAAI,MAAM,YAAY;AACpB,iBAAO,OAAP,gCAAY,cAAc,MAAM;AAAA,EAClC;AAEA,QAAM,MACJ,SAAS,gBACL,uDACA;AAEN,MAAI,SAAS,KAAK,cAAc,gBAAgB,OAAO;AAAG;AAE1D,QAAM,SAAS,SAAS,cAAc,QAAQ;AAC9C,SAAO,MAAM;AACb,SAAO,QAAQ;AAEf,MAAI,SAAS,iBAAiB,MAAM,UAAU,OAAO;AACnD,WAAO,aAAa,cAAc,OAAO;AAAA,EAC3C;AAEA,WAAS,KAAK,YAAY,MAAM;AAClC;;;AH7BO,SAAS,UAAU;AAAA,EACxB;AAAA,EACA,QAAQ;AAAA,EACR,OAAO;AACT,GAAyB;AACvB,YAAU,MAAM;AACd,WAAO,EAAE,YAAY,OAAO,KAAK,CAAC;AAAA,EACpC,GAAG,CAAC,YAAY,OAAO,IAAI,CAAC;AAE5B,SAAO;AACT;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercel/analytics",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"analytics",
|
|
6
6
|
"vercel"
|
|
@@ -10,12 +10,14 @@
|
|
|
10
10
|
"exports": {
|
|
11
11
|
"./package.json": "./package.json",
|
|
12
12
|
".": {
|
|
13
|
-
"
|
|
14
|
-
"import": "./dist/index.js"
|
|
13
|
+
"browser": "./dist/index.js",
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"require": "./dist/index.cjs"
|
|
15
16
|
},
|
|
16
17
|
"./react": {
|
|
17
|
-
"
|
|
18
|
-
"import": "./dist/react/index.js"
|
|
18
|
+
"browser": "./dist/react/index.js",
|
|
19
|
+
"import": "./dist/react/index.js",
|
|
20
|
+
"require": "./dist/react/index.cjs"
|
|
19
21
|
}
|
|
20
22
|
},
|
|
21
23
|
"main": "dist/index.js",
|
|
@@ -52,7 +54,7 @@
|
|
|
52
54
|
"jest-environment-jsdom": "^29.3.1",
|
|
53
55
|
"react": "^18.2.0",
|
|
54
56
|
"react-dom": "^18.2.0",
|
|
55
|
-
"tsup": "6.
|
|
57
|
+
"tsup": "^6.3.0"
|
|
56
58
|
},
|
|
57
59
|
"peerDependencies": {
|
|
58
60
|
"react": "^16.8||^17||^18"
|
package/tsup.config.js
CHANGED
|
@@ -23,5 +23,11 @@ export default defineConfig([
|
|
|
23
23
|
index: 'src/react.tsx',
|
|
24
24
|
},
|
|
25
25
|
outDir: 'dist/react',
|
|
26
|
+
esbuildOptions: (options) => {
|
|
27
|
+
// Append "use client" to the top of the react entry point
|
|
28
|
+
options.banner = {
|
|
29
|
+
js: '"use client";',
|
|
30
|
+
};
|
|
31
|
+
},
|
|
26
32
|
},
|
|
27
33
|
]);
|