@vercel/analytics 0.1.0 → 0.1.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/index.cjs +24 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +11 -9
- package/dist/index.js +12 -15
- package/dist/index.js.map +1 -1
- package/dist/react/index.cjs +40 -27
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.ts +8 -8
- package/dist/react/index.js +28 -22
- package/dist/react/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -8,50 +8,54 @@ var __export = (target, all) => {
|
|
|
8
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
9
|
};
|
|
10
10
|
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from ===
|
|
11
|
+
if ((from && typeof from === 'object') || typeof from === 'function') {
|
|
12
12
|
for (let key of __getOwnPropNames(from))
|
|
13
13
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, {
|
|
14
|
+
__defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
|
|
17
|
+
});
|
|
15
18
|
}
|
|
16
19
|
return to;
|
|
17
20
|
};
|
|
18
|
-
var __toCommonJS = (mod) =>
|
|
21
|
+
var __toCommonJS = (mod) =>
|
|
22
|
+
__copyProps(__defProp({}, '__esModule', { value: true }), mod);
|
|
19
23
|
|
|
20
24
|
// src/generic.ts
|
|
21
25
|
var generic_exports = {};
|
|
22
26
|
__export(generic_exports, {
|
|
23
|
-
inject: () => inject
|
|
27
|
+
inject: () => inject,
|
|
24
28
|
});
|
|
25
29
|
module.exports = __toCommonJS(generic_exports);
|
|
26
30
|
|
|
27
31
|
// src/queue.ts
|
|
28
32
|
var initQueue = () => {
|
|
29
|
-
if (window.va)
|
|
30
|
-
return;
|
|
33
|
+
if (window.va) return;
|
|
31
34
|
window.va = function a(...params) {
|
|
32
35
|
(window.vaq = window.vaq || []).push(params);
|
|
33
36
|
};
|
|
34
37
|
};
|
|
35
38
|
|
|
36
39
|
// src/generic.ts
|
|
37
|
-
var isBrowser = typeof window !==
|
|
38
|
-
var inject = ({
|
|
39
|
-
beforeSend
|
|
40
|
-
} = {}) => {
|
|
40
|
+
var isBrowser = typeof window !== 'undefined';
|
|
41
|
+
var inject = ({ beforeSend } = {}) => {
|
|
41
42
|
var _a;
|
|
42
|
-
if (!isBrowser
|
|
43
|
-
return;
|
|
43
|
+
if (!isBrowser) return;
|
|
44
44
|
initQueue();
|
|
45
45
|
if (beforeSend) {
|
|
46
|
-
(_a = window.va) == null
|
|
46
|
+
(_a = window.va) == null
|
|
47
|
+
? void 0
|
|
48
|
+
: _a.call(window, 'beforeSend', beforeSend);
|
|
47
49
|
}
|
|
48
|
-
|
|
49
|
-
script
|
|
50
|
+
if (document.head.querySelector('script[src="/va/script.js"]')) return;
|
|
51
|
+
const script = document.createElement('script');
|
|
52
|
+
script.src = '/va/script.js';
|
|
50
53
|
script.async = true;
|
|
51
54
|
document.head.appendChild(script);
|
|
52
55
|
};
|
|
53
56
|
// Annotate the CommonJS export names for ESM import in node:
|
|
54
|
-
0 &&
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
0 &&
|
|
58
|
+
(module.exports = {
|
|
59
|
+
inject,
|
|
60
|
+
});
|
|
61
|
+
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/generic.ts","../src/queue.ts"],"sourcesContent":["import { initQueue } from './queue';\nimport type { BeforeSend } from './types';\n\nconst isBrowser = typeof window !== 'undefined';\n\nexport const inject = ({\n beforeSend,\n}: { beforeSend?: BeforeSend } = {}): void => {\n if (!isBrowser
|
|
1
|
+
{"version":3,"sources":["../src/generic.ts","../src/queue.ts"],"sourcesContent":["import { initQueue } from './queue';\nimport type { BeforeSend } from './types';\n\nconst isBrowser = typeof window !== 'undefined';\n\nexport const inject = ({\n beforeSend,\n}: { beforeSend?: BeforeSend } = {}): void => {\n if (!isBrowser) return;\n initQueue();\n\n if (beforeSend) {\n window.va?.('beforeSend', beforeSend);\n }\n\n if (document.head.querySelector('script[src=\"/va/script.js\"]')) return;\n\n const script = document.createElement('script');\n script.src = '/va/script.js';\n script.async = true;\n\n document.head.appendChild(script);\n};\n","export const initQueue = (): void => {\n // initialise 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"],"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;;;ADJA,IAAM,YAAY,OAAO,WAAW;AAE7B,IAAM,SAAS,CAAC;AAAA,EACrB;AACF,IAAiC,CAAC,MAAY;AAP9C;AAQE,MAAI,CAAC;AAAW;AAChB,YAAU;AAEV,MAAI,YAAY;AACd,iBAAO,OAAP,gCAAY,cAAc;AAAA,EAC5B;AAEA,MAAI,SAAS,KAAK,cAAc,6BAA6B;AAAG;AAEhE,QAAM,SAAS,SAAS,cAAc,QAAQ;AAC9C,SAAO,MAAM;AACb,SAAO,QAAQ;AAEf,WAAS,KAAK,YAAY,MAAM;AAClC;","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
interface PageViewEvent {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
type: 'pageview';
|
|
3
|
+
url: string;
|
|
4
4
|
}
|
|
5
5
|
declare type IEvent = PageViewEvent;
|
|
6
6
|
declare type BeforeSend = (event: IEvent) => IEvent | null;
|
|
7
7
|
declare global {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
interface Window {
|
|
9
|
+
va?: (event: string, properties?: unknown) => void;
|
|
10
|
+
vaq?: [event: string, properties?: unknown][];
|
|
11
|
+
vai?: boolean;
|
|
12
|
+
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
declare const inject: ({
|
|
16
|
-
|
|
15
|
+
declare const inject: ({
|
|
16
|
+
beforeSend,
|
|
17
|
+
}?: {
|
|
18
|
+
beforeSend?: BeforeSend | undefined;
|
|
17
19
|
}) => void;
|
|
18
20
|
|
|
19
21
|
export { inject };
|
package/dist/index.js
CHANGED
|
@@ -1,30 +1,27 @@
|
|
|
1
1
|
// src/queue.ts
|
|
2
2
|
var initQueue = () => {
|
|
3
|
-
if (window.va)
|
|
4
|
-
return;
|
|
3
|
+
if (window.va) return;
|
|
5
4
|
window.va = function a(...params) {
|
|
6
5
|
(window.vaq = window.vaq || []).push(params);
|
|
7
6
|
};
|
|
8
7
|
};
|
|
9
8
|
|
|
10
9
|
// src/generic.ts
|
|
11
|
-
var isBrowser = typeof window !==
|
|
12
|
-
var inject = ({
|
|
13
|
-
beforeSend
|
|
14
|
-
} = {}) => {
|
|
10
|
+
var isBrowser = typeof window !== 'undefined';
|
|
11
|
+
var inject = ({ beforeSend } = {}) => {
|
|
15
12
|
var _a;
|
|
16
|
-
if (!isBrowser
|
|
17
|
-
return;
|
|
13
|
+
if (!isBrowser) return;
|
|
18
14
|
initQueue();
|
|
19
15
|
if (beforeSend) {
|
|
20
|
-
(_a = window.va) == null
|
|
16
|
+
(_a = window.va) == null
|
|
17
|
+
? void 0
|
|
18
|
+
: _a.call(window, 'beforeSend', beforeSend);
|
|
21
19
|
}
|
|
22
|
-
|
|
23
|
-
script
|
|
20
|
+
if (document.head.querySelector('script[src="/va/script.js"]')) return;
|
|
21
|
+
const script = document.createElement('script');
|
|
22
|
+
script.src = '/va/script.js';
|
|
24
23
|
script.async = true;
|
|
25
24
|
document.head.appendChild(script);
|
|
26
25
|
};
|
|
27
|
-
export {
|
|
28
|
-
|
|
29
|
-
};
|
|
30
|
-
//# sourceMappingURL=index.js.map
|
|
26
|
+
export { inject };
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/queue.ts","../src/generic.ts"],"sourcesContent":["export const initQueue = (): void => {\n // initialise 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 { initQueue } from './queue';\nimport type { BeforeSend } from './types';\n\nconst isBrowser = typeof window !== 'undefined';\n\nexport const inject = ({\n beforeSend,\n}: { beforeSend?: BeforeSend } = {}): void => {\n if (!isBrowser
|
|
1
|
+
{"version":3,"sources":["../src/queue.ts","../src/generic.ts"],"sourcesContent":["export const initQueue = (): void => {\n // initialise 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 { initQueue } from './queue';\nimport type { BeforeSend } from './types';\n\nconst isBrowser = typeof window !== 'undefined';\n\nexport const inject = ({\n beforeSend,\n}: { beforeSend?: BeforeSend } = {}): void => {\n if (!isBrowser) return;\n initQueue();\n\n if (beforeSend) {\n window.va?.('beforeSend', beforeSend);\n }\n\n if (document.head.querySelector('script[src=\"/va/script.js\"]')) return;\n\n const script = document.createElement('script');\n script.src = '/va/script.js';\n script.async = true;\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;;;ACJA,IAAM,YAAY,OAAO,WAAW;AAE7B,IAAM,SAAS,CAAC;AAAA,EACrB;AACF,IAAiC,CAAC,MAAY;AAP9C;AAQE,MAAI,CAAC;AAAW;AAChB,YAAU;AAEV,MAAI,YAAY;AACd,iBAAO,OAAP,gCAAY,cAAc;AAAA,EAC5B;AAEA,MAAI,SAAS,KAAK,cAAc,6BAA6B;AAAG;AAEhE,QAAM,SAAS,SAAS,cAAc,QAAQ;AAC9C,SAAO,MAAM;AACb,SAAO,QAAQ;AAEf,WAAS,KAAK,YAAY,MAAM;AAClC;","names":[]}
|
package/dist/react/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -8,67 +8,80 @@ var __export = (target, all) => {
|
|
|
8
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
9
|
};
|
|
10
10
|
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from ===
|
|
11
|
+
if ((from && typeof from === 'object') || typeof from === 'function') {
|
|
12
12
|
for (let key of __getOwnPropNames(from))
|
|
13
13
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, {
|
|
14
|
+
__defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
|
|
17
|
+
});
|
|
15
18
|
}
|
|
16
19
|
return to;
|
|
17
20
|
};
|
|
18
|
-
var __toCommonJS = (mod) =>
|
|
21
|
+
var __toCommonJS = (mod) =>
|
|
22
|
+
__copyProps(__defProp({}, '__esModule', { value: true }), mod);
|
|
19
23
|
|
|
20
24
|
// src/react.tsx
|
|
21
25
|
var react_exports = {};
|
|
22
26
|
__export(react_exports, {
|
|
23
|
-
Analytics: () => Analytics
|
|
27
|
+
Analytics: () => Analytics,
|
|
24
28
|
});
|
|
25
29
|
module.exports = __toCommonJS(react_exports);
|
|
26
|
-
var import_react = require(
|
|
30
|
+
var import_react = require('react');
|
|
27
31
|
|
|
28
32
|
// src/queue.ts
|
|
29
33
|
var initQueue = () => {
|
|
30
|
-
if (window.va)
|
|
31
|
-
return;
|
|
34
|
+
if (window.va) return;
|
|
32
35
|
window.va = function a(...params) {
|
|
33
36
|
(window.vaq = window.vaq || []).push(params);
|
|
34
37
|
};
|
|
35
38
|
};
|
|
36
39
|
|
|
37
|
-
// src/
|
|
38
|
-
var
|
|
39
|
-
|
|
40
|
+
// src/generic.ts
|
|
41
|
+
var isBrowser = typeof window !== 'undefined';
|
|
42
|
+
var inject = ({ beforeSend } = {}) => {
|
|
43
|
+
var _a;
|
|
44
|
+
if (!isBrowser) return;
|
|
40
45
|
initQueue();
|
|
41
|
-
|
|
46
|
+
if (beforeSend) {
|
|
47
|
+
(_a = window.va) == null
|
|
48
|
+
? void 0
|
|
49
|
+
: _a.call(window, 'beforeSend', beforeSend);
|
|
50
|
+
}
|
|
51
|
+
if (document.head.querySelector('script[src="/va/script.js"]')) return;
|
|
52
|
+
const script = document.createElement('script');
|
|
53
|
+
script.src = '/va/script.js';
|
|
54
|
+
script.async = true;
|
|
55
|
+
document.head.appendChild(script);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// src/react.tsx
|
|
59
|
+
var import_jsx_runtime = require('react/jsx-runtime');
|
|
42
60
|
function Analytics(props) {
|
|
43
|
-
if (process.env.NODE_ENV !==
|
|
61
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
44
62
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(NoopAnalytics, {});
|
|
45
63
|
}
|
|
46
64
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EnabledAnalytics, {
|
|
47
|
-
...props
|
|
65
|
+
...props,
|
|
48
66
|
});
|
|
49
67
|
}
|
|
50
68
|
function EnabledAnalytics({ beforeSend }) {
|
|
51
69
|
(0, import_react.useEffect)(() => {
|
|
52
|
-
|
|
53
|
-
if (beforeSend) {
|
|
54
|
-
(_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", beforeSend);
|
|
55
|
-
}
|
|
70
|
+
inject({ beforeSend });
|
|
56
71
|
}, [beforeSend]);
|
|
57
|
-
return
|
|
58
|
-
async: true,
|
|
59
|
-
src: "/va/script.js"
|
|
60
|
-
});
|
|
72
|
+
return null;
|
|
61
73
|
}
|
|
62
74
|
function NoopAnalytics() {
|
|
63
75
|
(0, import_react.useEffect)(() => {
|
|
64
76
|
console.warn(
|
|
65
|
-
|
|
77
|
+
'Vercel Analytics is set up, but detected a non-production environment.\n\nPlease note that no analytics events will be sent.',
|
|
66
78
|
);
|
|
67
79
|
}, []);
|
|
68
80
|
return null;
|
|
69
81
|
}
|
|
70
82
|
// Annotate the CommonJS export names for ESM import in node:
|
|
71
|
-
0 &&
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
83
|
+
0 &&
|
|
84
|
+
(module.exports = {
|
|
85
|
+
Analytics,
|
|
86
|
+
});
|
|
87
|
+
//# sourceMappingURL=index.cjs.map
|
package/dist/react/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/react.tsx","../../src/queue.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/react.tsx","../../src/queue.ts","../../src/generic.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport { inject } from './generic';\nimport type { BeforeSend } from './types';\n\ninterface AnalyticsProps {\n beforeSend?: BeforeSend;\n}\n\nexport function Analytics(props: AnalyticsProps): JSX.Element {\n if (process.env.NODE_ENV !== 'production') {\n return <NoopAnalytics />;\n }\n\n return <EnabledAnalytics {...props} />;\n}\n\nfunction EnabledAnalytics({ beforeSend }: AnalyticsProps): null {\n useEffect(() => {\n inject({ beforeSend });\n }, [beforeSend]);\n\n return null;\n}\n\nfunction NoopAnalytics(): null {\n useEffect(() => {\n // eslint-disable-next-line no-console\n console.warn(\n 'Vercel Analytics is set up, but detected a non-production environment.\\n\\nPlease note that no analytics events will be sent.',\n );\n }, []);\n\n return null;\n}\n","export const initQueue = (): void => {\n // initialise 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 { initQueue } from './queue';\nimport type { BeforeSend } from './types';\n\nconst isBrowser = typeof window !== 'undefined';\n\nexport const inject = ({\n beforeSend,\n}: { beforeSend?: BeforeSend } = {}): void => {\n if (!isBrowser) return;\n initQueue();\n\n if (beforeSend) {\n window.va?.('beforeSend', beforeSend);\n }\n\n if (document.head.querySelector('script[src=\"/va/script.js\"]')) return;\n\n const script = document.createElement('script');\n script.src = '/va/script.js';\n script.async = true;\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;;;ACJA,IAAM,YAAY,OAAO,WAAW;AAE7B,IAAM,SAAS,CAAC;AAAA,EACrB;AACF,IAAiC,CAAC,MAAY;AAP9C;AAQE,MAAI,CAAC;AAAW;AAChB,YAAU;AAEV,MAAI,YAAY;AACd,iBAAO,OAAP,gCAAY,cAAc;AAAA,EAC5B;AAEA,MAAI,SAAS,KAAK,cAAc,6BAA6B;AAAG;AAEhE,QAAM,SAAS,SAAS,cAAc,QAAQ;AAC9C,SAAO,MAAM;AACb,SAAO,QAAQ;AAEf,WAAS,KAAK,YAAY,MAAM;AAClC;;;AFZW;AAFJ,SAAS,UAAU,OAAoC;AAC5D,MAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,WAAO,4CAAC,iBAAc;AAAA,EACxB;AAEA,SAAO,4CAAC;AAAA,IAAkB,GAAG;AAAA,GAAO;AACtC;AAEA,SAAS,iBAAiB,EAAE,WAAW,GAAyB;AAC9D,8BAAU,MAAM;AACd,WAAO,EAAE,WAAW,CAAC;AAAA,EACvB,GAAG,CAAC,UAAU,CAAC;AAEf,SAAO;AACT;AAEA,SAAS,gBAAsB;AAC7B,8BAAU,MAAM;AAEd,YAAQ;AAAA,MACN;AAAA,IACF;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAAO;AACT;","names":[]}
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
interface PageViewEvent {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
type: 'pageview';
|
|
3
|
+
url: string;
|
|
4
4
|
}
|
|
5
5
|
declare type IEvent = PageViewEvent;
|
|
6
6
|
declare type BeforeSend = (event: IEvent) => IEvent | null;
|
|
7
7
|
declare global {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
interface Window {
|
|
9
|
+
va?: (event: string, properties?: unknown) => void;
|
|
10
|
+
vaq?: [event: string, properties?: unknown][];
|
|
11
|
+
vai?: boolean;
|
|
12
|
+
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
interface AnalyticsProps {
|
|
16
|
-
|
|
16
|
+
beforeSend?: BeforeSend;
|
|
17
17
|
}
|
|
18
18
|
declare function Analytics(props: AnalyticsProps): JSX.Element;
|
|
19
19
|
|
package/dist/react/index.js
CHANGED
|
@@ -1,49 +1,55 @@
|
|
|
1
1
|
// src/react.tsx
|
|
2
|
-
import { useEffect } from
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
3
|
|
|
4
4
|
// src/queue.ts
|
|
5
5
|
var initQueue = () => {
|
|
6
|
-
if (window.va)
|
|
7
|
-
return;
|
|
6
|
+
if (window.va) return;
|
|
8
7
|
window.va = function a(...params) {
|
|
9
8
|
(window.vaq = window.vaq || []).push(params);
|
|
10
9
|
};
|
|
11
10
|
};
|
|
12
11
|
|
|
13
|
-
// src/
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
// src/generic.ts
|
|
13
|
+
var isBrowser = typeof window !== 'undefined';
|
|
14
|
+
var inject = ({ beforeSend } = {}) => {
|
|
15
|
+
var _a;
|
|
16
|
+
if (!isBrowser) return;
|
|
16
17
|
initQueue();
|
|
17
|
-
|
|
18
|
+
if (beforeSend) {
|
|
19
|
+
(_a = window.va) == null
|
|
20
|
+
? void 0
|
|
21
|
+
: _a.call(window, 'beforeSend', beforeSend);
|
|
22
|
+
}
|
|
23
|
+
if (document.head.querySelector('script[src="/va/script.js"]')) return;
|
|
24
|
+
const script = document.createElement('script');
|
|
25
|
+
script.src = '/va/script.js';
|
|
26
|
+
script.async = true;
|
|
27
|
+
document.head.appendChild(script);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// src/react.tsx
|
|
31
|
+
import { jsx } from 'react/jsx-runtime';
|
|
18
32
|
function Analytics(props) {
|
|
19
|
-
if (process.env.NODE_ENV !==
|
|
33
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
20
34
|
return /* @__PURE__ */ jsx(NoopAnalytics, {});
|
|
21
35
|
}
|
|
22
36
|
return /* @__PURE__ */ jsx(EnabledAnalytics, {
|
|
23
|
-
...props
|
|
37
|
+
...props,
|
|
24
38
|
});
|
|
25
39
|
}
|
|
26
40
|
function EnabledAnalytics({ beforeSend }) {
|
|
27
41
|
useEffect(() => {
|
|
28
|
-
|
|
29
|
-
if (beforeSend) {
|
|
30
|
-
(_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", beforeSend);
|
|
31
|
-
}
|
|
42
|
+
inject({ beforeSend });
|
|
32
43
|
}, [beforeSend]);
|
|
33
|
-
return
|
|
34
|
-
async: true,
|
|
35
|
-
src: "/va/script.js"
|
|
36
|
-
});
|
|
44
|
+
return null;
|
|
37
45
|
}
|
|
38
46
|
function NoopAnalytics() {
|
|
39
47
|
useEffect(() => {
|
|
40
48
|
console.warn(
|
|
41
|
-
|
|
49
|
+
'Vercel Analytics is set up, but detected a non-production environment.\n\nPlease note that no analytics events will be sent.',
|
|
42
50
|
);
|
|
43
51
|
}, []);
|
|
44
52
|
return null;
|
|
45
53
|
}
|
|
46
|
-
export {
|
|
47
|
-
|
|
48
|
-
};
|
|
49
|
-
//# sourceMappingURL=index.js.map
|
|
54
|
+
export { Analytics };
|
|
55
|
+
//# sourceMappingURL=index.js.map
|
package/dist/react/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/react.tsx","../../src/queue.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/react.tsx","../../src/queue.ts","../../src/generic.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport { inject } from './generic';\nimport type { BeforeSend } from './types';\n\ninterface AnalyticsProps {\n beforeSend?: BeforeSend;\n}\n\nexport function Analytics(props: AnalyticsProps): JSX.Element {\n if (process.env.NODE_ENV !== 'production') {\n return <NoopAnalytics />;\n }\n\n return <EnabledAnalytics {...props} />;\n}\n\nfunction EnabledAnalytics({ beforeSend }: AnalyticsProps): null {\n useEffect(() => {\n inject({ beforeSend });\n }, [beforeSend]);\n\n return null;\n}\n\nfunction NoopAnalytics(): null {\n useEffect(() => {\n // eslint-disable-next-line no-console\n console.warn(\n 'Vercel Analytics is set up, but detected a non-production environment.\\n\\nPlease note that no analytics events will be sent.',\n );\n }, []);\n\n return null;\n}\n","export const initQueue = (): void => {\n // initialise 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 { initQueue } from './queue';\nimport type { BeforeSend } from './types';\n\nconst isBrowser = typeof window !== 'undefined';\n\nexport const inject = ({\n beforeSend,\n}: { beforeSend?: BeforeSend } = {}): void => {\n if (!isBrowser) return;\n initQueue();\n\n if (beforeSend) {\n window.va?.('beforeSend', beforeSend);\n }\n\n if (document.head.querySelector('script[src=\"/va/script.js\"]')) return;\n\n const script = document.createElement('script');\n script.src = '/va/script.js';\n script.async = true;\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;;;ACJA,IAAM,YAAY,OAAO,WAAW;AAE7B,IAAM,SAAS,CAAC;AAAA,EACrB;AACF,IAAiC,CAAC,MAAY;AAP9C;AAQE,MAAI,CAAC;AAAW;AAChB,YAAU;AAEV,MAAI,YAAY;AACd,iBAAO,OAAP,gCAAY,cAAc;AAAA,EAC5B;AAEA,MAAI,SAAS,KAAK,cAAc,6BAA6B;AAAG;AAEhE,QAAM,SAAS,SAAS,cAAc,QAAQ;AAC9C,SAAO,MAAM;AACb,SAAO,QAAQ;AAEf,WAAS,KAAK,YAAY,MAAM;AAClC;;;AFZW;AAFJ,SAAS,UAAU,OAAoC;AAC5D,MAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,WAAO,oBAAC,iBAAc;AAAA,EACxB;AAEA,SAAO,oBAAC;AAAA,IAAkB,GAAG;AAAA,GAAO;AACtC;AAEA,SAAS,iBAAiB,EAAE,WAAW,GAAyB;AAC9D,YAAU,MAAM;AACd,WAAO,EAAE,WAAW,CAAC;AAAA,EACvB,GAAG,CAAC,UAAU,CAAC;AAEf,SAAO;AACT;AAEA,SAAS,gBAAsB;AAC7B,YAAU,MAAM;AAEd,YAAQ;AAAA,MACN;AAAA,IACF;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAAO;AACT;","names":[]}
|