@vercel/analytics 0.1.0 → 0.1.2
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 +3 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/react/index.cjs +31 -15
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +25 -15
- package/dist/react/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -39,12 +39,14 @@ var inject = ({
|
|
|
39
39
|
beforeSend
|
|
40
40
|
} = {}) => {
|
|
41
41
|
var _a;
|
|
42
|
-
if (!isBrowser
|
|
42
|
+
if (!isBrowser)
|
|
43
43
|
return;
|
|
44
44
|
initQueue();
|
|
45
45
|
if (beforeSend) {
|
|
46
46
|
(_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", beforeSend);
|
|
47
47
|
}
|
|
48
|
+
if (document.head.querySelector('script[src="/va/script.js"]'))
|
|
49
|
+
return;
|
|
48
50
|
const script = document.createElement("script");
|
|
49
51
|
script.src = "/va/script.js";
|
|
50
52
|
script.async = true;
|
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.js
CHANGED
|
@@ -13,12 +13,14 @@ var inject = ({
|
|
|
13
13
|
beforeSend
|
|
14
14
|
} = {}) => {
|
|
15
15
|
var _a;
|
|
16
|
-
if (!isBrowser
|
|
16
|
+
if (!isBrowser)
|
|
17
17
|
return;
|
|
18
18
|
initQueue();
|
|
19
19
|
if (beforeSend) {
|
|
20
20
|
(_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", beforeSend);
|
|
21
21
|
}
|
|
22
|
+
if (document.head.querySelector('script[src="/va/script.js"]'))
|
|
23
|
+
return;
|
|
22
24
|
const script = document.createElement("script");
|
|
23
25
|
script.src = "/va/script.js";
|
|
24
26
|
script.async = true;
|
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,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
18
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
25
|
|
|
20
26
|
// src/react.tsx
|
|
@@ -23,7 +29,7 @@ __export(react_exports, {
|
|
|
23
29
|
Analytics: () => Analytics
|
|
24
30
|
});
|
|
25
31
|
module.exports = __toCommonJS(react_exports);
|
|
26
|
-
var import_react = require("react");
|
|
32
|
+
var import_react = __toESM(require("react"), 1);
|
|
27
33
|
|
|
28
34
|
// src/queue.ts
|
|
29
35
|
var initQueue = () => {
|
|
@@ -34,30 +40,40 @@ var initQueue = () => {
|
|
|
34
40
|
};
|
|
35
41
|
};
|
|
36
42
|
|
|
37
|
-
// src/
|
|
38
|
-
var
|
|
39
|
-
|
|
43
|
+
// src/generic.ts
|
|
44
|
+
var isBrowser = typeof window !== "undefined";
|
|
45
|
+
var inject = ({
|
|
46
|
+
beforeSend
|
|
47
|
+
} = {}) => {
|
|
48
|
+
var _a;
|
|
49
|
+
if (!isBrowser)
|
|
50
|
+
return;
|
|
40
51
|
initQueue();
|
|
41
|
-
|
|
52
|
+
if (beforeSend) {
|
|
53
|
+
(_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", beforeSend);
|
|
54
|
+
}
|
|
55
|
+
if (document.head.querySelector('script[src="/va/script.js"]'))
|
|
56
|
+
return;
|
|
57
|
+
const script = document.createElement("script");
|
|
58
|
+
script.src = "/va/script.js";
|
|
59
|
+
script.async = true;
|
|
60
|
+
document.head.appendChild(script);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// src/react.tsx
|
|
42
64
|
function Analytics(props) {
|
|
43
65
|
if (process.env.NODE_ENV !== "production") {
|
|
44
|
-
return /* @__PURE__ */
|
|
66
|
+
return /* @__PURE__ */ import_react.default.createElement(NoopAnalytics, null);
|
|
45
67
|
}
|
|
46
|
-
return /* @__PURE__ */
|
|
68
|
+
return /* @__PURE__ */ import_react.default.createElement(EnabledAnalytics, {
|
|
47
69
|
...props
|
|
48
70
|
});
|
|
49
71
|
}
|
|
50
72
|
function EnabledAnalytics({ beforeSend }) {
|
|
51
73
|
(0, import_react.useEffect)(() => {
|
|
52
|
-
|
|
53
|
-
if (beforeSend) {
|
|
54
|
-
(_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", beforeSend);
|
|
55
|
-
}
|
|
74
|
+
inject({ beforeSend });
|
|
56
75
|
}, [beforeSend]);
|
|
57
|
-
return
|
|
58
|
-
async: true,
|
|
59
|
-
src: "/va/script.js"
|
|
60
|
-
});
|
|
76
|
+
return null;
|
|
61
77
|
}
|
|
62
78
|
function NoopAnalytics() {
|
|
63
79
|
(0, import_react.useEffect)(() => {
|
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 React, { 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,mBAAiC;;;ACA1B,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;;;AFdO,SAAS,UAAU,OAAoC;AAC5D,MAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,WAAO,6BAAAA,QAAA,cAAC,mBAAc;AAAA,EACxB;AAEA,SAAO,6BAAAA,QAAA,cAAC;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":["React"]}
|
package/dist/react/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/react.tsx
|
|
2
|
-
import { useEffect } from "react";
|
|
2
|
+
import React, { useEffect } from "react";
|
|
3
3
|
|
|
4
4
|
// src/queue.ts
|
|
5
5
|
var initQueue = () => {
|
|
@@ -10,30 +10,40 @@ var initQueue = () => {
|
|
|
10
10
|
};
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
// src/
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
// src/generic.ts
|
|
14
|
+
var isBrowser = typeof window !== "undefined";
|
|
15
|
+
var inject = ({
|
|
16
|
+
beforeSend
|
|
17
|
+
} = {}) => {
|
|
18
|
+
var _a;
|
|
19
|
+
if (!isBrowser)
|
|
20
|
+
return;
|
|
16
21
|
initQueue();
|
|
17
|
-
|
|
22
|
+
if (beforeSend) {
|
|
23
|
+
(_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", beforeSend);
|
|
24
|
+
}
|
|
25
|
+
if (document.head.querySelector('script[src="/va/script.js"]'))
|
|
26
|
+
return;
|
|
27
|
+
const script = document.createElement("script");
|
|
28
|
+
script.src = "/va/script.js";
|
|
29
|
+
script.async = true;
|
|
30
|
+
document.head.appendChild(script);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// src/react.tsx
|
|
18
34
|
function Analytics(props) {
|
|
19
35
|
if (process.env.NODE_ENV !== "production") {
|
|
20
|
-
return /* @__PURE__ */
|
|
36
|
+
return /* @__PURE__ */ React.createElement(NoopAnalytics, null);
|
|
21
37
|
}
|
|
22
|
-
return /* @__PURE__ */
|
|
38
|
+
return /* @__PURE__ */ React.createElement(EnabledAnalytics, {
|
|
23
39
|
...props
|
|
24
40
|
});
|
|
25
41
|
}
|
|
26
42
|
function EnabledAnalytics({ beforeSend }) {
|
|
27
43
|
useEffect(() => {
|
|
28
|
-
|
|
29
|
-
if (beforeSend) {
|
|
30
|
-
(_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", beforeSend);
|
|
31
|
-
}
|
|
44
|
+
inject({ beforeSend });
|
|
32
45
|
}, [beforeSend]);
|
|
33
|
-
return
|
|
34
|
-
async: true,
|
|
35
|
-
src: "/va/script.js"
|
|
36
|
-
});
|
|
46
|
+
return null;
|
|
37
47
|
}
|
|
38
48
|
function NoopAnalytics() {
|
|
39
49
|
useEffect(() => {
|
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 React, { 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,OAAO,SAAS,iBAAiB;;;ACA1B,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;;;AFdO,SAAS,UAAU,OAAoC;AAC5D,MAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,WAAO,oCAAC,mBAAc;AAAA,EACxB;AAEA,SAAO,oCAAC;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":[]}
|