@vercel/analytics 0.1.8-beta.0 → 0.1.8
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 -67
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -4
- package/dist/index.js +10 -65
- package/dist/index.js.map +1 -1
- package/dist/react/index.cjs +11 -67
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.ts +1 -5
- package/dist/react/index.js +10 -65
- package/dist/react/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -20,8 +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
|
-
inject: () => inject
|
|
24
|
-
track: () => track
|
|
23
|
+
inject: () => inject
|
|
25
24
|
});
|
|
26
25
|
module.exports = __toCommonJS(generic_exports);
|
|
27
26
|
|
|
@@ -38,50 +37,16 @@ var initQueue = () => {
|
|
|
38
37
|
function isBrowser() {
|
|
39
38
|
return typeof window !== "undefined";
|
|
40
39
|
}
|
|
41
|
-
function
|
|
40
|
+
function isDevelopment() {
|
|
42
41
|
if (typeof process === "undefined")
|
|
43
|
-
return
|
|
44
|
-
|
|
45
|
-
return "development";
|
|
46
|
-
return "production";
|
|
42
|
+
return false;
|
|
43
|
+
return process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
|
|
47
44
|
}
|
|
48
|
-
function
|
|
45
|
+
function getMode(mode = "auto") {
|
|
49
46
|
if (mode === "auto") {
|
|
50
|
-
|
|
51
|
-
return;
|
|
47
|
+
return isDevelopment() ? "development" : "production";
|
|
52
48
|
}
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
function getMode() {
|
|
56
|
-
return window.vam || "production";
|
|
57
|
-
}
|
|
58
|
-
function isProduction() {
|
|
59
|
-
return getMode() === "production";
|
|
60
|
-
}
|
|
61
|
-
function isDevelopment() {
|
|
62
|
-
return getMode() === "development";
|
|
63
|
-
}
|
|
64
|
-
var removeKey = (key, { [key]: _, ...rest }) => rest;
|
|
65
|
-
function parseProperties(properties, options) {
|
|
66
|
-
let props = properties;
|
|
67
|
-
const errorProperties = [];
|
|
68
|
-
for (const [key, value] of Object.entries(properties)) {
|
|
69
|
-
if (typeof value === "object" && value !== null) {
|
|
70
|
-
if (options.strip) {
|
|
71
|
-
props = removeKey(key, props);
|
|
72
|
-
} else {
|
|
73
|
-
errorProperties.push(key);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
if (errorProperties.length > 0 && !options.strip) {
|
|
78
|
-
throw Error(
|
|
79
|
-
`The following properties are not valid: ${errorProperties.join(
|
|
80
|
-
", "
|
|
81
|
-
)}. Only strings, numbers, booleans, and null are allowed.`
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
return props;
|
|
49
|
+
return mode;
|
|
85
50
|
}
|
|
86
51
|
|
|
87
52
|
// src/generic.ts
|
|
@@ -91,45 +56,24 @@ var inject = (props = {
|
|
|
91
56
|
var _a;
|
|
92
57
|
if (!isBrowser())
|
|
93
58
|
return;
|
|
94
|
-
|
|
59
|
+
const mode = getMode(props.mode);
|
|
95
60
|
initQueue();
|
|
96
61
|
if (props.beforeSend) {
|
|
97
62
|
(_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", props.beforeSend);
|
|
98
63
|
}
|
|
99
|
-
const src =
|
|
64
|
+
const src = mode === "development" ? "https://cdn.vercel-insights.com/v1/script.debug.js" : "/_vercel/insights/script.js";
|
|
100
65
|
if (document.head.querySelector(`script[src*="${src}"]`))
|
|
101
66
|
return;
|
|
102
67
|
const script = document.createElement("script");
|
|
103
68
|
script.src = src;
|
|
104
69
|
script.defer = true;
|
|
105
|
-
if (
|
|
70
|
+
if (mode === "development" && props.debug === false) {
|
|
106
71
|
script.setAttribute("data-debug", "false");
|
|
107
72
|
}
|
|
108
73
|
document.head.appendChild(script);
|
|
109
74
|
};
|
|
110
|
-
var track = (name, properties) => {
|
|
111
|
-
var _a, _b;
|
|
112
|
-
if (!properties) {
|
|
113
|
-
(_a = window.va) == null ? void 0 : _a.call(window, "track", { name });
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
try {
|
|
117
|
-
const props = parseProperties(properties, {
|
|
118
|
-
strip: isProduction()
|
|
119
|
-
});
|
|
120
|
-
(_b = window.va) == null ? void 0 : _b.call(window, "track", {
|
|
121
|
-
name,
|
|
122
|
-
data: props
|
|
123
|
-
});
|
|
124
|
-
} catch (err) {
|
|
125
|
-
if (err instanceof Error && isDevelopment()) {
|
|
126
|
-
console.error(err);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
75
|
// Annotate the CommonJS export names for ESM import in node:
|
|
131
76
|
0 && (module.exports = {
|
|
132
|
-
inject
|
|
133
|
-
track
|
|
77
|
+
inject
|
|
134
78
|
});
|
|
135
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;
|
|
@@ -16,11 +15,9 @@ declare global {
|
|
|
16
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
22
|
|
|
26
|
-
export { inject
|
|
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;
|
|
21
|
+
return isDevelopment() ? "development" : "production";
|
|
25
22
|
}
|
|
26
|
-
|
|
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
|
-
}
|
|
49
|
-
}
|
|
50
|
-
if (errorProperties.length > 0 && !options.strip) {
|
|
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,44 +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 (!properties) {
|
|
86
|
-
(_a = window.va) == null ? void 0 : _a.call(window, "track", { name });
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
try {
|
|
90
|
-
const props = parseProperties(properties, {
|
|
91
|
-
strip: isProduction()
|
|
92
|
-
});
|
|
93
|
-
(_b = window.va) == null ? void 0 : _b.call(window, "track", {
|
|
94
|
-
name,
|
|
95
|
-
data: props
|
|
96
|
-
});
|
|
97
|
-
} catch (err) {
|
|
98
|
-
if (err instanceof Error && isDevelopment()) {
|
|
99
|
-
console.error(err);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
49
|
export {
|
|
104
|
-
inject
|
|
105
|
-
track
|
|
50
|
+
inject
|
|
106
51
|
};
|
|
107
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
|
@@ -20,8 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/react.tsx
|
|
21
21
|
var react_exports = {};
|
|
22
22
|
__export(react_exports, {
|
|
23
|
-
Analytics: () => Analytics
|
|
24
|
-
track: () => track
|
|
23
|
+
Analytics: () => Analytics
|
|
25
24
|
});
|
|
26
25
|
module.exports = __toCommonJS(react_exports);
|
|
27
26
|
var import_react = require("react");
|
|
@@ -39,50 +38,16 @@ var initQueue = () => {
|
|
|
39
38
|
function isBrowser() {
|
|
40
39
|
return typeof window !== "undefined";
|
|
41
40
|
}
|
|
42
|
-
function
|
|
41
|
+
function isDevelopment() {
|
|
43
42
|
if (typeof process === "undefined")
|
|
44
|
-
return
|
|
45
|
-
|
|
46
|
-
return "development";
|
|
47
|
-
return "production";
|
|
43
|
+
return false;
|
|
44
|
+
return process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
|
|
48
45
|
}
|
|
49
|
-
function
|
|
46
|
+
function getMode(mode = "auto") {
|
|
50
47
|
if (mode === "auto") {
|
|
51
|
-
|
|
52
|
-
return;
|
|
48
|
+
return isDevelopment() ? "development" : "production";
|
|
53
49
|
}
|
|
54
|
-
|
|
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
|
-
}
|
|
77
|
-
}
|
|
78
|
-
if (errorProperties.length > 0 && !options.strip) {
|
|
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;
|
|
50
|
+
return mode;
|
|
86
51
|
}
|
|
87
52
|
|
|
88
53
|
// src/generic.ts
|
|
@@ -92,42 +57,22 @@ var inject = (props = {
|
|
|
92
57
|
var _a;
|
|
93
58
|
if (!isBrowser())
|
|
94
59
|
return;
|
|
95
|
-
|
|
60
|
+
const mode = getMode(props.mode);
|
|
96
61
|
initQueue();
|
|
97
62
|
if (props.beforeSend) {
|
|
98
63
|
(_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", props.beforeSend);
|
|
99
64
|
}
|
|
100
|
-
const src =
|
|
65
|
+
const src = mode === "development" ? "https://cdn.vercel-insights.com/v1/script.debug.js" : "/_vercel/insights/script.js";
|
|
101
66
|
if (document.head.querySelector(`script[src*="${src}"]`))
|
|
102
67
|
return;
|
|
103
68
|
const script = document.createElement("script");
|
|
104
69
|
script.src = src;
|
|
105
70
|
script.defer = true;
|
|
106
|
-
if (
|
|
71
|
+
if (mode === "development" && props.debug === false) {
|
|
107
72
|
script.setAttribute("data-debug", "false");
|
|
108
73
|
}
|
|
109
74
|
document.head.appendChild(script);
|
|
110
75
|
};
|
|
111
|
-
var track = (name, properties) => {
|
|
112
|
-
var _a, _b;
|
|
113
|
-
if (!properties) {
|
|
114
|
-
(_a = window.va) == null ? void 0 : _a.call(window, "track", { name });
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
try {
|
|
118
|
-
const props = parseProperties(properties, {
|
|
119
|
-
strip: isProduction()
|
|
120
|
-
});
|
|
121
|
-
(_b = window.va) == null ? void 0 : _b.call(window, "track", {
|
|
122
|
-
name,
|
|
123
|
-
data: props
|
|
124
|
-
});
|
|
125
|
-
} catch (err) {
|
|
126
|
-
if (err instanceof Error && isDevelopment()) {
|
|
127
|
-
console.error(err);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
76
|
|
|
132
77
|
// src/react.tsx
|
|
133
78
|
function Analytics({
|
|
@@ -142,7 +87,6 @@ function Analytics({
|
|
|
142
87
|
}
|
|
143
88
|
// Annotate the CommonJS export names for ESM import in node:
|
|
144
89
|
0 && (module.exports = {
|
|
145
|
-
Analytics
|
|
146
|
-
track
|
|
90
|
+
Analytics
|
|
147
91
|
});
|
|
148
92
|
//# 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 } 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
|
|
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;
|
|
@@ -16,12 +15,9 @@ declare global {
|
|
|
16
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
|
-
export { Analytics, AnalyticsProps
|
|
23
|
+
export { Analytics, AnalyticsProps };
|
package/dist/react/index.js
CHANGED
|
@@ -14,50 +14,16 @@ var initQueue = () => {
|
|
|
14
14
|
function isBrowser() {
|
|
15
15
|
return typeof window !== "undefined";
|
|
16
16
|
}
|
|
17
|
-
function
|
|
17
|
+
function isDevelopment() {
|
|
18
18
|
if (typeof process === "undefined")
|
|
19
|
-
return
|
|
20
|
-
|
|
21
|
-
return "development";
|
|
22
|
-
return "production";
|
|
19
|
+
return false;
|
|
20
|
+
return process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
|
|
23
21
|
}
|
|
24
|
-
function
|
|
22
|
+
function getMode(mode = "auto") {
|
|
25
23
|
if (mode === "auto") {
|
|
26
|
-
|
|
27
|
-
return;
|
|
24
|
+
return isDevelopment() ? "development" : "production";
|
|
28
25
|
}
|
|
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;
|
|
26
|
+
return mode;
|
|
61
27
|
}
|
|
62
28
|
|
|
63
29
|
// src/generic.ts
|
|
@@ -67,42 +33,22 @@ var inject = (props = {
|
|
|
67
33
|
var _a;
|
|
68
34
|
if (!isBrowser())
|
|
69
35
|
return;
|
|
70
|
-
|
|
36
|
+
const mode = getMode(props.mode);
|
|
71
37
|
initQueue();
|
|
72
38
|
if (props.beforeSend) {
|
|
73
39
|
(_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", props.beforeSend);
|
|
74
40
|
}
|
|
75
|
-
const src =
|
|
41
|
+
const src = mode === "development" ? "https://cdn.vercel-insights.com/v1/script.debug.js" : "/_vercel/insights/script.js";
|
|
76
42
|
if (document.head.querySelector(`script[src*="${src}"]`))
|
|
77
43
|
return;
|
|
78
44
|
const script = document.createElement("script");
|
|
79
45
|
script.src = src;
|
|
80
46
|
script.defer = true;
|
|
81
|
-
if (
|
|
47
|
+
if (mode === "development" && props.debug === false) {
|
|
82
48
|
script.setAttribute("data-debug", "false");
|
|
83
49
|
}
|
|
84
50
|
document.head.appendChild(script);
|
|
85
51
|
};
|
|
86
|
-
var track = (name, properties) => {
|
|
87
|
-
var _a, _b;
|
|
88
|
-
if (!properties) {
|
|
89
|
-
(_a = window.va) == null ? void 0 : _a.call(window, "track", { name });
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
try {
|
|
93
|
-
const props = parseProperties(properties, {
|
|
94
|
-
strip: isProduction()
|
|
95
|
-
});
|
|
96
|
-
(_b = window.va) == null ? void 0 : _b.call(window, "track", {
|
|
97
|
-
name,
|
|
98
|
-
data: props
|
|
99
|
-
});
|
|
100
|
-
} catch (err) {
|
|
101
|
-
if (err instanceof Error && isDevelopment()) {
|
|
102
|
-
console.error(err);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
52
|
|
|
107
53
|
// src/react.tsx
|
|
108
54
|
function Analytics({
|
|
@@ -116,7 +62,6 @@ function Analytics({
|
|
|
116
62
|
return null;
|
|
117
63
|
}
|
|
118
64
|
export {
|
|
119
|
-
Analytics
|
|
120
|
-
track
|
|
65
|
+
Analytics
|
|
121
66
|
};
|
|
122
67
|
//# 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 } 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
|
|
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":[]}
|