@vercel/analytics 0.1.6-beta.0 → 0.1.6-beta.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/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  <div align="center">
7
7
  <a href="https://vercel.com/analytics">Website</a>
8
8
  <span> · </span>
9
- <a href="https://vercel.com/docs/concepts/analytics/audiences/quickstart">Documentation</a>
9
+ <a href="https://vercel.com/docs/concepts/analytics/audiences/package">Documentation</a>
10
10
  <span> · </span>
11
11
  <a href="https://twitter.com/vercel">Twitter</a>
12
12
  </div>
package/dist/index.cjs CHANGED
@@ -42,32 +42,23 @@ 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
- }
51
45
 
52
46
  // src/generic.ts
53
- var inject = (props = {
54
- debug: true
55
- }) => {
47
+ var inject = ({ beforeSend, debug } = { debug: isDevelopment() }) => {
56
48
  var _a;
57
49
  if (!isBrowser())
58
50
  return;
59
- const mode = getMode(props.__mode);
60
51
  initQueue();
61
- if (props.beforeSend) {
62
- (_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", props.beforeSend);
52
+ if (beforeSend) {
53
+ (_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", beforeSend);
63
54
  }
64
- const src = mode === "development" ? "https://cdn.vercel-insights.com/v1/script.debug.js" : "/_vercel/insights/script.js";
55
+ const src = isDevelopment() ? "https://cdn.vercel-insights.com/v1/script.debug.js" : "/_vercel/insights/script.js";
65
56
  if (document.head.querySelector(`script[src*="${src}"]`))
66
57
  return;
67
58
  const script = document.createElement("script");
68
59
  script.src = src;
69
60
  script.defer = true;
70
- if (mode === "development" && props.debug === false) {
61
+ if (isDevelopment() && debug === false) {
71
62
  script.setAttribute("data-debug", "false");
72
63
  }
73
64
  document.head.appendChild(script);
@@ -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, 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":[]}
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 if (typeof process === 'undefined') return false;\n return (\n process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test'\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,MAAI,OAAO,YAAY;AAAa,WAAO;AAC3C,SACE,QAAQ,IAAI,aAAa,iBAAiB,QAAQ,IAAI,aAAa;AAEvE;;;AFLO,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
@@ -2,13 +2,11 @@ interface PageViewEvent {
2
2
  type: 'pageview';
3
3
  url: string;
4
4
  }
5
- declare type Event = PageViewEvent;
6
- declare type Mode = 'auto' | 'development' | 'production';
7
- declare type BeforeSend = (event: Event) => Event | null;
5
+ declare type IEvent = PageViewEvent;
6
+ declare type BeforeSend = (event: IEvent) => IEvent | null;
8
7
  interface AnalyticsProps {
9
8
  beforeSend?: BeforeSend;
10
9
  debug?: boolean;
11
- __mode?: Mode;
12
10
  }
13
11
  declare global {
14
12
  interface Window {
@@ -18,6 +16,6 @@ declare global {
18
16
  }
19
17
  }
20
18
 
21
- declare const inject: (props?: AnalyticsProps) => void;
19
+ declare const inject: ({ beforeSend, debug }?: AnalyticsProps) => void;
22
20
 
23
21
  export { inject };
package/dist/index.js CHANGED
@@ -16,32 +16,23 @@ 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
- }
25
19
 
26
20
  // src/generic.ts
27
- var inject = (props = {
28
- debug: true
29
- }) => {
21
+ var inject = ({ beforeSend, debug } = { debug: isDevelopment() }) => {
30
22
  var _a;
31
23
  if (!isBrowser())
32
24
  return;
33
- const mode = getMode(props.__mode);
34
25
  initQueue();
35
- if (props.beforeSend) {
36
- (_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", props.beforeSend);
26
+ if (beforeSend) {
27
+ (_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", beforeSend);
37
28
  }
38
- const src = mode === "development" ? "https://cdn.vercel-insights.com/v1/script.debug.js" : "/_vercel/insights/script.js";
29
+ const src = isDevelopment() ? "https://cdn.vercel-insights.com/v1/script.debug.js" : "/_vercel/insights/script.js";
39
30
  if (document.head.querySelector(`script[src*="${src}"]`))
40
31
  return;
41
32
  const script = document.createElement("script");
42
33
  script.src = src;
43
34
  script.defer = true;
44
- if (mode === "development" && props.debug === false) {
35
+ if (isDevelopment() && debug === false) {
45
36
  script.setAttribute("data-debug", "false");
46
37
  }
47
38
  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 // 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":[]}
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 if (typeof process === 'undefined') return false;\n return (\n process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test'\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,MAAI,OAAO,YAAY;AAAa,WAAO;AAC3C,SACE,QAAQ,IAAI,aAAa,iBAAiB,QAAQ,IAAI,aAAa;AAEvE;;;ACLO,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":[]}
@@ -43,32 +43,23 @@ 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
- }
52
46
 
53
47
  // src/generic.ts
54
- var inject = (props = {
55
- debug: true
56
- }) => {
48
+ var inject = ({ beforeSend, debug } = { debug: isDevelopment() }) => {
57
49
  var _a;
58
50
  if (!isBrowser())
59
51
  return;
60
- const mode = getMode(props.__mode);
61
52
  initQueue();
62
- if (props.beforeSend) {
63
- (_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", props.beforeSend);
53
+ if (beforeSend) {
54
+ (_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", beforeSend);
64
55
  }
65
- const src = mode === "development" ? "https://cdn.vercel-insights.com/v1/script.debug.js" : "/_vercel/insights/script.js";
56
+ const src = isDevelopment() ? "https://cdn.vercel-insights.com/v1/script.debug.js" : "/_vercel/insights/script.js";
66
57
  if (document.head.querySelector(`script[src*="${src}"]`))
67
58
  return;
68
59
  const script = document.createElement("script");
69
60
  script.src = src;
70
61
  script.defer = true;
71
- if (mode === "development" && props.debug === false) {
62
+ if (isDevelopment() && debug === false) {
72
63
  script.setAttribute("data-debug", "false");
73
64
  }
74
65
  document.head.appendChild(script);
@@ -77,12 +68,11 @@ var inject = (props = {
77
68
  // src/react.tsx
78
69
  function Analytics({
79
70
  beforeSend,
80
- debug = true,
81
- __mode = "auto"
71
+ debug = isDevelopment()
82
72
  }) {
83
73
  (0, import_react.useEffect)(() => {
84
- inject({ beforeSend, debug, __mode });
85
- }, [beforeSend, debug, __mode]);
74
+ inject({ beforeSend, debug });
75
+ }, [beforeSend, debug]);
86
76
  return null;
87
77
  }
88
78
  // Annotate the CommonJS export names for ESM import in node:
@@ -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","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,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;;;AH7BO,SAAS,UAAU;AAAA,EACxB;AAAA,EACA,QAAQ;AAAA,EACR,SAAS;AACX,GAAyB;AACvB,8BAAU,MAAM;AACd,WAAO,EAAE,YAAY,OAAO,OAAO,CAAC;AAAA,EACtC,GAAG,CAAC,YAAY,OAAO,MAAM,CAAC;AAE9B,SAAO;AACT;","names":[]}
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 if (typeof process === 'undefined') return false;\n return (\n process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test'\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,MAAI,OAAO,YAAY;AAAa,WAAO;AAC3C,SACE,QAAQ,IAAI,aAAa,iBAAiB,QAAQ,IAAI,aAAa;AAEvE;;;ACLO,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":[]}
@@ -2,13 +2,11 @@ interface PageViewEvent {
2
2
  type: 'pageview';
3
3
  url: string;
4
4
  }
5
- declare type Event = PageViewEvent;
6
- declare type Mode = 'auto' | 'development' | 'production';
7
- declare type BeforeSend = (event: Event) => Event | null;
5
+ declare type IEvent = PageViewEvent;
6
+ declare type BeforeSend = (event: IEvent) => IEvent | null;
8
7
  interface AnalyticsProps {
9
8
  beforeSend?: BeforeSend;
10
9
  debug?: boolean;
11
- __mode?: Mode;
12
10
  }
13
11
  declare global {
14
12
  interface Window {
@@ -18,6 +16,6 @@ declare global {
18
16
  }
19
17
  }
20
18
 
21
- declare function Analytics({ beforeSend, debug, __mode, }: AnalyticsProps): null;
19
+ declare function Analytics({ beforeSend, debug, }: AnalyticsProps): null;
22
20
 
23
- export { Analytics, AnalyticsProps };
21
+ export { Analytics };
@@ -19,32 +19,23 @@ 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
- }
28
22
 
29
23
  // src/generic.ts
30
- var inject = (props = {
31
- debug: true
32
- }) => {
24
+ var inject = ({ beforeSend, debug } = { debug: isDevelopment() }) => {
33
25
  var _a;
34
26
  if (!isBrowser())
35
27
  return;
36
- const mode = getMode(props.__mode);
37
28
  initQueue();
38
- if (props.beforeSend) {
39
- (_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", props.beforeSend);
29
+ if (beforeSend) {
30
+ (_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", beforeSend);
40
31
  }
41
- const src = mode === "development" ? "https://cdn.vercel-insights.com/v1/script.debug.js" : "/_vercel/insights/script.js";
32
+ const src = isDevelopment() ? "https://cdn.vercel-insights.com/v1/script.debug.js" : "/_vercel/insights/script.js";
42
33
  if (document.head.querySelector(`script[src*="${src}"]`))
43
34
  return;
44
35
  const script = document.createElement("script");
45
36
  script.src = src;
46
37
  script.defer = true;
47
- if (mode === "development" && props.debug === false) {
38
+ if (isDevelopment() && debug === false) {
48
39
  script.setAttribute("data-debug", "false");
49
40
  }
50
41
  document.head.appendChild(script);
@@ -53,12 +44,11 @@ var inject = (props = {
53
44
  // src/react.tsx
54
45
  function Analytics({
55
46
  beforeSend,
56
- debug = true,
57
- __mode = "auto"
47
+ debug = isDevelopment()
58
48
  }) {
59
49
  useEffect(() => {
60
- inject({ beforeSend, debug, __mode });
61
- }, [beforeSend, debug, __mode]);
50
+ inject({ beforeSend, debug });
51
+ }, [beforeSend, debug]);
62
52
  return null;
63
53
  }
64
54
  export {
@@ -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","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,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;;;AH7BO,SAAS,UAAU;AAAA,EACxB;AAAA,EACA,QAAQ;AAAA,EACR,SAAS;AACX,GAAyB;AACvB,YAAU,MAAM;AACd,WAAO,EAAE,YAAY,OAAO,OAAO,CAAC;AAAA,EACtC,GAAG,CAAC,YAAY,OAAO,MAAM,CAAC;AAE9B,SAAO;AACT;","names":[]}
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 if (typeof process === 'undefined') return false;\n return (\n process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test'\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,MAAI,OAAO,YAAY;AAAa,WAAO;AAC3C,SACE,QAAQ,IAAI,aAAa,iBAAiB,QAAQ,IAAI,aAAa;AAEvE;;;ACLO,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.6-beta.0",
3
+ "version": "0.1.6-beta.1",
4
4
  "keywords": [
5
5
  "analytics",
6
6
  "vercel"