@vercel/analytics 0.1.5-beta.0 → 0.1.6-beta.0
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 +14 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.js +14 -5
- package/dist/index.js.map +1 -1
- package/dist/react/index.cjs +18 -8
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.ts +6 -4
- package/dist/react/index.js +18 -8
- package/dist/react/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -42,23 +42,32 @@ function isDevelopment() {
|
|
|
42
42
|
return false;
|
|
43
43
|
return process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
|
|
44
44
|
}
|
|
45
|
+
function getMode(mode = "auto") {
|
|
46
|
+
if (mode === "auto") {
|
|
47
|
+
return isDevelopment() ? "development" : "production";
|
|
48
|
+
}
|
|
49
|
+
return mode;
|
|
50
|
+
}
|
|
45
51
|
|
|
46
52
|
// src/generic.ts
|
|
47
|
-
var inject = (
|
|
53
|
+
var inject = (props = {
|
|
54
|
+
debug: true
|
|
55
|
+
}) => {
|
|
48
56
|
var _a;
|
|
49
57
|
if (!isBrowser())
|
|
50
58
|
return;
|
|
59
|
+
const mode = getMode(props.__mode);
|
|
51
60
|
initQueue();
|
|
52
|
-
if (beforeSend) {
|
|
53
|
-
(_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", beforeSend);
|
|
61
|
+
if (props.beforeSend) {
|
|
62
|
+
(_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", props.beforeSend);
|
|
54
63
|
}
|
|
55
|
-
const src =
|
|
64
|
+
const src = mode === "development" ? "https://cdn.vercel-insights.com/v1/script.debug.js" : "/_vercel/insights/script.js";
|
|
56
65
|
if (document.head.querySelector(`script[src*="${src}"]`))
|
|
57
66
|
return;
|
|
58
67
|
const script = document.createElement("script");
|
|
59
68
|
script.src = src;
|
|
60
69
|
script.defer = true;
|
|
61
|
-
if (
|
|
70
|
+
if (mode === "development" && props.debug === false) {
|
|
62
71
|
script.setAttribute("data-debug", "false");
|
|
63
72
|
}
|
|
64
73
|
document.head.appendChild(script);
|
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 { AnalyticsProps } from './types';\nimport { isBrowser,
|
|
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,MAAM;AAEjC,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
|
@@ -2,11 +2,13 @@ interface PageViewEvent {
|
|
|
2
2
|
type: 'pageview';
|
|
3
3
|
url: string;
|
|
4
4
|
}
|
|
5
|
-
declare type
|
|
6
|
-
declare type
|
|
5
|
+
declare type Event = PageViewEvent;
|
|
6
|
+
declare type Mode = 'auto' | 'development' | 'production';
|
|
7
|
+
declare type BeforeSend = (event: Event) => Event | null;
|
|
7
8
|
interface AnalyticsProps {
|
|
8
9
|
beforeSend?: BeforeSend;
|
|
9
10
|
debug?: boolean;
|
|
11
|
+
__mode?: Mode;
|
|
10
12
|
}
|
|
11
13
|
declare global {
|
|
12
14
|
interface Window {
|
|
@@ -16,6 +18,6 @@ declare global {
|
|
|
16
18
|
}
|
|
17
19
|
}
|
|
18
20
|
|
|
19
|
-
declare const inject: (
|
|
21
|
+
declare const inject: (props?: AnalyticsProps) => void;
|
|
20
22
|
|
|
21
23
|
export { inject };
|
package/dist/index.js
CHANGED
|
@@ -16,23 +16,32 @@ function isDevelopment() {
|
|
|
16
16
|
return false;
|
|
17
17
|
return process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
|
|
18
18
|
}
|
|
19
|
+
function getMode(mode = "auto") {
|
|
20
|
+
if (mode === "auto") {
|
|
21
|
+
return isDevelopment() ? "development" : "production";
|
|
22
|
+
}
|
|
23
|
+
return mode;
|
|
24
|
+
}
|
|
19
25
|
|
|
20
26
|
// src/generic.ts
|
|
21
|
-
var inject = (
|
|
27
|
+
var inject = (props = {
|
|
28
|
+
debug: true
|
|
29
|
+
}) => {
|
|
22
30
|
var _a;
|
|
23
31
|
if (!isBrowser())
|
|
24
32
|
return;
|
|
33
|
+
const mode = getMode(props.__mode);
|
|
25
34
|
initQueue();
|
|
26
|
-
if (beforeSend) {
|
|
27
|
-
(_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", beforeSend);
|
|
35
|
+
if (props.beforeSend) {
|
|
36
|
+
(_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", props.beforeSend);
|
|
28
37
|
}
|
|
29
|
-
const src =
|
|
38
|
+
const src = mode === "development" ? "https://cdn.vercel-insights.com/v1/script.debug.js" : "/_vercel/insights/script.js";
|
|
30
39
|
if (document.head.querySelector(`script[src*="${src}"]`))
|
|
31
40
|
return;
|
|
32
41
|
const script = document.createElement("script");
|
|
33
42
|
script.src = src;
|
|
34
43
|
script.defer = true;
|
|
35
|
-
if (
|
|
44
|
+
if (mode === "development" && props.debug === false) {
|
|
36
45
|
script.setAttribute("data-debug", "false");
|
|
37
46
|
}
|
|
38
47
|
document.head.appendChild(script);
|
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 //
|
|
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,MAAM;AAEjC,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
|
@@ -43,23 +43,32 @@ function isDevelopment() {
|
|
|
43
43
|
return false;
|
|
44
44
|
return process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
|
|
45
45
|
}
|
|
46
|
+
function getMode(mode = "auto") {
|
|
47
|
+
if (mode === "auto") {
|
|
48
|
+
return isDevelopment() ? "development" : "production";
|
|
49
|
+
}
|
|
50
|
+
return mode;
|
|
51
|
+
}
|
|
46
52
|
|
|
47
53
|
// src/generic.ts
|
|
48
|
-
var inject = (
|
|
54
|
+
var inject = (props = {
|
|
55
|
+
debug: true
|
|
56
|
+
}) => {
|
|
49
57
|
var _a;
|
|
50
58
|
if (!isBrowser())
|
|
51
59
|
return;
|
|
60
|
+
const mode = getMode(props.__mode);
|
|
52
61
|
initQueue();
|
|
53
|
-
if (beforeSend) {
|
|
54
|
-
(_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", beforeSend);
|
|
62
|
+
if (props.beforeSend) {
|
|
63
|
+
(_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", props.beforeSend);
|
|
55
64
|
}
|
|
56
|
-
const src =
|
|
65
|
+
const src = mode === "development" ? "https://cdn.vercel-insights.com/v1/script.debug.js" : "/_vercel/insights/script.js";
|
|
57
66
|
if (document.head.querySelector(`script[src*="${src}"]`))
|
|
58
67
|
return;
|
|
59
68
|
const script = document.createElement("script");
|
|
60
69
|
script.src = src;
|
|
61
70
|
script.defer = true;
|
|
62
|
-
if (
|
|
71
|
+
if (mode === "development" && props.debug === false) {
|
|
63
72
|
script.setAttribute("data-debug", "false");
|
|
64
73
|
}
|
|
65
74
|
document.head.appendChild(script);
|
|
@@ -68,11 +77,12 @@ var inject = ({ beforeSend, debug } = { debug: isDevelopment() }) => {
|
|
|
68
77
|
// src/react.tsx
|
|
69
78
|
function Analytics({
|
|
70
79
|
beforeSend,
|
|
71
|
-
debug =
|
|
80
|
+
debug = true,
|
|
81
|
+
__mode = "auto"
|
|
72
82
|
}) {
|
|
73
83
|
(0, import_react.useEffect)(() => {
|
|
74
|
-
inject({ beforeSend, debug });
|
|
75
|
-
}, [beforeSend, debug]);
|
|
84
|
+
inject({ beforeSend, debug, __mode });
|
|
85
|
+
}, [beforeSend, debug, __mode]);
|
|
76
86
|
return null;
|
|
77
87
|
}
|
|
78
88
|
// Annotate the CommonJS export names for ESM import in node:
|
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';\
|
|
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;AAEn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pageview';
|
|
3
3
|
url: string;
|
|
4
4
|
}
|
|
5
|
-
declare type
|
|
6
|
-
declare type
|
|
5
|
+
declare type Event = PageViewEvent;
|
|
6
|
+
declare type Mode = 'auto' | 'development' | 'production';
|
|
7
|
+
declare type BeforeSend = (event: Event) => Event | null;
|
|
7
8
|
interface AnalyticsProps {
|
|
8
9
|
beforeSend?: BeforeSend;
|
|
9
10
|
debug?: boolean;
|
|
11
|
+
__mode?: Mode;
|
|
10
12
|
}
|
|
11
13
|
declare global {
|
|
12
14
|
interface Window {
|
|
@@ -16,6 +18,6 @@ declare global {
|
|
|
16
18
|
}
|
|
17
19
|
}
|
|
18
20
|
|
|
19
|
-
declare function Analytics({ beforeSend, debug, }: AnalyticsProps): null;
|
|
21
|
+
declare function Analytics({ beforeSend, debug, __mode, }: AnalyticsProps): null;
|
|
20
22
|
|
|
21
|
-
export { Analytics };
|
|
23
|
+
export { Analytics, AnalyticsProps };
|
package/dist/react/index.js
CHANGED
|
@@ -19,23 +19,32 @@ function isDevelopment() {
|
|
|
19
19
|
return false;
|
|
20
20
|
return process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
|
|
21
21
|
}
|
|
22
|
+
function getMode(mode = "auto") {
|
|
23
|
+
if (mode === "auto") {
|
|
24
|
+
return isDevelopment() ? "development" : "production";
|
|
25
|
+
}
|
|
26
|
+
return mode;
|
|
27
|
+
}
|
|
22
28
|
|
|
23
29
|
// src/generic.ts
|
|
24
|
-
var inject = (
|
|
30
|
+
var inject = (props = {
|
|
31
|
+
debug: true
|
|
32
|
+
}) => {
|
|
25
33
|
var _a;
|
|
26
34
|
if (!isBrowser())
|
|
27
35
|
return;
|
|
36
|
+
const mode = getMode(props.__mode);
|
|
28
37
|
initQueue();
|
|
29
|
-
if (beforeSend) {
|
|
30
|
-
(_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", beforeSend);
|
|
38
|
+
if (props.beforeSend) {
|
|
39
|
+
(_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", props.beforeSend);
|
|
31
40
|
}
|
|
32
|
-
const src =
|
|
41
|
+
const src = mode === "development" ? "https://cdn.vercel-insights.com/v1/script.debug.js" : "/_vercel/insights/script.js";
|
|
33
42
|
if (document.head.querySelector(`script[src*="${src}"]`))
|
|
34
43
|
return;
|
|
35
44
|
const script = document.createElement("script");
|
|
36
45
|
script.src = src;
|
|
37
46
|
script.defer = true;
|
|
38
|
-
if (
|
|
47
|
+
if (mode === "development" && props.debug === false) {
|
|
39
48
|
script.setAttribute("data-debug", "false");
|
|
40
49
|
}
|
|
41
50
|
document.head.appendChild(script);
|
|
@@ -44,11 +53,12 @@ var inject = ({ beforeSend, debug } = { debug: isDevelopment() }) => {
|
|
|
44
53
|
// src/react.tsx
|
|
45
54
|
function Analytics({
|
|
46
55
|
beforeSend,
|
|
47
|
-
debug =
|
|
56
|
+
debug = true,
|
|
57
|
+
__mode = "auto"
|
|
48
58
|
}) {
|
|
49
59
|
useEffect(() => {
|
|
50
|
-
inject({ beforeSend, debug });
|
|
51
|
-
}, [beforeSend, debug]);
|
|
60
|
+
inject({ beforeSend, debug, __mode });
|
|
61
|
+
}, [beforeSend, debug, __mode]);
|
|
52
62
|
return null;
|
|
53
63
|
}
|
|
54
64
|
export {
|
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';\
|
|
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,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