@vercel/analytics 1.6.1 → 2.0.0
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/LICENSE +21 -373
- package/dist/astro/component.ts +1 -3
- package/dist/astro/index.astro +17 -2
- package/dist/index.d.mts +12 -7
- package/dist/index.d.ts +12 -7
- package/dist/index.js +66 -30
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +66 -30
- package/dist/index.mjs.map +1 -1
- package/dist/next/index.d.mts +4 -1
- package/dist/next/index.d.ts +4 -1
- package/dist/next/index.js +88 -36
- package/dist/next/index.js.map +1 -1
- package/dist/next/index.mjs +88 -36
- package/dist/next/index.mjs.map +1 -1
- package/dist/nuxt/index.d.mts +3 -31
- package/dist/nuxt/index.d.ts +3 -31
- package/dist/nuxt/index.js +30 -191
- package/dist/nuxt/index.js.map +1 -1
- package/dist/nuxt/index.mjs +26 -180
- package/dist/nuxt/index.mjs.map +1 -1
- package/dist/nuxt/runtime/index.d.mts +51 -0
- package/dist/nuxt/runtime/index.d.ts +51 -0
- package/dist/nuxt/runtime/index.js +365 -0
- package/dist/nuxt/runtime/index.js.map +1 -0
- package/dist/nuxt/runtime/index.mjs +336 -0
- package/dist/nuxt/runtime/index.mjs.map +1 -0
- package/dist/react/index.d.mts +5 -1
- package/dist/react/index.d.ts +5 -1
- package/dist/react/index.js +80 -35
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +80 -35
- package/dist/react/index.mjs.map +1 -1
- package/dist/remix/index.d.mts +4 -1
- package/dist/remix/index.d.ts +4 -1
- package/dist/remix/index.js +88 -36
- package/dist/remix/index.js.map +1 -1
- package/dist/remix/index.mjs +88 -36
- package/dist/remix/index.mjs.map +1 -1
- package/dist/server/index.js +15 -11
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +13 -9
- package/dist/server/index.mjs.map +1 -1
- package/dist/sveltekit/index.d.mts +4 -1
- package/dist/sveltekit/index.d.ts +4 -1
- package/dist/sveltekit/index.js +82 -37
- package/dist/sveltekit/index.js.map +1 -1
- package/dist/sveltekit/index.mjs +83 -36
- package/dist/sveltekit/index.mjs.map +1 -1
- package/dist/vue/index.d.mts +4 -1
- package/dist/vue/index.d.ts +4 -1
- package/dist/vue/index.js +85 -37
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/index.mjs +85 -37
- package/dist/vue/index.mjs.map +1 -1
- package/package.json +17 -22
- package/test.setup.ts +3 -0
- package/tsup.config.js +17 -2
- package/vitest.config.mts +0 -1
- package/jest.config.js +0 -9
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
// src/nuxt/runtime/index.ts
|
|
2
|
+
import { onNuxtReady, useRoute as useRoute2, useRouter } from "nuxt/app";
|
|
3
|
+
|
|
4
|
+
// src/queue.ts
|
|
5
|
+
var initQueue = () => {
|
|
6
|
+
if (window.va) return;
|
|
7
|
+
window.va = function a(...params) {
|
|
8
|
+
if (!window.vaq) window.vaq = [];
|
|
9
|
+
window.vaq.push(params);
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// package.json
|
|
14
|
+
var name = "@vercel/analytics";
|
|
15
|
+
var version = "2.0.0";
|
|
16
|
+
|
|
17
|
+
// src/utils.ts
|
|
18
|
+
function isBrowser() {
|
|
19
|
+
return typeof window !== "undefined";
|
|
20
|
+
}
|
|
21
|
+
function detectEnvironment() {
|
|
22
|
+
try {
|
|
23
|
+
const env = process.env.NODE_ENV;
|
|
24
|
+
if (env === "development" || env === "test") {
|
|
25
|
+
return "development";
|
|
26
|
+
}
|
|
27
|
+
} catch {
|
|
28
|
+
}
|
|
29
|
+
return "production";
|
|
30
|
+
}
|
|
31
|
+
function setMode(mode = "auto") {
|
|
32
|
+
if (mode === "auto") {
|
|
33
|
+
window.vam = detectEnvironment();
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
window.vam = mode;
|
|
37
|
+
}
|
|
38
|
+
function getMode() {
|
|
39
|
+
const mode = isBrowser() ? window.vam : detectEnvironment();
|
|
40
|
+
return mode || "production";
|
|
41
|
+
}
|
|
42
|
+
function isProduction() {
|
|
43
|
+
return getMode() === "production";
|
|
44
|
+
}
|
|
45
|
+
function isDevelopment() {
|
|
46
|
+
return getMode() === "development";
|
|
47
|
+
}
|
|
48
|
+
function removeKey(key, { [key]: _, ...rest }) {
|
|
49
|
+
return rest;
|
|
50
|
+
}
|
|
51
|
+
function parseProperties(properties, options) {
|
|
52
|
+
if (!properties) return void 0;
|
|
53
|
+
let props = properties;
|
|
54
|
+
const errorProperties = [];
|
|
55
|
+
for (const [key, value] of Object.entries(properties)) {
|
|
56
|
+
if (typeof value === "object" && value !== null) {
|
|
57
|
+
if (options.strip) {
|
|
58
|
+
props = removeKey(key, props);
|
|
59
|
+
} else {
|
|
60
|
+
errorProperties.push(key);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (errorProperties.length > 0 && !options.strip) {
|
|
65
|
+
throw Error(
|
|
66
|
+
`The following properties are not valid: ${errorProperties.join(
|
|
67
|
+
", "
|
|
68
|
+
)}. Only strings, numbers, booleans, and null are allowed.`
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
return props;
|
|
72
|
+
}
|
|
73
|
+
function computeRoute(pathname, pathParams) {
|
|
74
|
+
if (!pathname || !pathParams) {
|
|
75
|
+
return pathname;
|
|
76
|
+
}
|
|
77
|
+
let result = pathname;
|
|
78
|
+
try {
|
|
79
|
+
const entries = Object.entries(pathParams);
|
|
80
|
+
for (const [key, value] of entries) {
|
|
81
|
+
if (!Array.isArray(value)) {
|
|
82
|
+
const matcher = turnValueToRegExp(value);
|
|
83
|
+
if (matcher.test(result)) {
|
|
84
|
+
result = result.replace(matcher, `/[${key}]`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
for (const [key, value] of entries) {
|
|
89
|
+
if (Array.isArray(value)) {
|
|
90
|
+
const matcher = turnValueToRegExp(value.join("/"));
|
|
91
|
+
if (matcher.test(result)) {
|
|
92
|
+
result = result.replace(matcher, `/[...${key}]`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return result;
|
|
97
|
+
} catch {
|
|
98
|
+
return pathname;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function turnValueToRegExp(value) {
|
|
102
|
+
return new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);
|
|
103
|
+
}
|
|
104
|
+
function escapeRegExp(string) {
|
|
105
|
+
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
106
|
+
}
|
|
107
|
+
function getScriptSrc(props) {
|
|
108
|
+
if (props.scriptSrc) {
|
|
109
|
+
return makeAbsolute(props.scriptSrc);
|
|
110
|
+
}
|
|
111
|
+
if (isDevelopment()) {
|
|
112
|
+
return "https://va.vercel-scripts.com/v1/script.debug.js";
|
|
113
|
+
}
|
|
114
|
+
if (props.basePath) {
|
|
115
|
+
return makeAbsolute(`${props.basePath}/insights/script.js`);
|
|
116
|
+
}
|
|
117
|
+
return "/_vercel/insights/script.js";
|
|
118
|
+
}
|
|
119
|
+
function loadProps(explicitProps, confString) {
|
|
120
|
+
var _a;
|
|
121
|
+
let props = explicitProps;
|
|
122
|
+
if (confString) {
|
|
123
|
+
try {
|
|
124
|
+
props = {
|
|
125
|
+
...(_a = JSON.parse(confString)) == null ? void 0 : _a.analytics,
|
|
126
|
+
...explicitProps
|
|
127
|
+
};
|
|
128
|
+
} catch {
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
setMode(props.mode);
|
|
132
|
+
const dataset = {
|
|
133
|
+
sdkn: name + (props.framework ? `/${props.framework}` : ""),
|
|
134
|
+
sdkv: version
|
|
135
|
+
};
|
|
136
|
+
if (props.disableAutoTrack) {
|
|
137
|
+
dataset.disableAutoTrack = "1";
|
|
138
|
+
}
|
|
139
|
+
if (props.viewEndpoint) {
|
|
140
|
+
dataset.viewEndpoint = makeAbsolute(props.viewEndpoint);
|
|
141
|
+
}
|
|
142
|
+
if (props.eventEndpoint) {
|
|
143
|
+
dataset.eventEndpoint = makeAbsolute(props.eventEndpoint);
|
|
144
|
+
}
|
|
145
|
+
if (props.sessionEndpoint) {
|
|
146
|
+
dataset.sessionEndpoint = makeAbsolute(props.sessionEndpoint);
|
|
147
|
+
}
|
|
148
|
+
if (isDevelopment() && props.debug === false) {
|
|
149
|
+
dataset.debug = "false";
|
|
150
|
+
}
|
|
151
|
+
if (props.dsn) {
|
|
152
|
+
dataset.dsn = props.dsn;
|
|
153
|
+
}
|
|
154
|
+
if (props.endpoint) {
|
|
155
|
+
dataset.endpoint = props.endpoint;
|
|
156
|
+
} else if (props.basePath) {
|
|
157
|
+
dataset.endpoint = makeAbsolute(`${props.basePath}/insights`);
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
beforeSend: props.beforeSend,
|
|
161
|
+
src: getScriptSrc(props),
|
|
162
|
+
dataset
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
function makeAbsolute(url) {
|
|
166
|
+
return url.startsWith("http://") || url.startsWith("https://") || url.startsWith("/") ? url : `/${url}`;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// src/generic.ts
|
|
170
|
+
function inject(props = {
|
|
171
|
+
debug: true
|
|
172
|
+
}, confString) {
|
|
173
|
+
var _a;
|
|
174
|
+
if (!isBrowser()) return;
|
|
175
|
+
const { beforeSend, src, dataset } = loadProps(props, confString);
|
|
176
|
+
initQueue();
|
|
177
|
+
if (beforeSend) {
|
|
178
|
+
(_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", beforeSend);
|
|
179
|
+
}
|
|
180
|
+
if (document.head.querySelector(`script[src*="${src}"]`)) return;
|
|
181
|
+
const script = document.createElement("script");
|
|
182
|
+
script.src = src;
|
|
183
|
+
for (const [key, value] of Object.entries(dataset)) {
|
|
184
|
+
script.dataset[key] = value;
|
|
185
|
+
}
|
|
186
|
+
script.defer = true;
|
|
187
|
+
script.onerror = () => {
|
|
188
|
+
const errorMessage = isDevelopment() ? "Please check if any ad blockers are enabled and try again." : "Be sure to enable Web Analytics for your project and deploy again. See https://vercel.com/docs/analytics/quickstart for more information.";
|
|
189
|
+
console.log(
|
|
190
|
+
`[Vercel Web Analytics] Failed to load script from ${src}. ${errorMessage}`
|
|
191
|
+
);
|
|
192
|
+
};
|
|
193
|
+
document.head.appendChild(script);
|
|
194
|
+
}
|
|
195
|
+
function track(name2, properties, options) {
|
|
196
|
+
var _a, _b;
|
|
197
|
+
if (!isBrowser()) {
|
|
198
|
+
const msg = "[Vercel Web Analytics] Please import `track` from `@vercel/analytics/server` when using this function in a server environment";
|
|
199
|
+
if (isProduction()) {
|
|
200
|
+
console.warn(msg);
|
|
201
|
+
} else {
|
|
202
|
+
throw new Error(msg);
|
|
203
|
+
}
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
if (!properties) {
|
|
207
|
+
(_a = window.va) == null ? void 0 : _a.call(window, "event", { name: name2, options });
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
try {
|
|
211
|
+
const props = parseProperties(properties, {
|
|
212
|
+
strip: isProduction()
|
|
213
|
+
});
|
|
214
|
+
(_b = window.va) == null ? void 0 : _b.call(window, "event", {
|
|
215
|
+
name: name2,
|
|
216
|
+
data: props,
|
|
217
|
+
options
|
|
218
|
+
});
|
|
219
|
+
} catch (err) {
|
|
220
|
+
if (err instanceof Error && isDevelopment()) {
|
|
221
|
+
console.error(err);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
function pageview({
|
|
226
|
+
route,
|
|
227
|
+
path
|
|
228
|
+
}) {
|
|
229
|
+
var _a;
|
|
230
|
+
(_a = window.va) == null ? void 0 : _a.call(window, "pageview", { route, path });
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// src/vue/create-component.ts
|
|
234
|
+
import { defineComponent, watch } from "vue";
|
|
235
|
+
import { useRoute } from "vue-router";
|
|
236
|
+
|
|
237
|
+
// src/vue/utils.ts
|
|
238
|
+
function getBasePath() {
|
|
239
|
+
try {
|
|
240
|
+
return import.meta.env.VITE_VERCEL_OBSERVABILITY_BASEPATH;
|
|
241
|
+
} catch {
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
function getConfigString() {
|
|
245
|
+
try {
|
|
246
|
+
return import.meta.env.VITE_VERCEL_OBSERVABILITY_CLIENT_CONFIG;
|
|
247
|
+
} catch {
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// src/vue/create-component.ts
|
|
252
|
+
function createComponent(framework = "vue") {
|
|
253
|
+
return defineComponent({
|
|
254
|
+
props: ["dsn", "beforeSend", "debug", "scriptSrc", "endpoint", "mode"],
|
|
255
|
+
setup(props) {
|
|
256
|
+
const route = useRoute();
|
|
257
|
+
inject(
|
|
258
|
+
{
|
|
259
|
+
// trim out undefined values to avoid overriding config values
|
|
260
|
+
...Object.fromEntries(
|
|
261
|
+
Object.entries(props).filter(([_, v]) => v !== void 0)
|
|
262
|
+
),
|
|
263
|
+
basePath: getBasePath(),
|
|
264
|
+
// keep auto-tracking unless we have route support (Nuxt or vue-router).
|
|
265
|
+
disableAutoTrack: Boolean(route),
|
|
266
|
+
framework
|
|
267
|
+
},
|
|
268
|
+
getConfigString()
|
|
269
|
+
);
|
|
270
|
+
if (route && typeof window !== "undefined") {
|
|
271
|
+
const changeRoute = () => {
|
|
272
|
+
pageview({
|
|
273
|
+
route: computeRoute(route.path, route.params),
|
|
274
|
+
path: route.path
|
|
275
|
+
});
|
|
276
|
+
};
|
|
277
|
+
changeRoute();
|
|
278
|
+
watch(route, changeRoute);
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
// Vue component must have a render function, or a template.
|
|
282
|
+
render() {
|
|
283
|
+
return null;
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// src/nuxt/runtime/utils.ts
|
|
289
|
+
function getBasePath2() {
|
|
290
|
+
try {
|
|
291
|
+
return import.meta.env.VITE_VERCEL_OBSERVABILITY_BASEPATH;
|
|
292
|
+
} catch {
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
function getConfigString2() {
|
|
296
|
+
try {
|
|
297
|
+
return import.meta.env.VITE_VERCEL_OBSERVABILITY_CLIENT_CONFIG;
|
|
298
|
+
} catch {
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// src/nuxt/runtime/index.ts
|
|
303
|
+
var Analytics = createComponent("nuxt");
|
|
304
|
+
function injectAnalytics(props = {}) {
|
|
305
|
+
if (isBrowser()) {
|
|
306
|
+
const router = useRouter();
|
|
307
|
+
onNuxtReady(() => {
|
|
308
|
+
inject(
|
|
309
|
+
{
|
|
310
|
+
...props,
|
|
311
|
+
framework: "nuxt",
|
|
312
|
+
disableAutoTrack: true,
|
|
313
|
+
basePath: getBasePath2()
|
|
314
|
+
},
|
|
315
|
+
getConfigString2()
|
|
316
|
+
);
|
|
317
|
+
const route = useRoute2();
|
|
318
|
+
pageview({
|
|
319
|
+
route: computeRoute(route.path, route.params),
|
|
320
|
+
path: route.path
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
router.afterEach((to) => {
|
|
324
|
+
pageview({
|
|
325
|
+
route: computeRoute(to.path, to.params),
|
|
326
|
+
path: to.path
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
export {
|
|
332
|
+
Analytics,
|
|
333
|
+
injectAnalytics,
|
|
334
|
+
track
|
|
335
|
+
};
|
|
336
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/nuxt/runtime/index.ts","../../../src/queue.ts","../../../package.json","../../../src/utils.ts","../../../src/generic.ts","../../../src/vue/create-component.ts","../../../src/vue/utils.ts","../../../src/nuxt/runtime/utils.ts"],"sourcesContent":["import { onNuxtReady, useRoute, useRouter } from 'nuxt/app';\nimport { inject, pageview, track } from '../../generic';\nimport type { AnalyticsProps, BeforeSend, BeforeSendEvent } from '../../types';\nimport { computeRoute, isBrowser } from '../../utils';\nimport { createComponent } from '../../vue/create-component';\nimport { getBasePath, getConfigString } from './utils';\n\n// Export the Analytics component\n// Not recommended as must be used in both app.vue and error.vue\nexport const Analytics = createComponent('nuxt');\nexport type { AnalyticsProps, BeforeSend, BeforeSendEvent };\n\n// Export the injectAnalytics script with automatic tracking on page changes\nfunction injectAnalytics(props: Omit<AnalyticsProps, 'framework'> = {}): void {\n if (isBrowser()) {\n const router = useRouter();\n\n onNuxtReady(() => {\n inject(\n {\n ...props,\n framework: 'nuxt',\n disableAutoTrack: true,\n basePath: getBasePath(),\n },\n getConfigString(),\n );\n const route = useRoute();\n pageview({\n route: computeRoute(route.path, route.params),\n path: route.path,\n });\n });\n // On navigation to a new page\n router.afterEach((to) => {\n pageview({\n route: computeRoute(to.path, to.params),\n path: to.path,\n });\n });\n }\n}\n\nexport { injectAnalytics, track };\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 if (!window.vaq) window.vaq = [];\n window.vaq.push(params);\n };\n};\n","{\n \"name\": \"@vercel/analytics\",\n \"version\": \"2.0.0\",\n \"description\": \"Gain real-time traffic insights with Vercel Web Analytics\",\n \"keywords\": [\n \"analytics\",\n \"vercel\"\n ],\n \"repository\": {\n \"url\": \"github:vercel/analytics\",\n \"directory\": \"packages/web\"\n },\n \"license\": \"MIT\",\n \"exports\": {\n \"./package.json\": \"./package.json\",\n \".\": {\n \"browser\": \"./dist/index.mjs\",\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.js\"\n },\n \"./astro\": {\n \"import\": \"./dist/astro/component.ts\"\n },\n \"./next\": {\n \"browser\": \"./dist/next/index.mjs\",\n \"import\": \"./dist/next/index.mjs\",\n \"require\": \"./dist/next/index.js\"\n },\n \"./nuxt\": {\n \"import\": \"./dist/nuxt/index.mjs\",\n \"require\": \"./dist/nuxt/index.js\"\n },\n \"./nuxt/runtime\": {\n \"browser\": \"./dist/nuxt/runtime/index.mjs\",\n \"import\": \"./dist/nuxt/runtime/index.mjs\",\n \"require\": \"./dist/nuxt/runtime/index.js\"\n },\n \"./react\": {\n \"browser\": \"./dist/react/index.mjs\",\n \"import\": \"./dist/react/index.mjs\",\n \"require\": \"./dist/react/index.js\"\n },\n \"./remix\": {\n \"browser\": \"./dist/remix/index.mjs\",\n \"import\": \"./dist/remix/index.mjs\",\n \"require\": \"./dist/remix/index.js\"\n },\n \"./server\": {\n \"node\": \"./dist/server/index.mjs\",\n \"edge-light\": \"./dist/server/index.mjs\",\n \"import\": \"./dist/server/index.mjs\",\n \"require\": \"./dist/server/index.js\",\n \"default\": \"./dist/server/index.js\"\n },\n \"./sveltekit\": {\n \"svelte\": \"./dist/sveltekit/index.mjs\",\n \"types\": \"./dist/sveltekit/index.d.ts\"\n },\n \"./vue\": {\n \"browser\": \"./dist/vue/index.mjs\",\n \"import\": \"./dist/vue/index.mjs\",\n \"require\": \"./dist/vue/index.js\"\n }\n },\n \"main\": \"./dist/index.mjs\",\n \"types\": \"./dist/index.d.ts\",\n \"typesVersions\": {\n \"*\": {\n \"*\": [\n \"dist/index.d.ts\"\n ],\n \"next\": [\n \"dist/next/index.d.ts\"\n ],\n \"nuxt\": [\n \"dist/nuxt/index.d.ts\"\n ],\n \"nuxt/runtime\": [\n \"dist/nuxt/runtime/index.d.ts\"\n ],\n \"react\": [\n \"dist/react/index.d.ts\"\n ],\n \"remix\": [\n \"dist/remix/index.d.ts\"\n ],\n \"server\": [\n \"dist/server/index.d.ts\"\n ],\n \"sveltekit\": [\n \"dist/sveltekit/index.d.ts\"\n ],\n \"vue\": [\n \"dist/vue/index.d.ts\"\n ]\n }\n },\n \"scripts\": {\n \"build\": \"tsup && pnpm copy-astro\",\n \"copy-astro\": \"cp -R src/astro dist/\",\n \"dev\": \"pnpm copy-astro && tsup --watch\",\n \"test\": \"vitest\"\n },\n \"devDependencies\": {\n \"@nuxt/kit\": \"^4.2.0\",\n \"@nuxt/schema\": \"^4.2.0\",\n \"@swc/core\": \"^1.9.2\",\n \"@testing-library/jest-dom\": \"^6.9.1\",\n \"@testing-library/react\": \"^16.3.1\",\n \"@types/node\": \"^22.9.0\",\n \"@types/react\": \"^18.3.12\",\n \"server-only\": \"^0.0.1\",\n \"svelte\": \"^5.1.10\",\n \"tsup\": \"8.3.5\",\n \"vitest\": \"^4.0.16\",\n \"vue\": \"^3.5.12\",\n \"vue-router\": \"^4.4.5\"\n },\n \"peerDependencies\": {\n \"@remix-run/react\": \"^2\",\n \"@sveltejs/kit\": \"^1 || ^2\",\n \"next\": \">= 13\",\n \"nuxt\": \">= 3\",\n \"react\": \"^18 || ^19 || ^19.0.0-rc\",\n \"svelte\": \">= 4\",\n \"vue\": \"^3\",\n \"vue-router\": \"^4\"\n },\n \"peerDependenciesMeta\": {\n \"@remix-run/react\": {\n \"optional\": true\n },\n \"@sveltejs/kit\": {\n \"optional\": true\n },\n \"next\": {\n \"optional\": true\n },\n \"react\": {\n \"optional\": true\n },\n \"svelte\": {\n \"optional\": true\n },\n \"vue\": {\n \"optional\": true\n },\n \"vue-router\": {\n \"optional\": true\n }\n }\n}\n","import { name as packageName, version } from '../package.json';\nimport type {\n AllowedPropertyValues,\n AnalyticsProps,\n BeforeSend,\n InjectProps,\n Mode,\n} 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 {\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 const mode = isBrowser() ? window.vam : detectEnvironment();\n return mode || '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> | undefined,\n options: {\n strip?: boolean;\n },\n): Error | Record<string, AllowedPropertyValues> | undefined {\n if (!properties) return 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\nexport function computeRoute(\n pathname: string | null,\n pathParams: Record<string, string | string[]> | null,\n): string | null {\n if (!pathname || !pathParams) {\n return pathname;\n }\n\n let result = pathname;\n try {\n const entries = Object.entries(pathParams);\n // simple keys must be handled first\n for (const [key, value] of entries) {\n if (!Array.isArray(value)) {\n const matcher = turnValueToRegExp(value);\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[${key}]`);\n }\n }\n }\n // array values next\n for (const [key, value] of entries) {\n if (Array.isArray(value)) {\n const matcher = turnValueToRegExp(value.join('/'));\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[...${key}]`);\n }\n }\n }\n return result;\n } catch {\n return pathname;\n }\n}\n\nfunction turnValueToRegExp(value: string): RegExp {\n return new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);\n}\n\nfunction escapeRegExp(string: string): string {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\nfunction getScriptSrc(props: AnalyticsProps & { basePath?: string }): string {\n if (props.scriptSrc) {\n return makeAbsolute(props.scriptSrc);\n }\n if (isDevelopment()) {\n return 'https://va.vercel-scripts.com/v1/script.debug.js';\n }\n if (props.basePath) {\n return makeAbsolute(`${props.basePath}/insights/script.js`);\n }\n return '/_vercel/insights/script.js';\n}\n\nexport function loadProps(\n explicitProps: InjectProps,\n confString?: string,\n): {\n src: string;\n beforeSend?: BeforeSend;\n dataset: Record<string, string>;\n} {\n let props = explicitProps;\n if (confString) {\n try {\n props = {\n ...(JSON.parse(confString)?.analytics as InjectProps),\n ...explicitProps,\n };\n } catch {\n // do nothing\n }\n }\n setMode(props.mode);\n\n const dataset: Record<string, string> = {\n sdkn: packageName + (props.framework ? `/${props.framework}` : ''),\n sdkv: version,\n };\n if (props.disableAutoTrack) {\n dataset.disableAutoTrack = '1';\n }\n if (props.viewEndpoint) {\n dataset.viewEndpoint = makeAbsolute(props.viewEndpoint);\n }\n if (props.eventEndpoint) {\n dataset.eventEndpoint = makeAbsolute(props.eventEndpoint);\n }\n if (props.sessionEndpoint) {\n dataset.sessionEndpoint = makeAbsolute(props.sessionEndpoint);\n }\n if (isDevelopment() && props.debug === false) {\n dataset.debug = 'false';\n }\n if (props.dsn) {\n dataset.dsn = props.dsn;\n }\n // deprecated\n if (props.endpoint) {\n dataset.endpoint = props.endpoint;\n } else if (props.basePath) {\n dataset.endpoint = makeAbsolute(`${props.basePath}/insights`);\n }\n\n return {\n beforeSend: props.beforeSend,\n src: getScriptSrc(props),\n dataset,\n };\n}\n\nfunction makeAbsolute(url: string): string {\n return url.startsWith('http://') ||\n url.startsWith('https://') ||\n url.startsWith('/')\n ? url\n : `/${url}`;\n}\n","import { initQueue } from './queue';\nimport type {\n AllowedPropertyValues,\n AnalyticsProps,\n BeforeSend,\n BeforeSendEvent,\n FlagsDataInput,\n InjectProps,\n} from './types';\nimport {\n computeRoute,\n isBrowser,\n isDevelopment,\n isProduction,\n loadProps,\n parseProperties,\n} from './utils';\n\n/**\n * Injects the Vercel Web Analytics script into the page head and starts tracking page views. Read more in our [documentation](https://vercel.com/docs/concepts/analytics/package).\n * @param props - Analytics options.\n * @param [props.mode] - The mode to use for the analytics script. Defaults to `auto`.\n * - `auto` - Automatically detect the environment. Uses `production` if the environment cannot be determined.\n * - `production` - Always use the production script. (Sends events to the server)\n * - `development` - Always use the development script. (Logs events to the console)\n * @param [props.debug] - Whether to enable debug logging in development. Defaults to `true`.\n * @param [props.beforeSend] - A middleware function to modify events before they are sent. Should return the event object or `null` to cancel the event.\n * @param [props.dsn] - The DSN of the project to send events to. Only required when self-hosting.\n * @param [props.disableAutoTrack] - Whether the injected script should track page views from pushState events. Disable if route is updated after pushState, a manually call page pageview().\n * @param [confString] - an optional JSON string (InjectProps) containing the default configuration. Explicit props will take over any provided default.\n */\nfunction inject(\n props: InjectProps = {\n debug: true,\n },\n confString?: string,\n): void {\n if (!isBrowser()) return;\n\n const { beforeSend, src, dataset } = loadProps(props, confString);\n initQueue();\n\n if (beforeSend) {\n window.va?.('beforeSend', beforeSend);\n }\n if (document.head.querySelector(`script[src*=\"${src}\"]`)) return;\n\n const script = document.createElement('script');\n script.src = src;\n for (const [key, value] of Object.entries(dataset)) {\n script.dataset[key] = value;\n }\n script.defer = true;\n script.onerror = (): void => {\n const errorMessage = isDevelopment()\n ? 'Please check if any ad blockers are enabled and try again.'\n : 'Be sure to enable Web Analytics for your project and deploy again. See https://vercel.com/docs/analytics/quickstart for more information.';\n\n console.log(\n `[Vercel Web Analytics] Failed to load script from ${src}. ${errorMessage}`,\n );\n };\n\n document.head.appendChild(script);\n}\n\n/**\n * Tracks a custom event. Please refer to the [documentation](https://vercel.com/docs/concepts/analytics/custom-events) for more information on custom events.\n * @param name - The name of the event.\n * * Examples: `Purchase`, `Click Button`, or `Play Video`.\n * @param [properties] - Additional properties of the event. Nested objects are not supported. Allowed values are `string`, `number`, `boolean`, and `null`.\n */\nfunction track(\n name: string,\n properties?: Record<string, AllowedPropertyValues>,\n options?: {\n flags?: FlagsDataInput;\n },\n): void {\n if (!isBrowser()) {\n const msg =\n '[Vercel Web Analytics] Please import `track` from `@vercel/analytics/server` when using this function in a server environment';\n\n if (isProduction()) {\n console.warn(msg);\n } else {\n throw new Error(msg);\n }\n\n return;\n }\n\n if (!properties) {\n window.va?.('event', { name, options });\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 options,\n });\n } catch (err) {\n if (err instanceof Error && isDevelopment()) {\n console.error(err);\n }\n }\n}\n\nfunction pageview({\n route,\n path,\n}: {\n route?: string | null;\n path?: string;\n}): void {\n window.va?.('pageview', { route, path });\n}\n\nexport { inject, track, pageview, computeRoute };\nexport type { AnalyticsProps, BeforeSend, BeforeSendEvent };\n\nexport default {\n inject,\n track,\n computeRoute,\n};\n","import { defineComponent, watch } from 'vue';\n// for barebone vue project, vite will issue a warning since 'vue-router' import can't be resolved,\nimport { useRoute } from 'vue-router';\nimport { type AnalyticsProps, inject, pageview } from '../generic';\nimport { computeRoute } from '../utils';\nimport { getBasePath, getConfigString } from './utils';\n\nexport function createComponent(\n framework = 'vue',\n): ReturnType<typeof defineComponent> {\n return defineComponent({\n props: ['dsn', 'beforeSend', 'debug', 'scriptSrc', 'endpoint', 'mode'],\n setup(props: Omit<AnalyticsProps, 'framework'>) {\n const route = useRoute();\n inject(\n {\n // trim out undefined values to avoid overriding config values\n ...Object.fromEntries(\n Object.entries(props).filter(([_, v]) => v !== undefined),\n ),\n basePath: getBasePath(),\n // keep auto-tracking unless we have route support (Nuxt or vue-router).\n disableAutoTrack: Boolean(route),\n framework,\n },\n getConfigString(),\n );\n if (route && typeof window !== 'undefined') {\n const changeRoute = (): void => {\n pageview({\n route: computeRoute(route.path, route.params),\n path: route.path,\n });\n };\n changeRoute();\n watch(route, changeRoute);\n }\n },\n // Vue component must have a render function, or a template.\n render() {\n return null;\n },\n });\n}\n","// !! important !!\n// do not access env variables using import.meta.env[varname]\n// some bundlers won't replace the value at build time.\n\nexport function getBasePath(): string | undefined {\n try {\n return import.meta.env.VITE_VERCEL_OBSERVABILITY_BASEPATH as\n | string\n | undefined;\n } catch {\n // do nothing\n }\n}\n\nexport function getConfigString(): string | undefined {\n try {\n return import.meta.env.VITE_VERCEL_OBSERVABILITY_CLIENT_CONFIG as\n | string\n | undefined;\n } catch {\n // do nothing\n }\n}\n","// !! important !!\n// do not access env variables using import.meta.env[varname]\n// some bundlers won't replace the value at build time.\n\nexport function getBasePath(): string | undefined {\n try {\n return import.meta.env.VITE_VERCEL_OBSERVABILITY_BASEPATH as\n | string\n | undefined;\n } catch {\n // do nothing\n }\n}\n\nexport function getConfigString(): string | undefined {\n try {\n return import.meta.env.VITE_VERCEL_OBSERVABILITY_CLIENT_CONFIG as\n | string\n | undefined;\n } catch {\n // do nothing\n }\n}\n"],"mappings":";AAAA,SAAS,aAAa,YAAAA,WAAU,iBAAiB;;;ACA1C,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO,GAAI;AAEf,SAAO,KAAK,SAAS,KAAK,QAAc;AACtC,QAAI,CAAC,OAAO,IAAK,QAAO,MAAM,CAAC;AAC/B,WAAO,IAAI,KAAK,MAAM;AAAA,EACxB;AACF;;;ACPE,WAAQ;AACR,cAAW;;;ACON,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,QAAQ;AAAA,EAER;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,QAAM,OAAO,UAAU,IAAI,OAAO,MAAM,kBAAkB;AAC1D,SAAO,QAAQ;AACjB;AAEO,SAAS,eAAwB;AACtC,SAAO,QAAQ,MAAM;AACvB;AAEO,SAAS,gBAAyB;AACvC,SAAO,QAAQ,MAAM;AACvB;AAEA,SAAS,UACP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aAAa,MAAM,MAAM,MAAM,MAAM;AAAA,YAC5C,MAAM,MAAM;AAAA,UACd,CAAC;AAAA,QACH;AACA,oBAAY;AACZ,cAAM,OAAO,WAAW;AAAA,MAC1B;AAAA,IACF;AAAA;AAAA,IAEA,SAAS;AACP,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACH;;;AEvCO,SAASC,eAAkC;AAChD,MAAI;AACF,WAAO,YAAY,IAAI;AAAA,EAGzB,QAAQ;AAAA,EAER;AACF;AAEO,SAASC,mBAAsC;AACpD,MAAI;AACF,WAAO,YAAY,IAAI;AAAA,EAGzB,QAAQ;AAAA,EAER;AACF;;;APbO,IAAM,YAAY,gBAAgB,MAAM;AAI/C,SAAS,gBAAgB,QAA2C,CAAC,GAAS;AAC5E,MAAI,UAAU,GAAG;AACf,UAAM,SAAS,UAAU;AAEzB,gBAAY,MAAM;AAChB;AAAA,QACE;AAAA,UACE,GAAG;AAAA,UACH,WAAW;AAAA,UACX,kBAAkB;AAAA,UAClB,UAAUC,aAAY;AAAA,QACxB;AAAA,QACAC,iBAAgB;AAAA,MAClB;AACA,YAAM,QAAQC,UAAS;AACvB,eAAS;AAAA,QACP,OAAO,aAAa,MAAM,MAAM,MAAM,MAAM;AAAA,QAC5C,MAAM,MAAM;AAAA,MACd,CAAC;AAAA,IACH,CAAC;AAED,WAAO,UAAU,CAAC,OAAO;AACvB,eAAS;AAAA,QACP,OAAO,aAAa,GAAG,MAAM,GAAG,MAAM;AAAA,QACtC,MAAM,GAAG;AAAA,MACX,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AACF;","names":["useRoute","name","getBasePath","getConfigString","getBasePath","getConfigString","useRoute"]}
|
package/dist/react/index.d.mts
CHANGED
|
@@ -15,8 +15,11 @@ interface AnalyticsProps {
|
|
|
15
15
|
debug?: boolean;
|
|
16
16
|
mode?: Mode;
|
|
17
17
|
scriptSrc?: string;
|
|
18
|
-
endpoint?: string;
|
|
19
18
|
dsn?: string;
|
|
19
|
+
eventEndpoint?: string;
|
|
20
|
+
viewEndpoint?: string;
|
|
21
|
+
sessionEndpoint?: string;
|
|
22
|
+
endpoint?: string;
|
|
20
23
|
}
|
|
21
24
|
declare global {
|
|
22
25
|
interface Window {
|
|
@@ -69,6 +72,7 @@ declare function Analytics(props: AnalyticsProps & {
|
|
|
69
72
|
route?: string | null;
|
|
70
73
|
path?: string | null;
|
|
71
74
|
basePath?: string;
|
|
75
|
+
configString?: string;
|
|
72
76
|
}): null;
|
|
73
77
|
|
|
74
78
|
export { Analytics, type AnalyticsProps, type BeforeSend, type BeforeSendEvent, track };
|
package/dist/react/index.d.ts
CHANGED
|
@@ -15,8 +15,11 @@ interface AnalyticsProps {
|
|
|
15
15
|
debug?: boolean;
|
|
16
16
|
mode?: Mode;
|
|
17
17
|
scriptSrc?: string;
|
|
18
|
-
endpoint?: string;
|
|
19
18
|
dsn?: string;
|
|
19
|
+
eventEndpoint?: string;
|
|
20
|
+
viewEndpoint?: string;
|
|
21
|
+
sessionEndpoint?: string;
|
|
22
|
+
endpoint?: string;
|
|
20
23
|
}
|
|
21
24
|
declare global {
|
|
22
25
|
interface Window {
|
|
@@ -69,6 +72,7 @@ declare function Analytics(props: AnalyticsProps & {
|
|
|
69
72
|
route?: string | null;
|
|
70
73
|
path?: string | null;
|
|
71
74
|
basePath?: string;
|
|
75
|
+
configString?: string;
|
|
72
76
|
}): null;
|
|
73
77
|
|
|
74
78
|
export { Analytics, type AnalyticsProps, type BeforeSend, type BeforeSendEvent, track };
|
package/dist/react/index.js
CHANGED
|
@@ -27,18 +27,19 @@ __export(react_exports, {
|
|
|
27
27
|
module.exports = __toCommonJS(react_exports);
|
|
28
28
|
var import_react = require("react");
|
|
29
29
|
|
|
30
|
-
// package.json
|
|
31
|
-
var name = "@vercel/analytics";
|
|
32
|
-
var version = "1.6.1";
|
|
33
|
-
|
|
34
30
|
// src/queue.ts
|
|
35
31
|
var initQueue = () => {
|
|
36
32
|
if (window.va) return;
|
|
37
33
|
window.va = function a(...params) {
|
|
38
|
-
(window.vaq
|
|
34
|
+
if (!window.vaq) window.vaq = [];
|
|
35
|
+
window.vaq.push(params);
|
|
39
36
|
};
|
|
40
37
|
};
|
|
41
38
|
|
|
39
|
+
// package.json
|
|
40
|
+
var name = "@vercel/analytics";
|
|
41
|
+
var version = "2.0.0";
|
|
42
|
+
|
|
42
43
|
// src/utils.ts
|
|
43
44
|
function isBrowser() {
|
|
44
45
|
return typeof window !== "undefined";
|
|
@@ -49,7 +50,7 @@ function detectEnvironment() {
|
|
|
49
50
|
if (env === "development" || env === "test") {
|
|
50
51
|
return "development";
|
|
51
52
|
}
|
|
52
|
-
} catch
|
|
53
|
+
} catch {
|
|
53
54
|
}
|
|
54
55
|
return "production";
|
|
55
56
|
}
|
|
@@ -97,55 +98,90 @@ function parseProperties(properties, options) {
|
|
|
97
98
|
}
|
|
98
99
|
function getScriptSrc(props) {
|
|
99
100
|
if (props.scriptSrc) {
|
|
100
|
-
return props.scriptSrc;
|
|
101
|
+
return makeAbsolute(props.scriptSrc);
|
|
101
102
|
}
|
|
102
103
|
if (isDevelopment()) {
|
|
103
104
|
return "https://va.vercel-scripts.com/v1/script.debug.js";
|
|
104
105
|
}
|
|
105
106
|
if (props.basePath) {
|
|
106
|
-
return `${props.basePath}/insights/script.js
|
|
107
|
+
return makeAbsolute(`${props.basePath}/insights/script.js`);
|
|
107
108
|
}
|
|
108
109
|
return "/_vercel/insights/script.js";
|
|
109
110
|
}
|
|
111
|
+
function loadProps(explicitProps, confString) {
|
|
112
|
+
var _a;
|
|
113
|
+
let props = explicitProps;
|
|
114
|
+
if (confString) {
|
|
115
|
+
try {
|
|
116
|
+
props = {
|
|
117
|
+
...(_a = JSON.parse(confString)) == null ? void 0 : _a.analytics,
|
|
118
|
+
...explicitProps
|
|
119
|
+
};
|
|
120
|
+
} catch {
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
setMode(props.mode);
|
|
124
|
+
const dataset = {
|
|
125
|
+
sdkn: name + (props.framework ? `/${props.framework}` : ""),
|
|
126
|
+
sdkv: version
|
|
127
|
+
};
|
|
128
|
+
if (props.disableAutoTrack) {
|
|
129
|
+
dataset.disableAutoTrack = "1";
|
|
130
|
+
}
|
|
131
|
+
if (props.viewEndpoint) {
|
|
132
|
+
dataset.viewEndpoint = makeAbsolute(props.viewEndpoint);
|
|
133
|
+
}
|
|
134
|
+
if (props.eventEndpoint) {
|
|
135
|
+
dataset.eventEndpoint = makeAbsolute(props.eventEndpoint);
|
|
136
|
+
}
|
|
137
|
+
if (props.sessionEndpoint) {
|
|
138
|
+
dataset.sessionEndpoint = makeAbsolute(props.sessionEndpoint);
|
|
139
|
+
}
|
|
140
|
+
if (isDevelopment() && props.debug === false) {
|
|
141
|
+
dataset.debug = "false";
|
|
142
|
+
}
|
|
143
|
+
if (props.dsn) {
|
|
144
|
+
dataset.dsn = props.dsn;
|
|
145
|
+
}
|
|
146
|
+
if (props.endpoint) {
|
|
147
|
+
dataset.endpoint = props.endpoint;
|
|
148
|
+
} else if (props.basePath) {
|
|
149
|
+
dataset.endpoint = makeAbsolute(`${props.basePath}/insights`);
|
|
150
|
+
}
|
|
151
|
+
return {
|
|
152
|
+
beforeSend: props.beforeSend,
|
|
153
|
+
src: getScriptSrc(props),
|
|
154
|
+
dataset
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function makeAbsolute(url) {
|
|
158
|
+
return url.startsWith("http://") || url.startsWith("https://") || url.startsWith("/") ? url : `/${url}`;
|
|
159
|
+
}
|
|
110
160
|
|
|
111
161
|
// src/generic.ts
|
|
112
162
|
function inject(props = {
|
|
113
163
|
debug: true
|
|
114
|
-
}) {
|
|
164
|
+
}, confString) {
|
|
115
165
|
var _a;
|
|
116
166
|
if (!isBrowser()) return;
|
|
117
|
-
|
|
167
|
+
const { beforeSend, src, dataset } = loadProps(props, confString);
|
|
118
168
|
initQueue();
|
|
119
|
-
if (
|
|
120
|
-
(_a = window.va) == null ? void 0 : _a.call(window, "beforeSend",
|
|
169
|
+
if (beforeSend) {
|
|
170
|
+
(_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", beforeSend);
|
|
121
171
|
}
|
|
122
|
-
const src = getScriptSrc(props);
|
|
123
172
|
if (document.head.querySelector(`script[src*="${src}"]`)) return;
|
|
124
173
|
const script = document.createElement("script");
|
|
125
174
|
script.src = src;
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
script.dataset.sdkv = version;
|
|
129
|
-
if (props.disableAutoTrack) {
|
|
130
|
-
script.dataset.disableAutoTrack = "1";
|
|
131
|
-
}
|
|
132
|
-
if (props.endpoint) {
|
|
133
|
-
script.dataset.endpoint = props.endpoint;
|
|
134
|
-
} else if (props.basePath) {
|
|
135
|
-
script.dataset.endpoint = `${props.basePath}/insights`;
|
|
136
|
-
}
|
|
137
|
-
if (props.dsn) {
|
|
138
|
-
script.dataset.dsn = props.dsn;
|
|
175
|
+
for (const [key, value] of Object.entries(dataset)) {
|
|
176
|
+
script.dataset[key] = value;
|
|
139
177
|
}
|
|
178
|
+
script.defer = true;
|
|
140
179
|
script.onerror = () => {
|
|
141
180
|
const errorMessage = isDevelopment() ? "Please check if any ad blockers are enabled and try again." : "Be sure to enable Web Analytics for your project and deploy again. See https://vercel.com/docs/analytics/quickstart for more information.";
|
|
142
181
|
console.log(
|
|
143
182
|
`[Vercel Web Analytics] Failed to load script from ${src}. ${errorMessage}`
|
|
144
183
|
);
|
|
145
184
|
};
|
|
146
|
-
if (isDevelopment() && props.debug === false) {
|
|
147
|
-
script.dataset.debug = "false";
|
|
148
|
-
}
|
|
149
185
|
document.head.appendChild(script);
|
|
150
186
|
}
|
|
151
187
|
function track(name2, properties, options) {
|
|
@@ -193,6 +229,12 @@ function getBasePath() {
|
|
|
193
229
|
}
|
|
194
230
|
return process.env.REACT_APP_VERCEL_OBSERVABILITY_BASEPATH;
|
|
195
231
|
}
|
|
232
|
+
function getConfigString() {
|
|
233
|
+
if (typeof process === "undefined" || typeof process.env === "undefined") {
|
|
234
|
+
return void 0;
|
|
235
|
+
}
|
|
236
|
+
return process.env.REACT_APP_VERCEL_OBSERVABILITY_CLIENT_CONFIG;
|
|
237
|
+
}
|
|
196
238
|
|
|
197
239
|
// src/react/index.tsx
|
|
198
240
|
function Analytics(props) {
|
|
@@ -203,12 +245,15 @@ function Analytics(props) {
|
|
|
203
245
|
}
|
|
204
246
|
}, [props.beforeSend]);
|
|
205
247
|
(0, import_react.useEffect)(() => {
|
|
206
|
-
inject(
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
248
|
+
inject(
|
|
249
|
+
{
|
|
250
|
+
framework: props.framework || "react",
|
|
251
|
+
basePath: props.basePath ?? getBasePath(),
|
|
252
|
+
...props.route !== void 0 && { disableAutoTrack: true },
|
|
253
|
+
...props
|
|
254
|
+
},
|
|
255
|
+
props.configString ?? getConfigString()
|
|
256
|
+
);
|
|
212
257
|
}, []);
|
|
213
258
|
(0, import_react.useEffect)(() => {
|
|
214
259
|
if (props.route && props.path) {
|