@vercel/analytics 0.1.3 → 0.1.4
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 +16 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.js +16 -7
- package/dist/index.js.map +1 -1
- package/dist/react/index.cjs +23 -33
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.ts +5 -4
- package/dist/react/index.js +23 -27
- package/dist/react/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -33,23 +33,32 @@ var initQueue = () => {
|
|
|
33
33
|
};
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
+
// src/utils.ts
|
|
37
|
+
function isBrowser() {
|
|
38
|
+
return typeof window !== "undefined";
|
|
39
|
+
}
|
|
40
|
+
function isDevelopment() {
|
|
41
|
+
return typeof process !== "undefined" && process.env.NODE_ENV !== "production";
|
|
42
|
+
}
|
|
43
|
+
|
|
36
44
|
// src/generic.ts
|
|
37
|
-
var
|
|
38
|
-
var inject = ({
|
|
39
|
-
beforeSend
|
|
40
|
-
} = {}) => {
|
|
45
|
+
var inject = ({ beforeSend, debug } = { debug: isDevelopment() }) => {
|
|
41
46
|
var _a;
|
|
42
|
-
if (!isBrowser)
|
|
47
|
+
if (!isBrowser())
|
|
43
48
|
return;
|
|
44
49
|
initQueue();
|
|
45
50
|
if (beforeSend) {
|
|
46
51
|
(_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", beforeSend);
|
|
47
52
|
}
|
|
48
|
-
|
|
53
|
+
const src = isDevelopment() ? "https://cdn.vercel-insights.com/v1/script.debug.js" : "/_vercel/insights/script.js";
|
|
54
|
+
if (document.head.querySelector(`script[src*="${src}"]`))
|
|
49
55
|
return;
|
|
50
56
|
const script = document.createElement("script");
|
|
51
|
-
script.src =
|
|
57
|
+
script.src = src;
|
|
52
58
|
script.defer = true;
|
|
59
|
+
if (isDevelopment() && debug === false) {
|
|
60
|
+
script.setAttribute("data-debug", "false");
|
|
61
|
+
}
|
|
53
62
|
document.head.appendChild(script);
|
|
54
63
|
};
|
|
55
64
|
// Annotate the CommonJS export names for ESM import in node:
|
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 {
|
|
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, isDevelopment } from './utils';\n\nexport const inject = (\n { beforeSend, debug }: AnalyticsProps = { debug: isDevelopment() },\n): void => {\n if (!isBrowser()) return;\n initQueue();\n\n if (beforeSend) {\n window.va?.('beforeSend', beforeSend);\n }\n const src = isDevelopment()\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 (isDevelopment() && debug === false) {\n script.setAttribute('data-debug', 'false');\n }\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","export function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nexport function isDevelopment(): boolean {\n return (\n typeof process !== 'undefined' && process.env.NODE_ENV !== 'production'\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;;;ACPO,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;AAEO,SAAS,gBAAyB;AACvC,SACE,OAAO,YAAY,eAAe,QAAQ,IAAI,aAAa;AAE/D;;;AFJO,IAAM,SAAS,CACpB,EAAE,YAAY,MAAM,IAAoB,EAAE,OAAO,cAAc,EAAE,MACxD;AANX;AAOE,MAAI,CAAC,UAAU;AAAG;AAClB,YAAU;AAEV,MAAI,YAAY;AACd,iBAAO,OAAP,gCAAY,cAAc;AAAA,EAC5B;AACA,QAAM,MAAM,cAAc,IACtB,uDACA;AAEJ,MAAI,SAAS,KAAK,cAAc,gBAAgB,OAAO;AAAG;AAE1D,QAAM,SAAS,SAAS,cAAc,QAAQ;AAC9C,SAAO,MAAM;AACb,SAAO,QAAQ;AAEf,MAAI,cAAc,KAAK,UAAU,OAAO;AACtC,WAAO,aAAa,cAAc,OAAO;AAAA,EAC3C;AAEA,WAAS,KAAK,YAAY,MAAM;AAClC;","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,10 @@ interface PageViewEvent {
|
|
|
4
4
|
}
|
|
5
5
|
declare type IEvent = PageViewEvent;
|
|
6
6
|
declare type BeforeSend = (event: IEvent) => IEvent | null;
|
|
7
|
+
interface AnalyticsProps {
|
|
8
|
+
beforeSend?: BeforeSend;
|
|
9
|
+
debug?: boolean;
|
|
10
|
+
}
|
|
7
11
|
declare global {
|
|
8
12
|
interface Window {
|
|
9
13
|
va?: (event: string, properties?: unknown) => void;
|
|
@@ -12,8 +16,6 @@ declare global {
|
|
|
12
16
|
}
|
|
13
17
|
}
|
|
14
18
|
|
|
15
|
-
declare const inject: ({ beforeSend, }?:
|
|
16
|
-
beforeSend?: BeforeSend | undefined;
|
|
17
|
-
}) => void;
|
|
19
|
+
declare const inject: ({ beforeSend, debug }?: AnalyticsProps) => void;
|
|
18
20
|
|
|
19
21
|
export { inject };
|
package/dist/index.js
CHANGED
|
@@ -7,23 +7,32 @@ var initQueue = () => {
|
|
|
7
7
|
};
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
+
// src/utils.ts
|
|
11
|
+
function isBrowser() {
|
|
12
|
+
return typeof window !== "undefined";
|
|
13
|
+
}
|
|
14
|
+
function isDevelopment() {
|
|
15
|
+
return typeof process !== "undefined" && process.env.NODE_ENV !== "production";
|
|
16
|
+
}
|
|
17
|
+
|
|
10
18
|
// src/generic.ts
|
|
11
|
-
var
|
|
12
|
-
var inject = ({
|
|
13
|
-
beforeSend
|
|
14
|
-
} = {}) => {
|
|
19
|
+
var inject = ({ beforeSend, debug } = { debug: isDevelopment() }) => {
|
|
15
20
|
var _a;
|
|
16
|
-
if (!isBrowser)
|
|
21
|
+
if (!isBrowser())
|
|
17
22
|
return;
|
|
18
23
|
initQueue();
|
|
19
24
|
if (beforeSend) {
|
|
20
25
|
(_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", beforeSend);
|
|
21
26
|
}
|
|
22
|
-
|
|
27
|
+
const src = isDevelopment() ? "https://cdn.vercel-insights.com/v1/script.debug.js" : "/_vercel/insights/script.js";
|
|
28
|
+
if (document.head.querySelector(`script[src*="${src}"]`))
|
|
23
29
|
return;
|
|
24
30
|
const script = document.createElement("script");
|
|
25
|
-
script.src =
|
|
31
|
+
script.src = src;
|
|
26
32
|
script.defer = true;
|
|
33
|
+
if (isDevelopment() && debug === false) {
|
|
34
|
+
script.setAttribute("data-debug", "false");
|
|
35
|
+
}
|
|
27
36
|
document.head.appendChild(script);
|
|
28
37
|
};
|
|
29
38
|
export {
|
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 {
|
|
1
|
+
{"version":3,"sources":["../src/queue.ts","../src/utils.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","export function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nexport function isDevelopment(): boolean {\n return (\n typeof process !== 'undefined' && process.env.NODE_ENV !== 'production'\n );\n}\n","import { initQueue } from './queue';\nimport type { AnalyticsProps } from './types';\nimport { isBrowser, isDevelopment } from './utils';\n\nexport const inject = (\n { beforeSend, debug }: AnalyticsProps = { debug: isDevelopment() },\n): void => {\n if (!isBrowser()) return;\n initQueue();\n\n if (beforeSend) {\n window.va?.('beforeSend', beforeSend);\n }\n const src = isDevelopment()\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 (isDevelopment() && 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;;;ACPO,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;AAEO,SAAS,gBAAyB;AACvC,SACE,OAAO,YAAY,eAAe,QAAQ,IAAI,aAAa;AAE/D;;;ACJO,IAAM,SAAS,CACpB,EAAE,YAAY,MAAM,IAAoB,EAAE,OAAO,cAAc,EAAE,MACxD;AANX;AAOE,MAAI,CAAC,UAAU;AAAG;AAClB,YAAU;AAEV,MAAI,YAAY;AACd,iBAAO,OAAP,gCAAY,cAAc;AAAA,EAC5B;AACA,QAAM,MAAM,cAAc,IACtB,uDACA;AAEJ,MAAI,SAAS,KAAK,cAAc,gBAAgB,OAAO;AAAG;AAE1D,QAAM,SAAS,SAAS,cAAc,QAAQ;AAC9C,SAAO,MAAM;AACb,SAAO,QAAQ;AAEf,MAAI,cAAc,KAAK,UAAU,OAAO;AACtC,WAAO,aAAa,cAAc,OAAO;AAAA,EAC3C;AAEA,WAAS,KAAK,YAAY,MAAM;AAClC;","names":[]}
|
package/dist/react/index.cjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,10 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
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
|
-
));
|
|
24
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
19
|
|
|
26
20
|
// src/react.tsx
|
|
@@ -29,7 +23,7 @@ __export(react_exports, {
|
|
|
29
23
|
Analytics: () => Analytics
|
|
30
24
|
});
|
|
31
25
|
module.exports = __toCommonJS(react_exports);
|
|
32
|
-
var import_react =
|
|
26
|
+
var import_react = require("react");
|
|
33
27
|
|
|
34
28
|
// src/queue.ts
|
|
35
29
|
var initQueue = () => {
|
|
@@ -40,47 +34,43 @@ var initQueue = () => {
|
|
|
40
34
|
};
|
|
41
35
|
};
|
|
42
36
|
|
|
37
|
+
// src/utils.ts
|
|
38
|
+
function isBrowser() {
|
|
39
|
+
return typeof window !== "undefined";
|
|
40
|
+
}
|
|
41
|
+
function isDevelopment() {
|
|
42
|
+
return typeof process !== "undefined" && process.env.NODE_ENV !== "production";
|
|
43
|
+
}
|
|
44
|
+
|
|
43
45
|
// src/generic.ts
|
|
44
|
-
var
|
|
45
|
-
var inject = ({
|
|
46
|
-
beforeSend
|
|
47
|
-
} = {}) => {
|
|
46
|
+
var inject = ({ beforeSend, debug } = { debug: isDevelopment() }) => {
|
|
48
47
|
var _a;
|
|
49
|
-
if (!isBrowser)
|
|
48
|
+
if (!isBrowser())
|
|
50
49
|
return;
|
|
51
50
|
initQueue();
|
|
52
51
|
if (beforeSend) {
|
|
53
52
|
(_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", beforeSend);
|
|
54
53
|
}
|
|
55
|
-
|
|
54
|
+
const src = isDevelopment() ? "https://cdn.vercel-insights.com/v1/script.debug.js" : "/_vercel/insights/script.js";
|
|
55
|
+
if (document.head.querySelector(`script[src*="${src}"]`))
|
|
56
56
|
return;
|
|
57
57
|
const script = document.createElement("script");
|
|
58
|
-
script.src =
|
|
58
|
+
script.src = src;
|
|
59
59
|
script.defer = true;
|
|
60
|
+
if (isDevelopment() && debug === false) {
|
|
61
|
+
script.setAttribute("data-debug", "false");
|
|
62
|
+
}
|
|
60
63
|
document.head.appendChild(script);
|
|
61
64
|
};
|
|
62
65
|
|
|
63
66
|
// src/react.tsx
|
|
64
|
-
function Analytics(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return /* @__PURE__ */ import_react.default.createElement(EnabledAnalytics, {
|
|
69
|
-
...props
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
function EnabledAnalytics({ beforeSend }) {
|
|
73
|
-
(0, import_react.useEffect)(() => {
|
|
74
|
-
inject({ beforeSend });
|
|
75
|
-
}, [beforeSend]);
|
|
76
|
-
return null;
|
|
77
|
-
}
|
|
78
|
-
function NoopAnalytics() {
|
|
67
|
+
function Analytics({
|
|
68
|
+
beforeSend,
|
|
69
|
+
debug = isDevelopment()
|
|
70
|
+
}) {
|
|
79
71
|
(0, import_react.useEffect)(() => {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
);
|
|
83
|
-
}, []);
|
|
72
|
+
inject({ beforeSend, debug });
|
|
73
|
+
}, [beforeSend, debug]);
|
|
84
74
|
return null;
|
|
85
75
|
}
|
|
86
76
|
// 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/generic.ts"],"sourcesContent":["import
|
|
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';\nimport { isDevelopment } from './utils';\n\nexport function Analytics({\n beforeSend,\n debug = isDevelopment(),\n}: AnalyticsProps): null {\n useEffect(() => {\n inject({ beforeSend, debug });\n }, [beforeSend, debug]);\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","export function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nexport function isDevelopment(): boolean {\n return (\n typeof process !== 'undefined' && process.env.NODE_ENV !== 'production'\n );\n}\n","import { initQueue } from './queue';\nimport type { AnalyticsProps } from './types';\nimport { isBrowser, isDevelopment } from './utils';\n\nexport const inject = (\n { beforeSend, debug }: AnalyticsProps = { debug: isDevelopment() },\n): void => {\n if (!isBrowser()) return;\n initQueue();\n\n if (beforeSend) {\n window.va?.('beforeSend', beforeSend);\n }\n const src = isDevelopment()\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 (isDevelopment() && 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;;;ACPO,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;AAEO,SAAS,gBAAyB;AACvC,SACE,OAAO,YAAY,eAAe,QAAQ,IAAI,aAAa;AAE/D;;;ACJO,IAAM,SAAS,CACpB,EAAE,YAAY,MAAM,IAAoB,EAAE,OAAO,cAAc,EAAE,MACxD;AANX;AAOE,MAAI,CAAC,UAAU;AAAG;AAClB,YAAU;AAEV,MAAI,YAAY;AACd,iBAAO,OAAP,gCAAY,cAAc;AAAA,EAC5B;AACA,QAAM,MAAM,cAAc,IACtB,uDACA;AAEJ,MAAI,SAAS,KAAK,cAAc,gBAAgB,OAAO;AAAG;AAE1D,QAAM,SAAS,SAAS,cAAc,QAAQ;AAC9C,SAAO,MAAM;AACb,SAAO,QAAQ;AAEf,MAAI,cAAc,KAAK,UAAU,OAAO;AACtC,WAAO,aAAa,cAAc,OAAO;AAAA,EAC3C;AAEA,WAAS,KAAK,YAAY,MAAM;AAClC;;;AHvBO,SAAS,UAAU;AAAA,EACxB;AAAA,EACA,QAAQ,cAAc;AACxB,GAAyB;AACvB,8BAAU,MAAM;AACd,WAAO,EAAE,YAAY,MAAM,CAAC;AAAA,EAC9B,GAAG,CAAC,YAAY,KAAK,CAAC;AAEtB,SAAO;AACT;","names":[]}
|
package/dist/react/index.d.ts
CHANGED
|
@@ -4,6 +4,10 @@ interface PageViewEvent {
|
|
|
4
4
|
}
|
|
5
5
|
declare type IEvent = PageViewEvent;
|
|
6
6
|
declare type BeforeSend = (event: IEvent) => IEvent | null;
|
|
7
|
+
interface AnalyticsProps {
|
|
8
|
+
beforeSend?: BeforeSend;
|
|
9
|
+
debug?: boolean;
|
|
10
|
+
}
|
|
7
11
|
declare global {
|
|
8
12
|
interface Window {
|
|
9
13
|
va?: (event: string, properties?: unknown) => void;
|
|
@@ -12,9 +16,6 @@ declare global {
|
|
|
12
16
|
}
|
|
13
17
|
}
|
|
14
18
|
|
|
15
|
-
|
|
16
|
-
beforeSend?: BeforeSend;
|
|
17
|
-
}
|
|
18
|
-
declare function Analytics(props: AnalyticsProps): JSX.Element;
|
|
19
|
+
declare function Analytics({ beforeSend, debug, }: AnalyticsProps): null;
|
|
19
20
|
|
|
20
21
|
export { Analytics };
|
package/dist/react/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/react.tsx
|
|
2
|
-
import
|
|
2
|
+
import { useEffect } from "react";
|
|
3
3
|
|
|
4
4
|
// src/queue.ts
|
|
5
5
|
var initQueue = () => {
|
|
@@ -10,47 +10,43 @@ var initQueue = () => {
|
|
|
10
10
|
};
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
+
// src/utils.ts
|
|
14
|
+
function isBrowser() {
|
|
15
|
+
return typeof window !== "undefined";
|
|
16
|
+
}
|
|
17
|
+
function isDevelopment() {
|
|
18
|
+
return typeof process !== "undefined" && process.env.NODE_ENV !== "production";
|
|
19
|
+
}
|
|
20
|
+
|
|
13
21
|
// src/generic.ts
|
|
14
|
-
var
|
|
15
|
-
var inject = ({
|
|
16
|
-
beforeSend
|
|
17
|
-
} = {}) => {
|
|
22
|
+
var inject = ({ beforeSend, debug } = { debug: isDevelopment() }) => {
|
|
18
23
|
var _a;
|
|
19
|
-
if (!isBrowser)
|
|
24
|
+
if (!isBrowser())
|
|
20
25
|
return;
|
|
21
26
|
initQueue();
|
|
22
27
|
if (beforeSend) {
|
|
23
28
|
(_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", beforeSend);
|
|
24
29
|
}
|
|
25
|
-
|
|
30
|
+
const src = isDevelopment() ? "https://cdn.vercel-insights.com/v1/script.debug.js" : "/_vercel/insights/script.js";
|
|
31
|
+
if (document.head.querySelector(`script[src*="${src}"]`))
|
|
26
32
|
return;
|
|
27
33
|
const script = document.createElement("script");
|
|
28
|
-
script.src =
|
|
34
|
+
script.src = src;
|
|
29
35
|
script.defer = true;
|
|
36
|
+
if (isDevelopment() && debug === false) {
|
|
37
|
+
script.setAttribute("data-debug", "false");
|
|
38
|
+
}
|
|
30
39
|
document.head.appendChild(script);
|
|
31
40
|
};
|
|
32
41
|
|
|
33
42
|
// src/react.tsx
|
|
34
|
-
function Analytics(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return /* @__PURE__ */ React.createElement(EnabledAnalytics, {
|
|
39
|
-
...props
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
function EnabledAnalytics({ beforeSend }) {
|
|
43
|
-
useEffect(() => {
|
|
44
|
-
inject({ beforeSend });
|
|
45
|
-
}, [beforeSend]);
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
function NoopAnalytics() {
|
|
43
|
+
function Analytics({
|
|
44
|
+
beforeSend,
|
|
45
|
+
debug = isDevelopment()
|
|
46
|
+
}) {
|
|
49
47
|
useEffect(() => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
);
|
|
53
|
-
}, []);
|
|
48
|
+
inject({ beforeSend, debug });
|
|
49
|
+
}, [beforeSend, debug]);
|
|
54
50
|
return null;
|
|
55
51
|
}
|
|
56
52
|
export {
|
package/dist/react/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/react.tsx","../../src/queue.ts","../../src/generic.ts"],"sourcesContent":["import
|
|
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';\nimport { isDevelopment } from './utils';\n\nexport function Analytics({\n beforeSend,\n debug = isDevelopment(),\n}: AnalyticsProps): null {\n useEffect(() => {\n inject({ beforeSend, debug });\n }, [beforeSend, debug]);\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","export function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nexport function isDevelopment(): boolean {\n return (\n typeof process !== 'undefined' && process.env.NODE_ENV !== 'production'\n );\n}\n","import { initQueue } from './queue';\nimport type { AnalyticsProps } from './types';\nimport { isBrowser, isDevelopment } from './utils';\n\nexport const inject = (\n { beforeSend, debug }: AnalyticsProps = { debug: isDevelopment() },\n): void => {\n if (!isBrowser()) return;\n initQueue();\n\n if (beforeSend) {\n window.va?.('beforeSend', beforeSend);\n }\n const src = isDevelopment()\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 (isDevelopment() && 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;;;ACPO,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;AAEO,SAAS,gBAAyB;AACvC,SACE,OAAO,YAAY,eAAe,QAAQ,IAAI,aAAa;AAE/D;;;ACJO,IAAM,SAAS,CACpB,EAAE,YAAY,MAAM,IAAoB,EAAE,OAAO,cAAc,EAAE,MACxD;AANX;AAOE,MAAI,CAAC,UAAU;AAAG;AAClB,YAAU;AAEV,MAAI,YAAY;AACd,iBAAO,OAAP,gCAAY,cAAc;AAAA,EAC5B;AACA,QAAM,MAAM,cAAc,IACtB,uDACA;AAEJ,MAAI,SAAS,KAAK,cAAc,gBAAgB,OAAO;AAAG;AAE1D,QAAM,SAAS,SAAS,cAAc,QAAQ;AAC9C,SAAO,MAAM;AACb,SAAO,QAAQ;AAEf,MAAI,cAAc,KAAK,UAAU,OAAO;AACtC,WAAO,aAAa,cAAc,OAAO;AAAA,EAC3C;AAEA,WAAS,KAAK,YAAY,MAAM;AAClC;;;AHvBO,SAAS,UAAU;AAAA,EACxB;AAAA,EACA,QAAQ,cAAc;AACxB,GAAyB;AACvB,YAAU,MAAM;AACd,WAAO,EAAE,YAAY,MAAM,CAAC;AAAA,EAC9B,GAAG,CAAC,YAAY,KAAK,CAAC;AAEtB,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.4",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"analytics",
|
|
6
6
|
"vercel"
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"build": "tsup",
|
|
49
|
+
"dev": "tsup --watch",
|
|
49
50
|
"lint": "eslint .",
|
|
50
51
|
"lint-fix": "eslint . --fix",
|
|
51
52
|
"type-check": "tsc --noEmit"
|