@vercel/analytics 0.1.9-beta.4 → 0.1.9-beta.6

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 CHANGED
@@ -4,8 +4,8 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
6
  var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
7
+ for (var name2 in all)
8
+ __defProp(target, name2, { get: all[name2], enumerable: true });
9
9
  };
10
10
  var __copyProps = (to, from, except, desc) => {
11
11
  if (from && typeof from === "object" || typeof from === "function") {
@@ -26,6 +26,10 @@ __export(generic_exports, {
26
26
  });
27
27
  module.exports = __toCommonJS(generic_exports);
28
28
 
29
+ // package.json
30
+ var name = "@vercel/analytics";
31
+ var version = "0.1.9-beta.6";
32
+
29
33
  // src/queue.ts
30
34
  var initQueue = () => {
31
35
  if (window.va)
@@ -40,10 +44,13 @@ function isBrowser() {
40
44
  return typeof window !== "undefined";
41
45
  }
42
46
  function detectEnvironment() {
43
- if (typeof process === "undefined")
44
- return "production";
45
- if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test")
46
- return "development";
47
+ try {
48
+ const env = process.env.NODE_ENV;
49
+ if (env === "development" || env === "test") {
50
+ return "development";
51
+ }
52
+ } catch (e) {
53
+ }
47
54
  return "production";
48
55
  }
49
56
  function setMode(mode = "auto") {
@@ -62,7 +69,9 @@ function isProduction() {
62
69
  function isDevelopment() {
63
70
  return getMode() === "development";
64
71
  }
65
- var removeKey = (key, { [key]: _, ...rest }) => rest;
72
+ function removeKey(key, { [key]: _, ...rest }) {
73
+ return rest;
74
+ }
66
75
  function parseProperties(properties, options) {
67
76
  let props = properties;
68
77
  const errorProperties = [];
@@ -86,9 +95,9 @@ function parseProperties(properties, options) {
86
95
  }
87
96
 
88
97
  // src/generic.ts
89
- var inject = (props = {
98
+ function inject(props = {
90
99
  debug: true
91
- }) => {
100
+ }) {
92
101
  var _a;
93
102
  if (!isBrowser())
94
103
  return;
@@ -103,17 +112,23 @@ var inject = (props = {
103
112
  const script = document.createElement("script");
104
113
  script.src = src;
105
114
  script.defer = true;
115
+ script.setAttribute("data-sdkn", name);
116
+ script.setAttribute("data-sdkv", version);
106
117
  if (isDevelopment() && props.debug === false) {
107
118
  script.setAttribute("data-debug", "false");
108
119
  }
109
120
  document.head.appendChild(script);
110
- };
111
- var track = (name, properties) => {
121
+ }
122
+ function track(name2, properties) {
112
123
  var _a, _b;
113
- if (!isBrowser())
124
+ if (!isBrowser()) {
125
+ console.warn(
126
+ "[Vercel Analytics] Server-side execution of `track()` is currently not supported."
127
+ );
114
128
  return;
129
+ }
115
130
  if (!properties) {
116
- (_a = window.va) == null ? void 0 : _a.call(window, "event", { name });
131
+ (_a = window.va) == null ? void 0 : _a.call(window, "event", { name: name2 });
117
132
  return;
118
133
  }
119
134
  try {
@@ -121,7 +136,7 @@ var track = (name, properties) => {
121
136
  strip: isProduction()
122
137
  });
123
138
  (_b = window.va) == null ? void 0 : _b.call(window, "event", {
124
- name,
139
+ name: name2,
125
140
  data: props
126
141
  });
127
142
  } catch (err) {
@@ -129,7 +144,7 @@ var track = (name, properties) => {
129
144
  console.error(err);
130
145
  }
131
146
  }
132
- };
147
+ }
133
148
  var generic_default = {
134
149
  inject,
135
150
  track
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/generic.ts","../src/queue.ts","../src/utils.ts"],"sourcesContent":["import { initQueue } from './queue';\nimport type { AllowedPropertyValues, AnalyticsProps } from './types';\nimport {\n isBrowser,\n parseProperties,\n setMode,\n isDevelopment,\n isProduction,\n} from './utils';\n\nexport const inject = (\n props: AnalyticsProps = {\n debug: true,\n },\n): void => {\n if (!isBrowser()) return;\n\n setMode(props.mode);\n\n initQueue();\n\n if (props.beforeSend) {\n window.va?.('beforeSend', props.beforeSend);\n }\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() && props.debug === false) {\n script.setAttribute('data-debug', 'false');\n }\n\n document.head.appendChild(script);\n};\n\nexport const track = (\n name: string,\n properties?: Record<string, AllowedPropertyValues>,\n): void => {\n if (!isBrowser()) return;\n\n if (!properties) {\n window.va?.('event', { name });\n return;\n }\n\n try {\n const props = parseProperties(properties, {\n strip: isProduction(),\n });\n\n window.va?.('event', {\n name,\n data: props,\n });\n } catch (err) {\n if (err instanceof Error && isDevelopment()) {\n // eslint-disable-next-line no-console\n console.error(err);\n }\n }\n};\n\n// eslint-disable-next-line import/no-default-export\nexport default {\n inject,\n track,\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 { AllowedPropertyValues, Mode } from './types';\n\nexport function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nfunction detectEnvironment(): 'development' | 'production' {\n if (typeof process === 'undefined') return 'production';\n\n if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test')\n return 'development';\n\n return 'production';\n}\n\nexport function setMode(mode: Mode = 'auto'): void {\n if (mode === 'auto') {\n window.vam = detectEnvironment();\n return;\n }\n\n window.vam = mode;\n}\n\nexport function getMode(): Mode {\n return window.vam || 'production';\n}\n\nexport function isProduction(): boolean {\n return getMode() === 'production';\n}\n\nexport function isDevelopment(): boolean {\n return getMode() === 'development';\n}\n\nconst removeKey = (key: string, { [key]: _, ...rest }): Record<string, any> =>\n rest;\n\nexport function parseProperties(\n properties: Record<string, unknown>,\n options: {\n strip?: boolean;\n },\n): Error | Record<string, AllowedPropertyValues> | undefined {\n let props = properties;\n const errorProperties: string[] = [];\n for (const [key, value] of Object.entries(properties)) {\n if (typeof value === 'object' && value !== null) {\n if (options.strip) {\n props = removeKey(key, props);\n } else {\n errorProperties.push(key);\n }\n }\n }\n\n if (errorProperties.length > 0 && !options.strip) {\n throw Error(\n `The following properties are not valid: ${errorProperties.join(\n ', ',\n )}. Only strings, numbers, booleans, and null are allowed.`,\n );\n }\n return props as Record<string, AllowedPropertyValues>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;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;AAEA,SAAS,oBAAkD;AACzD,MAAI,OAAO,YAAY;AAAa,WAAO;AAE3C,MAAI,QAAQ,IAAI,aAAa,iBAAiB,QAAQ,IAAI,aAAa;AACrE,WAAO;AAET,SAAO;AACT;AAEO,SAAS,QAAQ,OAAa,QAAc;AACjD,MAAI,SAAS,QAAQ;AACnB,WAAO,MAAM,kBAAkB;AAC/B;AAAA,EACF;AAEA,SAAO,MAAM;AACf;AAEO,SAAS,UAAgB;AAC9B,SAAO,OAAO,OAAO;AACvB;AAEO,SAAS,eAAwB;AACtC,SAAO,QAAQ,MAAM;AACvB;AAEO,SAAS,gBAAyB;AACvC,SAAO,QAAQ,MAAM;AACvB;AAEA,IAAM,YAAY,CAAC,KAAa,GAAG,MAAM,MAAM,KAAK,MAClD;AAEK,SAAS,gBACd,YACA,SAG2D;AAC3D,MAAI,QAAQ;AACZ,QAAM,kBAA4B,CAAC;AACnC,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,UAAU,GAAG;AACrD,QAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,UAAI,QAAQ,OAAO;AACjB,gBAAQ,UAAU,KAAK,K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ources":["../src/generic.ts","../src/queue.ts","../src/utils.ts"],"sourcesContent":["import { name as packageName, version } from '../package.json';\nimport { initQueue } from './queue';\nimport type { AllowedPropertyValues, AnalyticsProps } from './types';\nimport {\n isBrowser,\n parseProperties,\n setMode,\n isDevelopment,\n isProduction,\n} from './utils';\n\nexport function inject(\n props: AnalyticsProps = {\n debug: true,\n },\n): void {\n if (!isBrowser()) return;\n\n setMode(props.mode);\n\n initQueue();\n\n if (props.beforeSend) {\n window.va?.('beforeSend', props.beforeSend);\n }\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 script.setAttribute('data-sdkn', packageName);\n script.setAttribute('data-sdkv', version);\n\n if (isDevelopment() && props.debug === false) {\n script.setAttribute('data-debug', 'false');\n }\n\n document.head.appendChild(script);\n}\n\nexport function track(\n name: string,\n properties?: Record<string, AllowedPropertyValues>,\n): void {\n if (!isBrowser()) {\n // eslint-disable-next-line no-console\n console.warn(\n '[Vercel Analytics] Server-side execution of `track()` is currently not supported.',\n );\n return;\n }\n\n if (!properties) {\n window.va?.('event', { name });\n return;\n }\n\n try {\n const props = parseProperties(properties, {\n strip: isProduction(),\n });\n\n window.va?.('event', {\n name,\n data: props,\n });\n } catch (err) {\n if (err instanceof Error && isDevelopment()) {\n // eslint-disable-next-line no-console\n console.error(err);\n }\n }\n}\n\n// eslint-disable-next-line import/no-default-export\nexport default {\n inject,\n track,\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 { AllowedPropertyValues, Mode } from './types';\n\nexport function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nfunction detectEnvironment(): 'development' | 'production' {\n try {\n const env = process.env.NODE_ENV;\n if (env === 'development' || env === 'test') {\n return 'development';\n }\n } catch (e) {\n // do nothing, this is okay\n }\n return 'production';\n}\n\nexport function setMode(mode: Mode = 'auto'): void {\n if (mode === 'auto') {\n window.vam = detectEnvironment();\n return;\n }\n\n window.vam = mode;\n}\n\nexport function getMode(): Mode {\n return window.vam || 'production';\n}\n\nexport function isProduction(): boolean {\n return getMode() === 'production';\n}\n\nexport function isDevelopment(): boolean {\n return getMode() === 'development';\n}\n\nfunction removeKey(\n key: string,\n { [key]: _, ...rest },\n): Record<string, unknown> {\n return rest;\n}\n\nexport function parseProperties(\n properties: Record<string, unknown>,\n options: {\n strip?: boolean;\n },\n): Error | Record<string, AllowedPropertyValues> | undefined {\n let props = properties;\n const errorProperties: string[] = [];\n for (const [key, value] of Object.entries(properties)) {\n if (typeof value === 'object' && value !== null) {\n if (options.strip) {\n props = removeKey(key, props);\n } else {\n errorProperties.push(key);\n }\n }\n }\n\n if (errorProperties.length > 0 && !options.strip) {\n throw Error(\n `The following properties are not valid: ${errorProperties.join(\n ', ',\n )}. Only strings, numbers, booleans, and null are allowed.`,\n );\n }\n return props as Record<string, AllowedPropertyValues>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;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;AAEA,SAAS,oBAAkD;AACzD,MAAI;AACF,UAAM,MAAM,QAAQ,IAAI;AACxB,QAAI,QAAQ,iBAAiB,QAAQ,QAAQ;AAC3C,aAAO;AAAA,IACT;AAAA,EACF,SAAS,GAAP;AAAA,EAEF;AACA,SAAO;AACT;AAEO,SAAS,QAAQ,OAAa,QAAc;AACjD,MAAI,SAAS,QAAQ;AACnB,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AAO,aAAa,cAAc,OAAO;AAAA,EAC3C;AAEA,WAAS,KAAK,YAAY,MAAM;AAClC;AAEO,SAAS,MACdA,OACA,YACM;AAhDR;AAiDE,MAAI,CAAC,UAAU,GAAG;AAEhB,YAAQ;AAAA,MACN;AAAA,IACF;AACA;AAAA,EACF;AAEA,MAAI,CAAC,YAAY;AACf,iBAAO,OAAP,gCAAY,SAAS,EAAE,MAAAA,MAAK;AAC5B;AAAA,EACF;AAEA,MAAI;AACF,UAAM,QAAQ,gBAAgB,YAAY;AAAA,MACxC,OAAO,aAAa;AAAA,IACtB,CAAC;AAED,iBAAO,OAAP,gCAAY,SAAS;AAAA,MACnB,MAAAA;AAAA,MACA,MAAM;AAAA,IACR;AAAA,EACF,SAAS,KAAP;AACA,QAAI,eAAe,SAAS,cAAc,GAAG;AAE3C,cAAQ,MAAM,GAAG;AAAA,IACnB;AAAA,EACF;AACF;AAGA,IAAO,kBAAQ;AAAA,EACb;AAAA,EACA;AACF;","names":["name"]}
package/dist/index.d.ts CHANGED
@@ -20,11 +20,11 @@ declare global {
20
20
  }
21
21
  }
22
22
 
23
- declare const inject: (props?: AnalyticsProps) => void;
24
- declare const track: (name: string, properties?: Record<string, AllowedPropertyValues>) => void;
23
+ declare function inject(props?: AnalyticsProps): void;
24
+ declare function track(name: string, properties?: Record<string, AllowedPropertyValues>): void;
25
25
  declare const _default: {
26
- inject: (props?: AnalyticsProps) => void;
27
- track: (name: string, properties?: Record<string, AllowedPropertyValues> | undefined) => void;
26
+ inject: typeof inject;
27
+ track: typeof track;
28
28
  };
29
29
 
30
30
  export { _default as default, inject, track };
package/dist/index.js CHANGED
@@ -1,3 +1,7 @@
1
+ // package.json
2
+ var name = "@vercel/analytics";
3
+ var version = "0.1.9-beta.6";
4
+
1
5
  // src/queue.ts
2
6
  var initQueue = () => {
3
7
  if (window.va)
@@ -12,10 +16,13 @@ function isBrowser() {
12
16
  return typeof window !== "undefined";
13
17
  }
14
18
  function detectEnvironment() {
15
- if (typeof process === "undefined")
16
- return "production";
17
- if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test")
18
- return "development";
19
+ try {
20
+ const env = process.env.NODE_ENV;
21
+ if (env === "development" || env === "test") {
22
+ return "development";
23
+ }
24
+ } catch (e) {
25
+ }
19
26
  return "production";
20
27
  }
21
28
  function setMode(mode = "auto") {
@@ -34,7 +41,9 @@ function isProduction() {
34
41
  function isDevelopment() {
35
42
  return getMode() === "development";
36
43
  }
37
- var removeKey = (key, { [key]: _, ...rest }) => rest;
44
+ function removeKey(key, { [key]: _, ...rest }) {
45
+ return rest;
46
+ }
38
47
  function parseProperties(properties, options) {
39
48
  let props = properties;
40
49
  const errorProperties = [];
@@ -58,9 +67,9 @@ function parseProperties(properties, options) {
58
67
  }
59
68
 
60
69
  // src/generic.ts
61
- var inject = (props = {
70
+ function inject(props = {
62
71
  debug: true
63
- }) => {
72
+ }) {
64
73
  var _a;
65
74
  if (!isBrowser())
66
75
  return;
@@ -75,17 +84,23 @@ var inject = (props = {
75
84
  const script = document.createElement("script");
76
85
  script.src = src;
77
86
  script.defer = true;
87
+ script.setAttribute("data-sdkn", name);
88
+ script.setAttribute("data-sdkv", version);
78
89
  if (isDevelopment() && props.debug === false) {
79
90
  script.setAttribute("data-debug", "false");
80
91
  }
81
92
  document.head.appendChild(script);
82
- };
83
- var track = (name, properties) => {
93
+ }
94
+ function track(name2, properties) {
84
95
  var _a, _b;
85
- if (!isBrowser())
96
+ if (!isBrowser()) {
97
+ console.warn(
98
+ "[Vercel Analytics] Server-side execution of `track()` is currently not supported."
99
+ );
86
100
  return;
101
+ }
87
102
  if (!properties) {
88
- (_a = window.va) == null ? void 0 : _a.call(window, "event", { name });
103
+ (_a = window.va) == null ? void 0 : _a.call(window, "event", { name: name2 });
89
104
  return;
90
105
  }
91
106
  try {
@@ -93,7 +108,7 @@ var track = (name, properties) => {
93
108
  strip: isProduction()
94
109
  });
95
110
  (_b = window.va) == null ? void 0 : _b.call(window, "event", {
96
- name,
111
+ name: name2,
97
112
  data: props
98
113
  });
99
114
  } catch (err) {
@@ -101,7 +116,7 @@ var track = (name, properties) => {
101
116
  console.error(err);
102
117
  }
103
118
  }
104
- };
119
+ }
105
120
  var generic_default = {
106
121
  inject,
107
122
  track
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 { AllowedPropertyValues, Mode } from './types';\n\nexport function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nfunction detectEnvironment(): 'development' | 'production' {\n if (typeof process === 'undefined') return 'production';\n\n if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test')\n return 'development';\n\n return 'production';\n}\n\nexport function setMode(mode: Mode = 'auto'): void {\n if (mode === 'auto') {\n window.vam = detectEnvironment();\n return;\n }\n\n window.vam = mode;\n}\n\nexport function getMode(): Mode {\n return window.vam || 'production';\n}\n\nexport function isProduction(): boolean {\n return getMode() === 'production';\n}\n\nexport function isDevelopment(): boolean {\n return getMode() === 'development';\n}\n\nconst removeKey = (key: string, { [key]: _, ...rest }): Record<string, any> =>\n rest;\n\nexport function parseProperties(\n properties: Record<string, unknown>,\n options: {\n strip?: boolean;\n },\n): Error | Record<string, AllowedPropertyValues> | undefined {\n let props = properties;\n const errorProperties: string[] = [];\n for (const [key, value] of Object.entries(properties)) {\n if (typeof value === 'object' && value !== null) {\n if (options.strip) {\n props = removeKey(key, props);\n } else {\n errorProperties.push(key);\n }\n }\n }\n\n if (errorProperties.length > 0 && !options.strip) {\n throw Error(\n `The following properties are not valid: ${errorProperties.join(\n ', ',\n )}. Only strings, numbers, booleans, and null are allowed.`,\n );\n }\n return props as Record<string, AllowedPropertyValues>;\n}\n","import { initQueue } from './queue';\nimport type { AllowedPropertyValues, AnalyticsProps } from './types';\nimport {\n isBrowser,\n parseProperties,\n setMode,\n isDevelopment,\n isProduction,\n} from './utils';\n\nexport const inject = (\n props: AnalyticsProps = {\n debug: true,\n },\n): void => {\n if (!isBrowser()) return;\n\n setMode(props.mode);\n\n initQueue();\n\n if (props.beforeSend) {\n window.va?.('beforeSend', props.beforeSend);\n }\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() && props.debug === false) {\n script.setAttribute('data-debug', 'false');\n }\n\n document.head.appendChild(script);\n};\n\nexport const track = (\n name: string,\n properties?: Record<string, AllowedPropertyValues>,\n): void => {\n if (!isBrowser()) return;\n\n if (!properties) {\n window.va?.('event', { name });\n return;\n }\n\n try {\n const props = parseProperties(properties, {\n strip: isProduction(),\n });\n\n window.va?.('event', {\n name,\n data: props,\n });\n } catch (err) {\n if (err instanceof Error && isDevelopment()) {\n // eslint-disable-next-line no-console\n console.error(err);\n }\n }\n};\n\n// eslint-disable-next-line import/no-default-export\nexport default {\n inject,\n track,\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;AAEA,SAAS,oBAAkD;AACzD,MAAI,OAAO,YAAY;AAAa,WAAO;AAE3C,MAAI,QAAQ,IAAI,aAAa,iBAAiB,QAAQ,IAAI,aAAa;AACrE,WAAO;AAET,SAAO;AACT;AAEO,SAAS,QAAQ,OAAa,QAAc;AACjD,MAAI,SAAS,QAAQ;AACnB,WAAO,MAAM,kBAAkB;AAC/B;AAAA,EACF;AAEA,SAAO,MAAM;AACf;AAEO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CAAC,UAAU;AAAG;AAElB,MAAI,CAAC,YAAY;AACf,iBAAO,OAAP,gCAAY,SAAS,EAAE,KAAK;AAC5B;AAAA,EACF;AAEA,MAAI;AACF,UAAM,QAAQ,gBAAgB,YAAY;AAAA,MACxC,OAAO,aAAa;AAAA,IACtB,CAAC;AAED,iBAAO,OAAP,gCAAY,SAAS;AAAA,MACnB;AAAA,MACA,MAAM;AAAA,IACR;AAAA,EACF,SAAS,KAAP;AACA,QAAI,eAAe,SAAS,cAAc,GAAG;AAE3C,cAAQ,MAAM,GAAG;AAAA,IACnB;AAAA,EACF;AACF;AAGA,IAAO,kBAAQ;AAAA,EACb;AAAA,EACA;AACF;","names":[]}
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 { AllowedPropertyValues, Mode } from './types';\n\nexport function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nfunction detectEnvironment(): 'development' | 'production' {\n try {\n const env = process.env.NODE_ENV;\n if (env === 'development' || env === 'test') {\n return 'development';\n }\n } catch (e) {\n // do nothing, this is okay\n }\n return 'production';\n}\n\nexport function setMode(mode: Mode = 'auto'): void {\n if (mode === 'auto') {\n window.vam = detectEnvironment();\n return;\n }\n\n window.vam = mode;\n}\n\nexport function getMode(): Mode {\n return window.vam || 'production';\n}\n\nexport function isProduction(): boolean {\n return getMode() === 'production';\n}\n\nexport function isDevelopment(): boolean {\n return getMode() === 'development';\n}\n\nfunction removeKey(\n key: string,\n { [key]: _, ...rest },\n): Record<string, unknown> {\n return rest;\n}\n\nexport function parseProperties(\n properties: Record<string, unknown>,\n options: {\n strip?: boolean;\n },\n): Error | Record<string, AllowedPropertyValues> | undefined {\n let props = properties;\n const errorProperties: string[] = [];\n for (const [key, value] of Object.entries(properties)) {\n if (typeof value === 'object' && value !== null) {\n if (options.strip) {\n props = removeKey(key, props);\n } else {\n errorProperties.push(key);\n }\n }\n }\n\n if (errorProperties.length > 0 && !options.strip) {\n throw Error(\n `The following properties are not valid: ${errorProperties.join(\n ', ',\n )}. Only strings, numbers, booleans, and null are allowed.`,\n );\n }\n return props as Record<string, AllowedPropertyValues>;\n}\n","import { name as packageName, version } from '../package.json';\nimport { initQueue } from './queue';\nimport type { AllowedPropertyValues, AnalyticsProps } from './types';\nimport {\n isBrowser,\n parseProperties,\n setMode,\n isDevelopment,\n isProduction,\n} from './utils';\n\nexport function inject(\n props: AnalyticsProps = {\n debug: true,\n },\n): void {\n if (!isBrowser()) return;\n\n setMode(props.mode);\n\n initQueue();\n\n if (props.beforeSend) {\n window.va?.('beforeSend', props.beforeSend);\n }\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 script.setAttribute('data-sdkn', packageName);\n script.setAttribute('data-sdkv', version);\n\n if (isDevelopment() && props.debug === false) {\n script.setAttribute('data-debug', 'false');\n }\n\n document.head.appendChild(script);\n}\n\nexport function track(\n name: string,\n properties?: Record<string, AllowedPropertyValues>,\n): void {\n if (!isBrowser()) {\n // eslint-disable-next-line no-console\n console.warn(\n '[Vercel Analytics] Server-side execution of `track()` is currently not supported.',\n );\n return;\n }\n\n if (!properties) {\n window.va?.('event', { name });\n return;\n }\n\n try {\n const props = parseProperties(properties, {\n strip: isProduction(),\n });\n\n window.va?.('event', {\n name,\n data: props,\n });\n } catch (err) {\n if (err instanceof Error && isDevelopment()) {\n // eslint-disable-next-line no-console\n console.error(err);\n }\n }\n}\n\n// eslint-disable-next-line import/no-default-export\nexport default {\n inject,\n track,\n};\n"],"mappings":";;;;;AAAO,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO;AAAI;AAEf,SAAO,KAAK,SAAS,KAAK,QAA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,MAAM,IAAI;AAElB,YAAU;AAEV,MAAI,MAAM,YAAY;AACpB,iBAAO,OAAP,gCAAY,cAAc,MAAM;AAAA,EAClC;AAEA,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;AACf,SAAO,aAAa,aAAa,IAAW;AAC5C,SAAO,aAAa,aAAa,OAAO;AAExC,MAAI,cAAc,KAAK,MAAM,UAAU,OAAO;AAC5C,WAAO,aAAa,cAAc,OAAO;AAAA,EAC3C;AAEA,WAAS,KAAK,YAAY,MAAM;AAClC;AAEO,SAAS,MACdA,OACA,YACM;AAhDR;AAiDE,MAAI,CAAC,UAAU,GAAG;AAEhB,YAAQ;AAAA,MACN;AAAA,IACF;AACA;AAAA,EACF;AAEA,MAAI,CAAC,YAAY;AACf,iBAAO,OAAP,gCAAY,SAAS,EAAE,MAAAA,MAAK;AAC5B;AAAA,EACF;AAEA,MAAI;AACF,UAAM,QAAQ,gBAAgB,YAAY;AAAA,MACxC,OAAO,aAAa;AAAA,IACtB,CAAC;AAED,iBAAO,OAAP,gCAAY,SAAS;AAAA,MACnB,MAAAA;AAAA,MACA,MAAM;AAAA,IACR;AAAA,EACF,SAAS,KAAP;AACA,QAAI,eAAe,SAAS,cAAc,GAAG;AAE3C,cAAQ,MAAM,GAAG;AAAA,IACnB;AAAA,EACF;AACF;AAGA,IAAO,kBAAQ;AAAA,EACb;AAAA,EACA;AACF;","names":["name"]}
@@ -1,11 +1,12 @@
1
+ "use client";
1
2
  "use strict";
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
7
  var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
8
+ for (var name2 in all)
9
+ __defProp(target, name2, { get: all[name2], enumerable: true });
9
10
  };
10
11
  var __copyProps = (to, from, except, desc) => {
11
12
  if (from && typeof from === "object" || typeof from === "function") {
@@ -27,6 +28,10 @@ __export(react_exports, {
27
28
  module.exports = __toCommonJS(react_exports);
28
29
  var import_react = require("react");
29
30
 
31
+ // package.json
32
+ var name = "@vercel/analytics";
33
+ var version = "0.1.9-beta.6";
34
+
30
35
  // src/queue.ts
31
36
  var initQueue = () => {
32
37
  if (window.va)
@@ -41,10 +46,13 @@ function isBrowser() {
41
46
  return typeof window !== "undefined";
42
47
  }
43
48
  function detectEnvironment() {
44
- if (typeof process === "undefined")
45
- return "production";
46
- if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test")
47
- return "development";
49
+ try {
50
+ const env = process.env.NODE_ENV;
51
+ if (env === "development" || env === "test") {
52
+ return "development";
53
+ }
54
+ } catch (e) {
55
+ }
48
56
  return "production";
49
57
  }
50
58
  function setMode(mode = "auto") {
@@ -63,7 +71,9 @@ function isProduction() {
63
71
  function isDevelopment() {
64
72
  return getMode() === "development";
65
73
  }
66
- var removeKey = (key, { [key]: _, ...rest }) => rest;
74
+ function removeKey(key, { [key]: _, ...rest }) {
75
+ return rest;
76
+ }
67
77
  function parseProperties(properties, options) {
68
78
  let props = properties;
69
79
  const errorProperties = [];
@@ -87,9 +97,9 @@ function parseProperties(properties, options) {
87
97
  }
88
98
 
89
99
  // src/generic.ts
90
- var inject = (props = {
100
+ function inject(props = {
91
101
  debug: true
92
- }) => {
102
+ }) {
93
103
  var _a;
94
104
  if (!isBrowser())
95
105
  return;
@@ -104,17 +114,23 @@ var inject = (props = {
104
114
  const script = document.createElement("script");
105
115
  script.src = src;
106
116
  script.defer = true;
117
+ script.setAttribute("data-sdkn", name);
118
+ script.setAttribute("data-sdkv", version);
107
119
  if (isDevelopment() && props.debug === false) {
108
120
  script.setAttribute("data-debug", "false");
109
121
  }
110
122
  document.head.appendChild(script);
111
- };
112
- var track = (name, properties) => {
123
+ }
124
+ function track(name2, properties) {
113
125
  var _a, _b;
114
- if (!isBrowser())
126
+ if (!isBrowser()) {
127
+ console.warn(
128
+ "[Vercel Analytics] Server-side execution of `track()` is currently not supported."
129
+ );
115
130
  return;
131
+ }
116
132
  if (!properties) {
117
- (_a = window.va) == null ? void 0 : _a.call(window, "event", { name });
133
+ (_a = window.va) == null ? void 0 : _a.call(window, "event", { name: name2 });
118
134
  return;
119
135
  }
120
136
  try {
@@ -122,7 +138,7 @@ var track = (name, properties) => {
122
138
  strip: isProduction()
123
139
  });
124
140
  (_b = window.va) == null ? void 0 : _b.call(window, "event", {
125
- name,
141
+ name: name2,
126
142
  data: props
127
143
  });
128
144
  } catch (err) {
@@ -130,7 +146,7 @@ var track = (name, properties) => {
130
146
  console.error(err);
131
147
  }
132
148
  }
133
- };
149
+ }
134
150
 
135
151
  // src/react.tsx
136
152
  function Analytics({
@@ -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, track } from './generic';\nimport type { AnalyticsProps } from './types';\n\nfunction 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}\nexport { track, Analytics };\nexport type { AnalyticsProps };\n\n// eslint-disable-next-line import/no-default-export\nexport default {\n Analytics,\n track,\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 { AllowedPropertyValues, Mode } from './types';\n\nexport function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nfunction detectEnvironment(): 'development' | 'production' {\n if (typeof process === 'undefined') return 'production';\n\n if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test')\n return 'development';\n\n return 'production';\n}\n\nexport function setMode(mode: Mode = 'auto'): void {\n if (mode === 'auto') {\n window.vam = detectEnvironment();\n return;\n }\n\n window.vam = mode;\n}\n\nexport function getMode(): Mode {\n return window.vam || 'production';\n}\n\nexport function isProduction(): boolean {\n return getMode() === 'production';\n}\n\nexport function isDevelopment(): boolean {\n return getMode() === 'development';\n}\n\nconst removeKey = (key: string, { [key]: _, ...rest }): Record<string, any> =>\n rest;\n\nexport function parseProperties(\n properties: Record<string, unknown>,\n options: {\n strip?: boolean;\n },\n): Error | Record<string, AllowedPropertyValues> | undefined {\n let props = properties;\n const errorProperties: string[] = [];\n for (const [key, value] of Object.entries(properties)) {\n if (typeof value === 'object' && value !== null) {\n if (options.strip) {\n props = removeKey(key, props);\n } else {\n errorProperties.push(key);\n }\n }\n }\n\n if (errorProperties.length > 0 && !options.strip) {\n throw Error(\n `The following properties are not valid: ${errorProperties.join(\n ', ',\n )}. Only strings, numbers, booleans, and null are allowed.`,\n );\n }\n return props as Record<string, AllowedPropertyValues>;\n}\n","import { initQueue } from './queue';\nimport type { AllowedPropertyValues, AnalyticsProps } from './types';\nimport {\n isBrowser,\n parseProperties,\n setMode,\n isDevelopment,\n isProduction,\n} from './utils';\n\nexport const inject = (\n props: AnalyticsProps = {\n debug: true,\n },\n): void => {\n if (!isBrowser()) return;\n\n setMode(props.mode);\n\n initQueue();\n\n if (props.beforeSend) {\n window.va?.('beforeSend', props.beforeSend);\n }\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() && props.debug === false) {\n script.setAttribute('data-debug', 'false');\n }\n\n document.head.appendChild(script);\n};\n\nexport const track = (\n name: string,\n properties?: Record<string, AllowedPropertyValues>,\n): void => {\n if (!isBrowser()) return;\n\n if (!properties) {\n window.va?.('event', { name });\n return;\n }\n\n try {\n const props = parseProperties(properties, {\n strip: isProduction(),\n });\n\n window.va?.('event', {\n name,\n data: props,\n });\n } catch (err) {\n if (err instanceof Error && isDevelopment()) {\n // eslint-disable-next-line no-console\n console.error(err);\n }\n }\n};\n\n// eslint-disable-next-line import/no-default-export\nexport default {\n inject,\n track,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;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;AAEA,SAAS,oBAAkD;AACzD,MAAI,OAAO,YAAY;AAAa,WAAO;AAE3C,MAAI,QAAQ,IAAI,aAAa,iBAAiB,QAAQ,IAAI,aAAa;AACrE,WAAO;AAET,SAAO;AACT;AAEO,SAAS,QAAQ,OAAa,QAAc;AACjD,MAAI,SAAS,QAAQ;AACnB,WAAO,MAAM,kBAAkB;AAC/B;AAAA,EACF;AAEA,SAAO,MAAM;AACf;AAEO,SAAS,UAAgB;AAC9B,SAAO,OAAO,OAAO;AACvB;AAEO,SAAS,eAAwB;AACtC,SAAO,QAAQ,MAAM;AACvB;AAEO,SAAS,gBAAyB;AACvC,SAAO,QAAQ,MAAM;AACvB;AAEA,IAAM,YAAY,CAAC,KAAa,GAAG,MAAM,MAAM,KAAK,MAClD;AAEK,SAAS,gBACd,YACA,SAG2D;AAC3D,MAAI,QAAQ;AACZ,QAAM,kBAA4B,CAAC;AACnC,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,UAAU,GAAG;AACrD,QAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,UAAI,QAAQ,OAAO;AACjB,gBAAQ,UAAU,KAAK,KAAK;AAAA,M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ACvB,8BAAU,MAAM;AACd,WAAO,EAAE,YAAY,OAAO,KAAK,CAAC;AAAA,EACpC,GAAG,CAAC,YAAY,OAAO,IAAI,CAAC;AAE5B,SAAO;AACT;AAKA,IAAO,gBAAQ;AAAA,EACb;AAAA,EACA;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/react.tsx","../../src/queue.ts","../../src/utils.ts","../../src/generic.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport { inject, track } from './generic';\nimport type { AnalyticsProps } from './types';\n\nfunction 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}\nexport { track, Analytics };\nexport type { AnalyticsProps };\n\n// eslint-disable-next-line import/no-default-export\nexport default {\n Analytics,\n track,\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 { AllowedPropertyValues, Mode } from './types';\n\nexport function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nfunction detectEnvironment(): 'development' | 'production' {\n try {\n const env = process.env.NODE_ENV;\n if (env === 'development' || env === 'test') {\n return 'development';\n }\n } catch (e) {\n // do nothing, this is okay\n }\n return 'production';\n}\n\nexport function setMode(mode: Mode = 'auto'): void {\n if (mode === 'auto') {\n window.vam = detectEnvironment();\n return;\n }\n\n window.vam = mode;\n}\n\nexport function getMode(): Mode {\n return window.vam || 'production';\n}\n\nexport function isProduction(): boolean {\n return getMode() === 'production';\n}\n\nexport function isDevelopment(): boolean {\n return getMode() === 'development';\n}\n\nfunction removeKey(\n key: string,\n { [key]: _, ...rest },\n): Record<string, unknown> {\n return rest;\n}\n\nexport function parseProperties(\n properties: Record<string, unknown>,\n options: {\n strip?: boolean;\n },\n): Error | Record<string, AllowedPropertyValues> | undefined {\n let props = properties;\n const errorProperties: string[] = [];\n for (const [key, value] of Object.entries(properties)) {\n if (typeof value === 'object' && value !== null) {\n if (options.strip) {\n props = removeKey(key, props);\n } else {\n errorProperties.push(key);\n }\n }\n }\n\n if (errorProperties.length > 0 && !options.strip) {\n throw Error(\n `The following properties are not valid: ${errorProperties.join(\n ', ',\n )}. Only strings, numbers, booleans, and null are allowed.`,\n );\n }\n return props as Record<string, AllowedPropertyValues>;\n}\n","import { name as packageName, version } from '../package.json';\nimport { initQueue } from './queue';\nimport type { AllowedPropertyValues, AnalyticsProps } from './types';\nimport {\n isBrowser,\n parseProperties,\n setMode,\n isDevelopment,\n isProduction,\n} from './utils';\n\nexport function inject(\n props: AnalyticsProps = {\n debug: true,\n },\n): void {\n if (!isBrowser()) return;\n\n setMode(props.mode);\n\n initQueue();\n\n if (props.beforeSend) {\n window.va?.('beforeSend', props.beforeSend);\n }\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 script.setAttribute('data-sdkn', packageName);\n script.setAttribute('data-sdkv', version);\n\n if (isDevelopment() && props.debug === false) {\n script.setAttribute('data-debug', 'false');\n }\n\n document.head.appendChild(script);\n}\n\nexport function track(\n name: string,\n properties?: Record<string, AllowedPropertyValues>,\n): void {\n if (!isBrowser()) {\n // eslint-disable-next-line no-console\n console.warn(\n '[Vercel Analytics] Server-side execution of `track()` is currently not supported.',\n );\n return;\n }\n\n if (!properties) {\n window.va?.('event', { name });\n return;\n }\n\n try {\n const props = parseProperties(properties, {\n strip: isProduction(),\n });\n\n window.va?.('event', {\n name,\n data: props,\n });\n } catch (err) {\n if (err instanceof Error && isDevelopment()) {\n // eslint-disable-next-line no-console\n console.error(err);\n }\n }\n}\n\n// eslint-disable-next-line import/no-default-export\nexport default {\n inject,\n track,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;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AO,IAAI,CAAC;AAE5B,SAAO;AACT;AAKA,IAAO,gBAAQ;AAAA,EACb;AAAA,EACA;AACF;","names":["name"]}
@@ -20,13 +20,13 @@ declare global {
20
20
  }
21
21
  }
22
22
 
23
- declare const track: (name: string, properties?: Record<string, AllowedPropertyValues>) => void;
23
+ declare function track(name: string, properties?: Record<string, AllowedPropertyValues>): void;
24
24
 
25
25
  declare function Analytics({ beforeSend, debug, mode, }: AnalyticsProps): null;
26
26
 
27
27
  declare const _default: {
28
28
  Analytics: typeof Analytics;
29
- track: (name: string, properties?: Record<string, AllowedPropertyValues> | undefined) => void;
29
+ track: typeof track;
30
30
  };
31
31
 
32
32
  export { Analytics, AnalyticsProps, _default as default, track };
@@ -1,6 +1,12 @@
1
+ "use client";
2
+
1
3
  // src/react.tsx
2
4
  import { useEffect } from "react";
3
5
 
6
+ // package.json
7
+ var name = "@vercel/analytics";
8
+ var version = "0.1.9-beta.6";
9
+
4
10
  // src/queue.ts
5
11
  var initQueue = () => {
6
12
  if (window.va)
@@ -15,10 +21,13 @@ function isBrowser() {
15
21
  return typeof window !== "undefined";
16
22
  }
17
23
  function detectEnvironment() {
18
- if (typeof process === "undefined")
19
- return "production";
20
- if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test")
21
- return "development";
24
+ try {
25
+ const env = process.env.NODE_ENV;
26
+ if (env === "development" || env === "test") {
27
+ return "development";
28
+ }
29
+ } catch (e) {
30
+ }
22
31
  return "production";
23
32
  }
24
33
  function setMode(mode = "auto") {
@@ -37,7 +46,9 @@ function isProduction() {
37
46
  function isDevelopment() {
38
47
  return getMode() === "development";
39
48
  }
40
- var removeKey = (key, { [key]: _, ...rest }) => rest;
49
+ function removeKey(key, { [key]: _, ...rest }) {
50
+ return rest;
51
+ }
41
52
  function parseProperties(properties, options) {
42
53
  let props = properties;
43
54
  const errorProperties = [];
@@ -61,9 +72,9 @@ function parseProperties(properties, options) {
61
72
  }
62
73
 
63
74
  // src/generic.ts
64
- var inject = (props = {
75
+ function inject(props = {
65
76
  debug: true
66
- }) => {
77
+ }) {
67
78
  var _a;
68
79
  if (!isBrowser())
69
80
  return;
@@ -78,17 +89,23 @@ var inject = (props = {
78
89
  const script = document.createElement("script");
79
90
  script.src = src;
80
91
  script.defer = true;
92
+ script.setAttribute("data-sdkn", name);
93
+ script.setAttribute("data-sdkv", version);
81
94
  if (isDevelopment() && props.debug === false) {
82
95
  script.setAttribute("data-debug", "false");
83
96
  }
84
97
  document.head.appendChild(script);
85
- };
86
- var track = (name, properties) => {
98
+ }
99
+ function track(name2, properties) {
87
100
  var _a, _b;
88
- if (!isBrowser())
101
+ if (!isBrowser()) {
102
+ console.warn(
103
+ "[Vercel Analytics] Server-side execution of `track()` is currently not supported."
104
+ );
89
105
  return;
106
+ }
90
107
  if (!properties) {
91
- (_a = window.va) == null ? void 0 : _a.call(window, "event", { name });
108
+ (_a = window.va) == null ? void 0 : _a.call(window, "event", { name: name2 });
92
109
  return;
93
110
  }
94
111
  try {
@@ -96,7 +113,7 @@ var track = (name, properties) => {
96
113
  strip: isProduction()
97
114
  });
98
115
  (_b = window.va) == null ? void 0 : _b.call(window, "event", {
99
- name,
116
+ name: name2,
100
117
  data: props
101
118
  });
102
119
  } catch (err) {
@@ -104,7 +121,7 @@ var track = (name, properties) => {
104
121
  console.error(err);
105
122
  }
106
123
  }
107
- };
124
+ }
108
125
 
109
126
  // src/react.tsx
110
127
  function Analytics({
@@ -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, track } from './generic';\nimport type { AnalyticsProps } from './types';\n\nfunction 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}\nexport { track, Analytics };\nexport type { AnalyticsProps };\n\n// eslint-disable-next-line import/no-default-export\nexport default {\n Analytics,\n track,\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 { AllowedPropertyValues, Mode } from './types';\n\nexport function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nfunction detectEnvironment(): 'development' | 'production' {\n if (typeof process === 'undefined') return 'production';\n\n if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test')\n return 'development';\n\n return 'production';\n}\n\nexport function setMode(mode: Mode = 'auto'): void {\n if (mode === 'auto') {\n window.vam = detectEnvironment();\n return;\n }\n\n window.vam = mode;\n}\n\nexport function getMode(): Mode {\n return window.vam || 'production';\n}\n\nexport function isProduction(): boolean {\n return getMode() === 'production';\n}\n\nexport function isDevelopment(): boolean {\n return getMode() === 'development';\n}\n\nconst removeKey = (key: string, { [key]: _, ...rest }): Record<string, any> =>\n rest;\n\nexport function parseProperties(\n properties: Record<string, unknown>,\n options: {\n strip?: boolean;\n },\n): Error | Record<string, AllowedPropertyValues> | undefined {\n let props = properties;\n const errorProperties: string[] = [];\n for (const [key, value] of Object.entries(properties)) {\n if (typeof value === 'object' && value !== null) {\n if (options.strip) {\n props = removeKey(key, props);\n } else {\n errorProperties.push(key);\n }\n }\n }\n\n if (errorProperties.length > 0 && !options.strip) {\n throw Error(\n `The following properties are not valid: ${errorProperties.join(\n ', ',\n )}. Only strings, numbers, booleans, and null are allowed.`,\n );\n }\n return props as Record<string, AllowedPropertyValues>;\n}\n","import { initQueue } from './queue';\nimport type { AllowedPropertyValues, AnalyticsProps } from './types';\nimport {\n isBrowser,\n parseProperties,\n setMode,\n isDevelopment,\n isProduction,\n} from './utils';\n\nexport const inject = (\n props: AnalyticsProps = {\n debug: true,\n },\n): void => {\n if (!isBrowser()) return;\n\n setMode(props.mode);\n\n initQueue();\n\n if (props.beforeSend) {\n window.va?.('beforeSend', props.beforeSend);\n }\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() && props.debug === false) {\n script.setAttribute('data-debug', 'false');\n }\n\n document.head.appendChild(script);\n};\n\nexport const track = (\n name: string,\n properties?: Record<string, AllowedPropertyValues>,\n): void => {\n if (!isBrowser()) return;\n\n if (!properties) {\n window.va?.('event', { name });\n return;\n }\n\n try {\n const props = parseProperties(properties, {\n strip: isProduction(),\n });\n\n window.va?.('event', {\n name,\n data: props,\n });\n } catch (err) {\n if (err instanceof Error && isDevelopment()) {\n // eslint-disable-next-line no-console\n console.error(err);\n }\n }\n};\n\n// eslint-disable-next-line import/no-default-export\nexport default {\n inject,\n track,\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;AAEA,SAAS,oBAAkD;AACzD,MAAI,OAAO,YAAY;AAAa,WAAO;AAE3C,MAAI,QAAQ,IAAI,aAAa,iBAAiB,QAAQ,IAAI,aAAa;AACrE,WAAO;AAET,SAAO;AACT;AAEO,SAAS,QAAQ,OAAa,QAAc;AACjD,MAAI,SAAS,QAAQ;AACnB,WAAO,MAAM,kBAAkB;AAC/B;AAAA,EACF;AAEA,SAAO,MAAM;AACf;AAEO,SAAS,UAAgB;AAC9B,SAAO,OAAO,OAAO;AACvB;AAEO,SAAS,eAAwB;AACtC,SAAO,QAAQ,MAAM;AACvB;AAEO,SAAS,gBAAyB;AACvC,SAAO,QAAQ,MAAM;AACvB;AAEA,IAAM,YAAY,CAAC,KAAa,GAAG,MAAM,MAAM,KAAK,MAClD;AAEK,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,SAAS;AAAA,MACnB;AAAA,MACA,MAAM;AAAA,IACR;AAAA,EACF,SAAS,KAAP;AACA,QAAI,eAAe,SAAS,cAAc,GAAG;AAE3C,cAAQ,MAAM,GAAG;AAAA,IACnB;AAAA,EACF;AACF;;;AHhEA,SAAS,UAAU;AAAA,EACjB;AAAA,EACA,QAAQ;AAAA,EACR,OAAO;AACT,GAAyB;AACvB,YAAU,MAAM;AACd,WAAO,EAAE,YAAY,OAAO,KAAK,CAAC;AAAA,EACpC,GAAG,CAAC,YAAY,OAAO,IAAI,CAAC;AAE5B,SAAO;AACT;AAKA,IAAO,gBAAQ;AAAA,EACb;AAAA,EACA;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/react.tsx","../../src/queue.ts","../../src/utils.ts","../../src/generic.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport { inject, track } from './generic';\nimport type { AnalyticsProps } from './types';\n\nfunction 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}\nexport { track, Analytics };\nexport type { AnalyticsProps };\n\n// eslint-disable-next-line import/no-default-export\nexport default {\n Analytics,\n track,\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 { AllowedPropertyValues, Mode } from './types';\n\nexport function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nfunction detectEnvironment(): 'development' | 'production' {\n try {\n const env = process.env.NODE_ENV;\n if (env === 'development' || env === 'test') {\n return 'development';\n }\n } catch (e) {\n // do nothing, this is okay\n }\n return 'production';\n}\n\nexport function setMode(mode: Mode = 'auto'): void {\n if (mode === 'auto') {\n window.vam = detectEnvironment();\n return;\n }\n\n window.vam = mode;\n}\n\nexport function getMode(): Mode {\n return window.vam || 'production';\n}\n\nexport function isProduction(): boolean {\n return getMode() === 'production';\n}\n\nexport function isDevelopment(): boolean {\n return getMode() === 'development';\n}\n\nfunction removeKey(\n key: string,\n { [key]: _, ...rest },\n): Record<string, unknown> {\n return rest;\n}\n\nexport function parseProperties(\n properties: Record<string, unknown>,\n options: {\n strip?: boolean;\n },\n): Error | Record<string, AllowedPropertyValues> | undefined {\n let props = properties;\n const errorProperties: string[] = [];\n for (const [key, value] of Object.entries(properties)) {\n if (typeof value === 'object' && value !== null) {\n if (options.strip) {\n props = removeKey(key, props);\n } else {\n errorProperties.push(key);\n }\n }\n }\n\n if (errorProperties.length > 0 && !options.strip) {\n throw Error(\n `The following properties are not valid: ${errorProperties.join(\n ', ',\n )}. Only strings, numbers, booleans, and null are allowed.`,\n );\n }\n return props as Record<string, AllowedPropertyValues>;\n}\n","import { name as packageName, version } from '../package.json';\nimport { initQueue } from './queue';\nimport type { AllowedPropertyValues, AnalyticsProps } from './types';\nimport {\n isBrowser,\n parseProperties,\n setMode,\n isDevelopment,\n isProduction,\n} from './utils';\n\nexport function inject(\n props: AnalyticsProps = {\n debug: true,\n },\n): void {\n if (!isBrowser()) return;\n\n setMode(props.mode);\n\n initQueue();\n\n if (props.beforeSend) {\n window.va?.('beforeSend', props.beforeSend);\n }\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 script.setAttribute('data-sdkn', packageName);\n script.setAttribute('data-sdkv', version);\n\n if (isDevelopment() && props.debug === false) {\n script.setAttribute('data-debug', 'false');\n }\n\n document.head.appendChild(script);\n}\n\nexport function track(\n name: string,\n properties?: Record<string, AllowedPropertyValues>,\n): void {\n if (!isBrowser()) {\n // eslint-disable-next-line no-console\n console.warn(\n '[Vercel Analytics] Server-side execution of `track()` is currently not supported.',\n );\n return;\n }\n\n if (!properties) {\n window.va?.('event', { name });\n return;\n }\n\n try {\n const props = parseProperties(properties, {\n strip: isProduction(),\n });\n\n window.va?.('event', {\n name,\n data: props,\n });\n } catch (err) {\n if (err instanceof Error && isDevelopment()) {\n // eslint-disable-next-line no-console\n console.error(err);\n }\n }\n}\n\n// eslint-disable-next-line import/no-default-export\nexport default {\n inject,\n track,\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;AAEA,SAAS,oBAAkD;AACzD,MAAI;AACF,UAAM,MAAM,QAAQ,IAAI;AACxB,QAAI,QAAQ,iBAAiB,QAAQ,QAAQ;AAC3C,aAAO;AAAA,IACT;AAAA,EACF,SAAS,GAAP;AAAA,EAEF;AACA,SAAO;AACT;AAEO,SAAS,QAAQ,OAAa,QAAc;AACjD,MAAI,SAAS,QAAQ;AACnB,WAAO,MAAM,kBAAkB;AAC/B;AAAA,EACF;AAEA,SAAO,MAAM;AACf;AAEO,SAAS,UAAgB;AAC9B,SAAO,OAAO,OAAO;AACvB;AAEO,SAAS,eAAwB;AACtC,SAAO,QAAQ,MAAM;AACvB;AAEO,SAAS,gBAAyB;AACvC,SAAO,QAAQ,MAAM;AACvB;AAEA,SAAS,UACP,KACA,GAAG,MAAM,MAAM,KAAK,GACK;AACzB,SAAO;AACT;AAEO,SAAS,gBACd,YACA,SAG2D;AAC3D,MAAI,QAAQ;AACZ,QAAM,kBAA4B,CAAC;AACnC,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,UAAU,GAAG;AACrD,QAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,UAAI,QAAQ,OAAO;AACjB,gBAAQ,UAAU,KAAK,KAAK;AAAA,MAC9B,OAAO;AACL,wBAAg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ACF;AACF;;;AHzEA,SAAS,UAAU;AAAA,EACjB;AAAA,EACA,QAAQ;AAAA,EACR,OAAO;AACT,GAAyB;AACvB,YAAU,MAAM;AACd,WAAO,EAAE,YAAY,OAAO,KAAK,CAAC;AAAA,EACpC,GAAG,CAAC,YAAY,OAAO,IAAI,CAAC;AAE5B,SAAO;AACT;AAKA,IAAO,gBAAQ;AAAA,EACb;AAAA,EACA;AACF;","names":["name"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/analytics",
3
- "version": "0.1.9-beta.4",
3
+ "version": "0.1.9-beta.6",
4
4
  "keywords": [
5
5
  "analytics",
6
6
  "vercel"
@@ -10,12 +10,14 @@
10
10
  "exports": {
11
11
  "./package.json": "./package.json",
12
12
  ".": {
13
- "require": "./dist/index.cjs",
14
- "import": "./dist/index.js"
13
+ "browser": "./dist/index.js",
14
+ "import": "./dist/index.js",
15
+ "require": "./dist/index.cjs"
15
16
  },
16
17
  "./react": {
17
- "require": "./dist/react/index.cjs",
18
- "import": "./dist/react/index.js"
18
+ "browser": "./dist/react/index.js",
19
+ "import": "./dist/react/index.js",
20
+ "require": "./dist/react/index.cjs"
19
21
  }
20
22
  },
21
23
  "main": "dist/index.js",
package/tsup.config.js CHANGED
@@ -23,5 +23,11 @@ export default defineConfig([
23
23
  index: 'src/react.tsx',
24
24
  },
25
25
  outDir: 'dist/react',
26
+ esbuildOptions: (options) => {
27
+ // Append "use client" to the top of the react entry point
28
+ options.banner = {
29
+ js: '"use client";',
30
+ };
31
+ },
26
32
  },
27
33
  ]);