@vercel/analytics 1.5.0 → 1.6.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/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/next/index.js +1 -1
- package/dist/next/index.js.map +1 -1
- package/dist/next/index.mjs +1 -1
- package/dist/next/index.mjs.map +1 -1
- package/dist/nuxt/index.d.mts +16 -1
- package/dist/nuxt/index.d.ts +16 -1
- package/dist/nuxt/index.js +99 -3
- package/dist/nuxt/index.js.map +1 -1
- package/dist/nuxt/index.mjs +97 -2
- package/dist/nuxt/index.mjs.map +1 -1
- package/dist/nuxt/module.d.mts +5 -0
- package/dist/nuxt/module.d.ts +5 -0
- package/dist/nuxt/module.js +51 -0
- package/dist/nuxt/module.js.map +1 -0
- package/dist/nuxt/module.mjs +30 -0
- package/dist/nuxt/module.mjs.map +1 -0
- package/dist/react/index.d.mts +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +1 -1
- package/dist/react/index.mjs.map +1 -1
- package/dist/remix/index.js +1 -1
- package/dist/remix/index.js.map +1 -1
- package/dist/remix/index.mjs +1 -1
- package/dist/remix/index.mjs.map +1 -1
- package/dist/server/index.d.mts +1 -1
- package/dist/server/index.d.ts +1 -1
- package/dist/sveltekit/index.d.mts +1 -1
- package/dist/sveltekit/index.d.ts +1 -1
- package/dist/sveltekit/index.js +1 -1
- package/dist/sveltekit/index.js.map +1 -1
- package/dist/sveltekit/index.mjs +1 -1
- package/dist/sveltekit/index.mjs.map +1 -1
- package/dist/vue/index.js +1 -1
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/index.mjs +1 -1
- package/dist/vue/index.mjs.map +1 -1
- package/package.json +9 -1
- package/tsup.config.js +2 -1
package/dist/nuxt/index.js
CHANGED
|
@@ -20,9 +20,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/nuxt/index.ts
|
|
21
21
|
var nuxt_exports = {};
|
|
22
22
|
__export(nuxt_exports, {
|
|
23
|
-
Analytics: () => Analytics
|
|
23
|
+
Analytics: () => Analytics,
|
|
24
|
+
injectAnalytics: () => injectAnalytics,
|
|
25
|
+
track: () => track
|
|
24
26
|
});
|
|
25
27
|
module.exports = __toCommonJS(nuxt_exports);
|
|
28
|
+
var import_app = require("nuxt/app");
|
|
26
29
|
|
|
27
30
|
// src/vue/create-component.ts
|
|
28
31
|
var import_vue = require("vue");
|
|
@@ -30,7 +33,7 @@ var import_vue_router = require("vue-router");
|
|
|
30
33
|
|
|
31
34
|
// package.json
|
|
32
35
|
var name = "@vercel/analytics";
|
|
33
|
-
var version = "1.
|
|
36
|
+
var version = "1.6.0";
|
|
34
37
|
|
|
35
38
|
// src/queue.ts
|
|
36
39
|
var initQueue = () => {
|
|
@@ -65,9 +68,37 @@ function getMode() {
|
|
|
65
68
|
const mode = isBrowser() ? window.vam : detectEnvironment();
|
|
66
69
|
return mode || "production";
|
|
67
70
|
}
|
|
71
|
+
function isProduction() {
|
|
72
|
+
return getMode() === "production";
|
|
73
|
+
}
|
|
68
74
|
function isDevelopment() {
|
|
69
75
|
return getMode() === "development";
|
|
70
76
|
}
|
|
77
|
+
function removeKey(key, { [key]: _, ...rest }) {
|
|
78
|
+
return rest;
|
|
79
|
+
}
|
|
80
|
+
function parseProperties(properties, options) {
|
|
81
|
+
if (!properties) return void 0;
|
|
82
|
+
let props = properties;
|
|
83
|
+
const errorProperties = [];
|
|
84
|
+
for (const [key, value] of Object.entries(properties)) {
|
|
85
|
+
if (typeof value === "object" && value !== null) {
|
|
86
|
+
if (options.strip) {
|
|
87
|
+
props = removeKey(key, props);
|
|
88
|
+
} else {
|
|
89
|
+
errorProperties.push(key);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (errorProperties.length > 0 && !options.strip) {
|
|
94
|
+
throw Error(
|
|
95
|
+
`The following properties are not valid: ${errorProperties.join(
|
|
96
|
+
", "
|
|
97
|
+
)}. Only strings, numbers, booleans, and null are allowed.`
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
return props;
|
|
101
|
+
}
|
|
71
102
|
function computeRoute(pathname, pathParams) {
|
|
72
103
|
if (!pathname || !pathParams) {
|
|
73
104
|
return pathname;
|
|
@@ -155,6 +186,36 @@ function inject(props = {
|
|
|
155
186
|
}
|
|
156
187
|
document.head.appendChild(script);
|
|
157
188
|
}
|
|
189
|
+
function track(name2, properties, options) {
|
|
190
|
+
var _a, _b;
|
|
191
|
+
if (!isBrowser()) {
|
|
192
|
+
const msg = "[Vercel Web Analytics] Please import `track` from `@vercel/analytics/server` when using this function in a server environment";
|
|
193
|
+
if (isProduction()) {
|
|
194
|
+
console.warn(msg);
|
|
195
|
+
} else {
|
|
196
|
+
throw new Error(msg);
|
|
197
|
+
}
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
if (!properties) {
|
|
201
|
+
(_a = window.va) == null ? void 0 : _a.call(window, "event", { name: name2, options });
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
try {
|
|
205
|
+
const props = parseProperties(properties, {
|
|
206
|
+
strip: isProduction()
|
|
207
|
+
});
|
|
208
|
+
(_b = window.va) == null ? void 0 : _b.call(window, "event", {
|
|
209
|
+
name: name2,
|
|
210
|
+
data: props,
|
|
211
|
+
options
|
|
212
|
+
});
|
|
213
|
+
} catch (err) {
|
|
214
|
+
if (err instanceof Error && isDevelopment()) {
|
|
215
|
+
console.error(err);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
158
219
|
function pageview({
|
|
159
220
|
route,
|
|
160
221
|
path
|
|
@@ -203,10 +264,45 @@ function createComponent(framework = "vue") {
|
|
|
203
264
|
});
|
|
204
265
|
}
|
|
205
266
|
|
|
267
|
+
// src/nuxt/utils.ts
|
|
268
|
+
var import_meta2 = {};
|
|
269
|
+
function getBasePath2() {
|
|
270
|
+
try {
|
|
271
|
+
return import_meta2.env.VITE_VERCEL_OBSERVABILITY_BASEPATH;
|
|
272
|
+
} catch {
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
206
276
|
// src/nuxt/index.ts
|
|
207
277
|
var Analytics = createComponent("nuxt");
|
|
278
|
+
function injectAnalytics(props = {}) {
|
|
279
|
+
if (isBrowser()) {
|
|
280
|
+
const router = (0, import_app.useRouter)();
|
|
281
|
+
(0, import_app.onNuxtReady)(() => {
|
|
282
|
+
inject({
|
|
283
|
+
...props,
|
|
284
|
+
framework: "nuxt",
|
|
285
|
+
disableAutoTrack: true,
|
|
286
|
+
basePath: getBasePath2()
|
|
287
|
+
});
|
|
288
|
+
const route = (0, import_app.useRoute)();
|
|
289
|
+
pageview({
|
|
290
|
+
route: computeRoute(route.path, route.params),
|
|
291
|
+
path: route.path
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
router.afterEach((to) => {
|
|
295
|
+
pageview({
|
|
296
|
+
route: computeRoute(to.path, to.params),
|
|
297
|
+
path: to.path
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
}
|
|
208
302
|
// Annotate the CommonJS export names for ESM import in node:
|
|
209
303
|
0 && (module.exports = {
|
|
210
|
-
Analytics
|
|
304
|
+
Analytics,
|
|
305
|
+
injectAnalytics,
|
|
306
|
+
track
|
|
211
307
|
});
|
|
212
308
|
//# sourceMappingURL=index.js.map
|
package/dist/nuxt/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/nuxt/index.ts","../../src/vue/create-component.ts","../../package.json","../../src/queue.ts","../../src/utils.ts","../../src/generic.ts","../../src/vue/utils.ts"],"sourcesContent":["import type { AnalyticsProps, BeforeSend, BeforeSendEvent } from '../types';\nimport { createComponent } from '../vue/create-component';\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- vue's defineComponent return type is any\nexport const Analytics = createComponent('nuxt');\nexport type { AnalyticsProps, BeforeSend, BeforeSendEvent };\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 { inject, pageview, type AnalyticsProps } from '../generic';\nimport { computeRoute } from '../utils';\nimport { getBasePath } 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 // eslint-disable-next-line react-hooks/rules-of-hooks -- this is not a React component.\n const route = useRoute();\n inject({\n ...props,\n basePath: getBasePath(),\n // keep auto-tracking unless we have route support (Nuxt or vue-router).\n disableAutoTrack: Boolean(route),\n framework,\n });\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- route is undefined for barebone vue project.\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","{\n \"name\": \"@vercel/analytics\",\n \"version\": \"1.5.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\": \"MPL-2.0\",\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 \"browser\": \"./dist/nuxt/index.mjs\",\n \"import\": \"./dist/nuxt/index.mjs\",\n \"require\": \"./dist/nuxt/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 \"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 \"lint\": \"eslint .\",\n \"lint-fix\": \"eslint . --fix\",\n \"test\": \"vitest\",\n \"type-check\": \"tsc --noEmit\"\n },\n \"eslintConfig\": {\n \"extends\": [\n \"@vercel/eslint-config\"\n ],\n \"rules\": {\n \"tsdoc/syntax\": \"off\"\n },\n \"ignorePatterns\": [\n \"jest.setup.ts\"\n ]\n },\n \"devDependencies\": {\n \"@swc/core\": \"^1.9.2\",\n \"@testing-library/jest-dom\": \"^6.6.3\",\n \"@testing-library/react\": \"^16.0.1\",\n \"@types/node\": \"^22.9.0\",\n \"@types/react\": \"^18.3.12\",\n \"@vercel/eslint-config\": \"workspace:0.0.0\",\n \"server-only\": \"^0.0.1\",\n \"svelte\": \"^5.1.10\",\n \"tsup\": \"8.3.5\",\n \"vitest\": \"^2.1.5\",\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 \"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","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, AnalyticsProps, 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 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 (e) {\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\nexport function getScriptSrc(\n props: AnalyticsProps & { basePath?: string }\n): string {\n if (props.scriptSrc) {\n return props.scriptSrc;\n }\n if (isDevelopment()) {\n return 'https://va.vercel-scripts.com/v1/script.debug.js';\n }\n if (props.basePath) {\n return `${props.basePath}/insights/script.js`;\n }\n return '/_vercel/insights/script.js';\n}\n","import { name as packageName, version } from '../package.json';\nimport { initQueue } from './queue';\nimport type {\n AllowedPropertyValues,\n AnalyticsProps,\n FlagsDataInput,\n BeforeSend,\n BeforeSendEvent,\n} from './types';\nimport {\n isBrowser,\n parseProperties,\n setMode,\n isDevelopment,\n isProduction,\n computeRoute,\n getScriptSrc,\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 */\nfunction inject(\n props: AnalyticsProps & {\n framework?: string;\n disableAutoTrack?: boolean;\n basePath?: string;\n } = {\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 = getScriptSrc(props);\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.dataset.sdkn =\n packageName + (props.framework ? `/${props.framework}` : '');\n script.dataset.sdkv = version;\n\n if (props.disableAutoTrack) {\n script.dataset.disableAutoTrack = '1';\n }\n if (props.endpoint) {\n script.dataset.endpoint = props.endpoint;\n } else if (props.basePath) {\n script.dataset.endpoint = `${props.basePath}/insights`;\n }\n if (props.dsn) {\n script.dataset.dsn = props.dsn;\n }\n\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 // eslint-disable-next-line no-console -- Logging to console is intentional\n console.log(\n `[Vercel Web Analytics] Failed to load script from ${src}. ${errorMessage}`\n );\n };\n\n if (isDevelopment() && props.debug === false) {\n script.dataset.debug = 'false';\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 // eslint-disable-next-line no-console -- Show warning in production\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 // eslint-disable-next-line no-console -- Logging to console is intentional\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\n// eslint-disable-next-line import/no-default-export -- Default export is intentional\nexport default {\n inject,\n track,\n computeRoute,\n};\n","export function getBasePath(): string | undefined {\n // !! important !!\n // do not access env variables using import.meta.env[varname]\n // some bundles won't replace the value at build time.\n try {\n return import.meta.env.VITE_VERCEL_OBSERVABILITY_BASEPATH as\n | string\n | undefined;\n } catch {\n // do nothing\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,iBAAuC;AAEvC,wBAAyB;;;ACDvB,WAAQ;AACR,cAAW;;;ACFN,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO,GAAI;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,GAAG;AAAA,EAEZ;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;AAMO,SAAS,gBAAyB;AACvC,SAAO,QAAQ,MAAM;AACvB;AAsCO,SAAS,aACd,UACA,YACe;AACf,MAAI,CAAC,YAAY,CAAC,YAAY;AAC5B,WAAO;AAAA,EACT;AAEA,MAAI,SAAS;AACb,MAAI;AACF,UAAM,UAAU,OAAO,QAAQ,UAAU;AAEzC,eAAW,CAAC,KAAK,KAAK,KAAK,SAAS;AAClC,UAAI,CAAC,MAAM,QAA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;AAAA,YAC5C,MAAM,MAAM;AAAA,UACd,CAAC;AAAA,QACH;AACA,oBAAY;AACZ,8BAAM,OAAO,WAAW;AAAA,MAC1B;AAAA,IACF;AAAA;AAAA,IAEA,SAAS;AACP,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACH;;;ADnCO,IAAM,YAAY,gBAAgB,MAAM;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/nuxt/index.ts","../../src/vue/create-component.ts","../../package.json","../../src/queue.ts","../../src/utils.ts","../../src/generic.ts","../../src/vue/utils.ts","../../src/nuxt/utils.ts"],"sourcesContent":["import { onNuxtReady, useRouter, useRoute } from 'nuxt/app';\nimport type { AnalyticsProps, BeforeSend, BeforeSendEvent } from '../types';\nimport { createComponent } from '../vue/create-component';\nimport { inject, pageview, track } from '../generic';\nimport { isBrowser, computeRoute } from '../utils';\nimport { getBasePath } from './utils';\n\n// Export the Analytics component\n// Not recommended as must be used in both app.vue and error.vue\n// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- vue's defineComponent return type is any\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 // eslint-disable-next-line react-hooks/rules-of-hooks -- we are not using a React here\n const router = useRouter();\n\n onNuxtReady(() => {\n inject({\n ...props,\n framework: 'nuxt',\n disableAutoTrack: true,\n basePath: getBasePath(),\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","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 { inject, pageview, type AnalyticsProps } from '../generic';\nimport { computeRoute } from '../utils';\nimport { getBasePath } 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 // eslint-disable-next-line react-hooks/rules-of-hooks -- this is not a React component.\n const route = useRoute();\n inject({\n ...props,\n basePath: getBasePath(),\n // keep auto-tracking unless we have route support (Nuxt or vue-router).\n disableAutoTrack: Boolean(route),\n framework,\n });\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- route is undefined for barebone vue project.\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","{\n \"name\": \"@vercel/analytics\",\n \"version\": \"1.6.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\": \"MPL-2.0\",\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 \"browser\": \"./dist/nuxt/index.mjs\",\n \"import\": \"./dist/nuxt/index.mjs\",\n \"require\": \"./dist/nuxt/index.js\"\n },\n \"./nuxt/module\": {\n \"browser\": \"./dist/nuxt/module.mjs\",\n \"import\": \"./dist/nuxt/module.mjs\",\n \"require\": \"./dist/nuxt/module.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 \"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 \"lint\": \"eslint .\",\n \"lint-fix\": \"eslint . --fix\",\n \"test\": \"vitest\",\n \"type-check\": \"tsc --noEmit\"\n },\n \"eslintConfig\": {\n \"extends\": [\n \"@vercel/eslint-config\"\n ],\n \"rules\": {\n \"tsdoc/syntax\": \"off\"\n },\n \"ignorePatterns\": [\n \"jest.setup.ts\"\n ]\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.6.3\",\n \"@testing-library/react\": \"^16.0.1\",\n \"@types/node\": \"^22.9.0\",\n \"@types/react\": \"^18.3.12\",\n \"@vercel/eslint-config\": \"workspace:0.0.0\",\n \"server-only\": \"^0.0.1\",\n \"svelte\": \"^5.1.10\",\n \"tsup\": \"8.3.5\",\n \"vitest\": \"^2.1.5\",\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","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, AnalyticsProps, 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 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 (e) {\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\nexport function getScriptSrc(\n props: AnalyticsProps & { basePath?: string }\n): string {\n if (props.scriptSrc) {\n return props.scriptSrc;\n }\n if (isDevelopment()) {\n return 'https://va.vercel-scripts.com/v1/script.debug.js';\n }\n if (props.basePath) {\n return `${props.basePath}/insights/script.js`;\n }\n return '/_vercel/insights/script.js';\n}\n","import { name as packageName, version } from '../package.json';\nimport { initQueue } from './queue';\nimport type {\n AllowedPropertyValues,\n AnalyticsProps,\n FlagsDataInput,\n BeforeSend,\n BeforeSendEvent,\n} from './types';\nimport {\n isBrowser,\n parseProperties,\n setMode,\n isDevelopment,\n isProduction,\n computeRoute,\n getScriptSrc,\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 */\nfunction inject(\n props: AnalyticsProps & {\n framework?: string;\n disableAutoTrack?: boolean;\n basePath?: string;\n } = {\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 = getScriptSrc(props);\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.dataset.sdkn =\n packageName + (props.framework ? `/${props.framework}` : '');\n script.dataset.sdkv = version;\n\n if (props.disableAutoTrack) {\n script.dataset.disableAutoTrack = '1';\n }\n if (props.endpoint) {\n script.dataset.endpoint = props.endpoint;\n } else if (props.basePath) {\n script.dataset.endpoint = `${props.basePath}/insights`;\n }\n if (props.dsn) {\n script.dataset.dsn = props.dsn;\n }\n\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 // eslint-disable-next-line no-console -- Logging to console is intentional\n console.log(\n `[Vercel Web Analytics] Failed to load script from ${src}. ${errorMessage}`\n );\n };\n\n if (isDevelopment() && props.debug === false) {\n script.dataset.debug = 'false';\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 // eslint-disable-next-line no-console -- Show warning in production\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 // eslint-disable-next-line no-console -- Logging to console is intentional\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\n// eslint-disable-next-line import/no-default-export -- Default export is intentional\nexport default {\n inject,\n track,\n computeRoute,\n};\n","export function getBasePath(): string | undefined {\n // !! important !!\n // do not access env variables using import.meta.env[varname]\n // some bundles won't replace the value at build time.\n try {\n return import.meta.env.VITE_VERCEL_OBSERVABILITY_BASEPATH as\n | string\n | undefined;\n } catch {\n // do nothing\n }\n}\n","export function getBasePath(): string | undefined {\n // !! important !!\n // do not access env variables using import.meta.env[varname]\n // some bundles won't replace the value at build time.\n try {\n return import.meta.env.VITE_VERCEL_OBSERVABILITY_BASEPATH as\n | string\n | undefined;\n } catch {\n // do nothing\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAiD;;;ACAjD,iBAAuC;AAEvC,wBAAyB;;;ACDvB,WAAQ;AACR,cAAW;;;ACFN,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO,GAAI;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,GAAG;AAAA,EAEZ;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,KACA,EAAE,CAAC,GAAG,GAAG,GAAG,GAAG,KAAK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;AAED,UAAI,SAAS,OAAO,WAAW,aAAa;AAC1C,cAAM,cAAc,MAAY;AAC9B,mBAAS;AAAA,YACP,OAAO,aAAa,MAAM,MAAM,MAAM,MAAM;AAAA,YAC5C,MAAM,MAAM;AAAA,UACd,CAAC;AAAA,QACH;AACA,oBAAY;AACZ,8BAAM,OAAO,WAAW;AAAA,MAC1B;AAAA,IACF;AAAA;AAAA,IAEA,SAAS;AACP,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACH;;;AMvCA,IAAAC,eAAA;AAAO,SAASC,eAAkC;AAIhD,MAAI;AACF,WAAOD,aAAY,IAAI;AAAA,EAGzB,QAAQ;AAAA,EAER;AACF;;;APDO,IAAM,YAAY,gBAAgB,MAAM;AAI/C,SAAS,gBAAgB,QAA2C,CAAC,GAAS;AAC5E,MAAI,UAAU,GAAG;AAEf,UAAM,aAAS,sBAAU;AAEzB,gCAAY,MAAM;AAChB,aAAO;AAAA,QACL,GAAG;AAAA,QACH,WAAW;AAAA,QACX,kBAAkB;AAAA,QAClB,UAAUE,aAAY;AAAA,MACxB,CAAC;AACD,YAAM,YAAQ,qBAAS;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":["name","import_meta","getBasePath","getBasePath"]}
|
package/dist/nuxt/index.mjs
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
// src/nuxt/index.ts
|
|
2
|
+
import { onNuxtReady, useRouter, useRoute as useRoute2 } from "nuxt/app";
|
|
3
|
+
|
|
1
4
|
// src/vue/create-component.ts
|
|
2
5
|
import { defineComponent, watch } from "vue";
|
|
3
6
|
import { useRoute } from "vue-router";
|
|
4
7
|
|
|
5
8
|
// package.json
|
|
6
9
|
var name = "@vercel/analytics";
|
|
7
|
-
var version = "1.
|
|
10
|
+
var version = "1.6.0";
|
|
8
11
|
|
|
9
12
|
// src/queue.ts
|
|
10
13
|
var initQueue = () => {
|
|
@@ -39,9 +42,37 @@ function getMode() {
|
|
|
39
42
|
const mode = isBrowser() ? window.vam : detectEnvironment();
|
|
40
43
|
return mode || "production";
|
|
41
44
|
}
|
|
45
|
+
function isProduction() {
|
|
46
|
+
return getMode() === "production";
|
|
47
|
+
}
|
|
42
48
|
function isDevelopment() {
|
|
43
49
|
return getMode() === "development";
|
|
44
50
|
}
|
|
51
|
+
function removeKey(key, { [key]: _, ...rest }) {
|
|
52
|
+
return rest;
|
|
53
|
+
}
|
|
54
|
+
function parseProperties(properties, options) {
|
|
55
|
+
if (!properties) return void 0;
|
|
56
|
+
let props = properties;
|
|
57
|
+
const errorProperties = [];
|
|
58
|
+
for (const [key, value] of Object.entries(properties)) {
|
|
59
|
+
if (typeof value === "object" && value !== null) {
|
|
60
|
+
if (options.strip) {
|
|
61
|
+
props = removeKey(key, props);
|
|
62
|
+
} else {
|
|
63
|
+
errorProperties.push(key);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (errorProperties.length > 0 && !options.strip) {
|
|
68
|
+
throw Error(
|
|
69
|
+
`The following properties are not valid: ${errorProperties.join(
|
|
70
|
+
", "
|
|
71
|
+
)}. Only strings, numbers, booleans, and null are allowed.`
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
return props;
|
|
75
|
+
}
|
|
45
76
|
function computeRoute(pathname, pathParams) {
|
|
46
77
|
if (!pathname || !pathParams) {
|
|
47
78
|
return pathname;
|
|
@@ -129,6 +160,36 @@ function inject(props = {
|
|
|
129
160
|
}
|
|
130
161
|
document.head.appendChild(script);
|
|
131
162
|
}
|
|
163
|
+
function track(name2, properties, options) {
|
|
164
|
+
var _a, _b;
|
|
165
|
+
if (!isBrowser()) {
|
|
166
|
+
const msg = "[Vercel Web Analytics] Please import `track` from `@vercel/analytics/server` when using this function in a server environment";
|
|
167
|
+
if (isProduction()) {
|
|
168
|
+
console.warn(msg);
|
|
169
|
+
} else {
|
|
170
|
+
throw new Error(msg);
|
|
171
|
+
}
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (!properties) {
|
|
175
|
+
(_a = window.va) == null ? void 0 : _a.call(window, "event", { name: name2, options });
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
try {
|
|
179
|
+
const props = parseProperties(properties, {
|
|
180
|
+
strip: isProduction()
|
|
181
|
+
});
|
|
182
|
+
(_b = window.va) == null ? void 0 : _b.call(window, "event", {
|
|
183
|
+
name: name2,
|
|
184
|
+
data: props,
|
|
185
|
+
options
|
|
186
|
+
});
|
|
187
|
+
} catch (err) {
|
|
188
|
+
if (err instanceof Error && isDevelopment()) {
|
|
189
|
+
console.error(err);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
132
193
|
function pageview({
|
|
133
194
|
route,
|
|
134
195
|
path
|
|
@@ -176,9 +237,43 @@ function createComponent(framework = "vue") {
|
|
|
176
237
|
});
|
|
177
238
|
}
|
|
178
239
|
|
|
240
|
+
// src/nuxt/utils.ts
|
|
241
|
+
function getBasePath2() {
|
|
242
|
+
try {
|
|
243
|
+
return import.meta.env.VITE_VERCEL_OBSERVABILITY_BASEPATH;
|
|
244
|
+
} catch {
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
179
248
|
// src/nuxt/index.ts
|
|
180
249
|
var Analytics = createComponent("nuxt");
|
|
250
|
+
function injectAnalytics(props = {}) {
|
|
251
|
+
if (isBrowser()) {
|
|
252
|
+
const router = useRouter();
|
|
253
|
+
onNuxtReady(() => {
|
|
254
|
+
inject({
|
|
255
|
+
...props,
|
|
256
|
+
framework: "nuxt",
|
|
257
|
+
disableAutoTrack: true,
|
|
258
|
+
basePath: getBasePath2()
|
|
259
|
+
});
|
|
260
|
+
const route = useRoute2();
|
|
261
|
+
pageview({
|
|
262
|
+
route: computeRoute(route.path, route.params),
|
|
263
|
+
path: route.path
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
router.afterEach((to) => {
|
|
267
|
+
pageview({
|
|
268
|
+
route: computeRoute(to.path, to.params),
|
|
269
|
+
path: to.path
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
}
|
|
181
274
|
export {
|
|
182
|
-
Analytics
|
|
275
|
+
Analytics,
|
|
276
|
+
injectAnalytics,
|
|
277
|
+
track
|
|
183
278
|
};
|
|
184
279
|
//# sourceMappingURL=index.mjs.map
|
package/dist/nuxt/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/vue/create-component.ts","../../package.json","../../src/queue.ts","../../src/utils.ts","../../src/generic.ts","../../src/vue/utils.ts","../../src/nuxt/index.ts"],"sourcesContent":["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 { inject, pageview, type AnalyticsProps } from '../generic';\nimport { computeRoute } from '../utils';\nimport { getBasePath } 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 // eslint-disable-next-line react-hooks/rules-of-hooks -- this is not a React component.\n const route = useRoute();\n inject({\n ...props,\n basePath: getBasePath(),\n // keep auto-tracking unless we have route support (Nuxt or vue-router).\n disableAutoTrack: Boolean(route),\n framework,\n });\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- route is undefined for barebone vue project.\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","{\n \"name\": \"@vercel/analytics\",\n \"version\": \"1.5.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\": \"MPL-2.0\",\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 \"browser\": \"./dist/nuxt/index.mjs\",\n \"import\": \"./dist/nuxt/index.mjs\",\n \"require\": \"./dist/nuxt/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 \"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 \"lint\": \"eslint .\",\n \"lint-fix\": \"eslint . --fix\",\n \"test\": \"vitest\",\n \"type-check\": \"tsc --noEmit\"\n },\n \"eslintConfig\": {\n \"extends\": [\n \"@vercel/eslint-config\"\n ],\n \"rules\": {\n \"tsdoc/syntax\": \"off\"\n },\n \"ignorePatterns\": [\n \"jest.setup.ts\"\n ]\n },\n \"devDependencies\": {\n \"@swc/core\": \"^1.9.2\",\n \"@testing-library/jest-dom\": \"^6.6.3\",\n \"@testing-library/react\": \"^16.0.1\",\n \"@types/node\": \"^22.9.0\",\n \"@types/react\": \"^18.3.12\",\n \"@vercel/eslint-config\": \"workspace:0.0.0\",\n \"server-only\": \"^0.0.1\",\n \"svelte\": \"^5.1.10\",\n \"tsup\": \"8.3.5\",\n \"vitest\": \"^2.1.5\",\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 \"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","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, AnalyticsProps, 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 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 (e) {\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\nexport function getScriptSrc(\n props: AnalyticsProps & { basePath?: string }\n): string {\n if (props.scriptSrc) {\n return props.scriptSrc;\n }\n if (isDevelopment()) {\n return 'https://va.vercel-scripts.com/v1/script.debug.js';\n }\n if (props.basePath) {\n return `${props.basePath}/insights/script.js`;\n }\n return '/_vercel/insights/script.js';\n}\n","import { name as packageName, version } from '../package.json';\nimport { initQueue } from './queue';\nimport type {\n AllowedPropertyValues,\n AnalyticsProps,\n FlagsDataInput,\n BeforeSend,\n BeforeSendEvent,\n} from './types';\nimport {\n isBrowser,\n parseProperties,\n setMode,\n isDevelopment,\n isProduction,\n computeRoute,\n getScriptSrc,\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 */\nfunction inject(\n props: AnalyticsProps & {\n framework?: string;\n disableAutoTrack?: boolean;\n basePath?: string;\n } = {\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 = getScriptSrc(props);\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.dataset.sdkn =\n packageName + (props.framework ? `/${props.framework}` : '');\n script.dataset.sdkv = version;\n\n if (props.disableAutoTrack) {\n script.dataset.disableAutoTrack = '1';\n }\n if (props.endpoint) {\n script.dataset.endpoint = props.endpoint;\n } else if (props.basePath) {\n script.dataset.endpoint = `${props.basePath}/insights`;\n }\n if (props.dsn) {\n script.dataset.dsn = props.dsn;\n }\n\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 // eslint-disable-next-line no-console -- Logging to console is intentional\n console.log(\n `[Vercel Web Analytics] Failed to load script from ${src}. ${errorMessage}`\n );\n };\n\n if (isDevelopment() && props.debug === false) {\n script.dataset.debug = 'false';\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 // eslint-disable-next-line no-console -- Show warning in production\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 // eslint-disable-next-line no-console -- Logging to console is intentional\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\n// eslint-disable-next-line import/no-default-export -- Default export is intentional\nexport default {\n inject,\n track,\n computeRoute,\n};\n","export function getBasePath(): string | undefined {\n // !! important !!\n // do not access env variables using import.meta.env[varname]\n // some bundles won't replace the value at build time.\n try {\n return import.meta.env.VITE_VERCEL_OBSERVABILITY_BASEPATH as\n | string\n | undefined;\n } catch {\n // do nothing\n }\n}\n","import type { AnalyticsProps, BeforeSend, BeforeSendEvent } from '../types';\nimport { createComponent } from '../vue/create-component';\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- vue's defineComponent return type is any\nexport const Analytics = createComponent('nuxt');\nexport type { AnalyticsProps, BeforeSend, BeforeSendEvent };\n"],"mappings":";AAAA,SAAS,iBAAiB,aAAa;AAEvC,SAAS,gBAAgB;;;ACDvB,WAAQ;AACR,cAAW;;;ACFN,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO,GAAI;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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;AAClC;AAoDA,SAAS,SAAS;AAAA,EAChB;AAAA,EACA;AACF,GAGS;AAnJT;AAoJE,eAAO,OAAP,gCAAY,YAAY,EAAE,OAAO,KAAK;AACxC;;;ACrJO,SAAS,cAAkC;AAIhD,MAAI;AACF,WAAO,YAAY,IAAI;AAAA,EAGzB,QAAQ;AAAA,EAER;AACF;;;ALJO,SAAS,gBACd,YAAY,OACwB;AACpC,SAAO,gBAAgB;AAAA,IACrB,OAAO,CAAC,OAAO,cAAc,SAAS,aAAa,YAAY,MAAM;AAAA,IACrE,MAAM,OAA0C;AAE9C,YAAM,QAAQ,SAAS;AACvB,aAAO;AAAA,QACL,GAAG;AAAA,QACH,UAAU,YAAY;AAAA;AAAA,QAEtB,kBAAkB,QAAQ,KAAK;AAAA,QAC/B;AAAA,MACF,CAAC;AAED,UAAI,SAAS,OAAO,WAAW,aAAa;AAC1C,cAAM,cAAc,MAAY;AAC9B,mBAAS;AAAA,YACP,OAAO,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;;;AMnCO,IAAM,YAAY,gBAAgB,MAAM;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/nuxt/index.ts","../../src/vue/create-component.ts","../../package.json","../../src/queue.ts","../../src/utils.ts","../../src/generic.ts","../../src/vue/utils.ts","../../src/nuxt/utils.ts"],"sourcesContent":["import { onNuxtReady, useRouter, useRoute } from 'nuxt/app';\nimport type { AnalyticsProps, BeforeSend, BeforeSendEvent } from '../types';\nimport { createComponent } from '../vue/create-component';\nimport { inject, pageview, track } from '../generic';\nimport { isBrowser, computeRoute } from '../utils';\nimport { getBasePath } from './utils';\n\n// Export the Analytics component\n// Not recommended as must be used in both app.vue and error.vue\n// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- vue's defineComponent return type is any\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 // eslint-disable-next-line react-hooks/rules-of-hooks -- we are not using a React here\n const router = useRouter();\n\n onNuxtReady(() => {\n inject({\n ...props,\n framework: 'nuxt',\n disableAutoTrack: true,\n basePath: getBasePath(),\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","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 { inject, pageview, type AnalyticsProps } from '../generic';\nimport { computeRoute } from '../utils';\nimport { getBasePath } 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 // eslint-disable-next-line react-hooks/rules-of-hooks -- this is not a React component.\n const route = useRoute();\n inject({\n ...props,\n basePath: getBasePath(),\n // keep auto-tracking unless we have route support (Nuxt or vue-router).\n disableAutoTrack: Boolean(route),\n framework,\n });\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- route is undefined for barebone vue project.\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","{\n \"name\": \"@vercel/analytics\",\n \"version\": \"1.6.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\": \"MPL-2.0\",\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 \"browser\": \"./dist/nuxt/index.mjs\",\n \"import\": \"./dist/nuxt/index.mjs\",\n \"require\": \"./dist/nuxt/index.js\"\n },\n \"./nuxt/module\": {\n \"browser\": \"./dist/nuxt/module.mjs\",\n \"import\": \"./dist/nuxt/module.mjs\",\n \"require\": \"./dist/nuxt/module.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 \"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 \"lint\": \"eslint .\",\n \"lint-fix\": \"eslint . --fix\",\n \"test\": \"vitest\",\n \"type-check\": \"tsc --noEmit\"\n },\n \"eslintConfig\": {\n \"extends\": [\n \"@vercel/eslint-config\"\n ],\n \"rules\": {\n \"tsdoc/syntax\": \"off\"\n },\n \"ignorePatterns\": [\n \"jest.setup.ts\"\n ]\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.6.3\",\n \"@testing-library/react\": \"^16.0.1\",\n \"@types/node\": \"^22.9.0\",\n \"@types/react\": \"^18.3.12\",\n \"@vercel/eslint-config\": \"workspace:0.0.0\",\n \"server-only\": \"^0.0.1\",\n \"svelte\": \"^5.1.10\",\n \"tsup\": \"8.3.5\",\n \"vitest\": \"^2.1.5\",\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","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, AnalyticsProps, 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 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 (e) {\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\nexport function getScriptSrc(\n props: AnalyticsProps & { basePath?: string }\n): string {\n if (props.scriptSrc) {\n return props.scriptSrc;\n }\n if (isDevelopment()) {\n return 'https://va.vercel-scripts.com/v1/script.debug.js';\n }\n if (props.basePath) {\n return `${props.basePath}/insights/script.js`;\n }\n return '/_vercel/insights/script.js';\n}\n","import { name as packageName, version } from '../package.json';\nimport { initQueue } from './queue';\nimport type {\n AllowedPropertyValues,\n AnalyticsProps,\n FlagsDataInput,\n BeforeSend,\n BeforeSendEvent,\n} from './types';\nimport {\n isBrowser,\n parseProperties,\n setMode,\n isDevelopment,\n isProduction,\n computeRoute,\n getScriptSrc,\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 */\nfunction inject(\n props: AnalyticsProps & {\n framework?: string;\n disableAutoTrack?: boolean;\n basePath?: string;\n } = {\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 = getScriptSrc(props);\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.dataset.sdkn =\n packageName + (props.framework ? `/${props.framework}` : '');\n script.dataset.sdkv = version;\n\n if (props.disableAutoTrack) {\n script.dataset.disableAutoTrack = '1';\n }\n if (props.endpoint) {\n script.dataset.endpoint = props.endpoint;\n } else if (props.basePath) {\n script.dataset.endpoint = `${props.basePath}/insights`;\n }\n if (props.dsn) {\n script.dataset.dsn = props.dsn;\n }\n\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 // eslint-disable-next-line no-console -- Logging to console is intentional\n console.log(\n `[Vercel Web Analytics] Failed to load script from ${src}. ${errorMessage}`\n );\n };\n\n if (isDevelopment() && props.debug === false) {\n script.dataset.debug = 'false';\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 // eslint-disable-next-line no-console -- Show warning in production\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 // eslint-disable-next-line no-console -- Logging to console is intentional\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\n// eslint-disable-next-line import/no-default-export -- Default export is intentional\nexport default {\n inject,\n track,\n computeRoute,\n};\n","export function getBasePath(): string | undefined {\n // !! important !!\n // do not access env variables using import.meta.env[varname]\n // some bundles won't replace the value at build time.\n try {\n return import.meta.env.VITE_VERCEL_OBSERVABILITY_BASEPATH as\n | string\n | undefined;\n } catch {\n // do nothing\n }\n}\n","export function getBasePath(): string | undefined {\n // !! important !!\n // do not access env variables using import.meta.env[varname]\n // some bundles won't replace the value at build time.\n try {\n return import.meta.env.VITE_VERCEL_OBSERVABILITY_BASEPATH as\n | string\n | undefined;\n } catch {\n // do nothing\n }\n}\n"],"mappings":";AAAA,SAAS,aAAa,WAAW,YAAAA,iBAAgB;;;ACAjD,SAAS,iBAAiB,aAAa;AAEvC,SAAS,gBAAgB;;;ACDvB,WAAQ;AACR,cAAW;;;ACFN,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO,GAAI;AAEf,SAAO,KAAK,SAAS,KAAK,QAAc;AACtC,KAAC,OAAO,MAAM,OAAO,OAAO,CAAC,GAAG,KAAK,MAAM;AAAA,EAC7C;AACF;;;ACLO,SAAS,Y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AA,MACxB,CAAC;AACD,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","getBasePath","useRoute"]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/nuxt/module.ts
|
|
21
|
+
var module_exports = {};
|
|
22
|
+
__export(module_exports, {
|
|
23
|
+
default: () => module_default
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(module_exports);
|
|
26
|
+
var import_kit = require("@nuxt/kit");
|
|
27
|
+
var module_default = (0, import_kit.defineNuxtModule)({
|
|
28
|
+
meta: {
|
|
29
|
+
name: "@vercel/analytics",
|
|
30
|
+
configKey: "analytics",
|
|
31
|
+
docs: "https://vercel.com/docs/analytics/quickstart"
|
|
32
|
+
},
|
|
33
|
+
setup() {
|
|
34
|
+
const template = (0, import_kit.addTemplate)({
|
|
35
|
+
filename: "vercel-analytics.client.ts",
|
|
36
|
+
getContents: () => `
|
|
37
|
+
import { injectAnalytics } from '@vercel/analytics/nuxt'
|
|
38
|
+
import { defineNuxtPlugin } from '#imports'
|
|
39
|
+
|
|
40
|
+
export default defineNuxtPlugin(() => {
|
|
41
|
+
injectAnalytics()
|
|
42
|
+
})
|
|
43
|
+
`
|
|
44
|
+
});
|
|
45
|
+
(0, import_kit.addPlugin)({
|
|
46
|
+
src: template.dst,
|
|
47
|
+
mode: "client"
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
//# sourceMappingURL=module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/nuxt/module.ts"],"sourcesContent":["import { defineNuxtModule, addPlugin, addTemplate } from '@nuxt/kit';\nimport type { NuxtModule } from '@nuxt/schema';\n\n// eslint-disable-next-line import/no-default-export -- default export is required for nuxt module\nexport default defineNuxtModule({\n meta: {\n name: '@vercel/analytics',\n configKey: 'analytics',\n docs: 'https://vercel.com/docs/analytics/quickstart',\n },\n setup() {\n const template = addTemplate({\n filename: 'vercel-analytics.client.ts',\n getContents: () => `\nimport { injectAnalytics } from '@vercel/analytics/nuxt'\nimport { defineNuxtPlugin } from '#imports'\n\nexport default defineNuxtPlugin(() => {\n injectAnalytics()\n})\n`,\n });\n\n addPlugin({\n src: template.dst,\n mode: 'client',\n });\n },\n}) as NuxtModule;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAyD;AAIzD,IAAO,qBAAQ,6BAAiB;AAAA,EAC9B,MAAM;AAAA,IACJ,MAAM;AAAA,IACN,WAAW;AAAA,IACX,MAAM;AAAA,EACR;AAAA,EACA,QAAQ;AACN,UAAM,eAAW,wBAAY;AAAA,MAC3B,UAAU;AAAA,MACV,aAAa,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQrB,CAAC;AAED,8BAAU;AAAA,MACR,KAAK,SAAS;AAAA,MACd,MAAM;AAAA,IACR,CAAC;AAAA,EACH;AACF,CAAC;","names":[]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// src/nuxt/module.ts
|
|
2
|
+
import { defineNuxtModule, addPlugin, addTemplate } from "@nuxt/kit";
|
|
3
|
+
var module_default = defineNuxtModule({
|
|
4
|
+
meta: {
|
|
5
|
+
name: "@vercel/analytics",
|
|
6
|
+
configKey: "analytics",
|
|
7
|
+
docs: "https://vercel.com/docs/analytics/quickstart"
|
|
8
|
+
},
|
|
9
|
+
setup() {
|
|
10
|
+
const template = addTemplate({
|
|
11
|
+
filename: "vercel-analytics.client.ts",
|
|
12
|
+
getContents: () => `
|
|
13
|
+
import { injectAnalytics } from '@vercel/analytics/nuxt'
|
|
14
|
+
import { defineNuxtPlugin } from '#imports'
|
|
15
|
+
|
|
16
|
+
export default defineNuxtPlugin(() => {
|
|
17
|
+
injectAnalytics()
|
|
18
|
+
})
|
|
19
|
+
`
|
|
20
|
+
});
|
|
21
|
+
addPlugin({
|
|
22
|
+
src: template.dst,
|
|
23
|
+
mode: "client"
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
export {
|
|
28
|
+
module_default as default
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=module.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/nuxt/module.ts"],"sourcesContent":["import { defineNuxtModule, addPlugin, addTemplate } from '@nuxt/kit';\nimport type { NuxtModule } from '@nuxt/schema';\n\n// eslint-disable-next-line import/no-default-export -- default export is required for nuxt module\nexport default defineNuxtModule({\n meta: {\n name: '@vercel/analytics',\n configKey: 'analytics',\n docs: 'https://vercel.com/docs/analytics/quickstart',\n },\n setup() {\n const template = addTemplate({\n filename: 'vercel-analytics.client.ts',\n getContents: () => `\nimport { injectAnalytics } from '@vercel/analytics/nuxt'\nimport { defineNuxtPlugin } from '#imports'\n\nexport default defineNuxtPlugin(() => {\n injectAnalytics()\n})\n`,\n });\n\n addPlugin({\n src: template.dst,\n mode: 'client',\n });\n },\n}) as NuxtModule;\n"],"mappings":";AAAA,SAAS,kBAAkB,WAAW,mBAAmB;AAIzD,IAAO,iBAAQ,iBAAiB;AAAA,EAC9B,MAAM;AAAA,IACJ,MAAM;AAAA,IACN,WAAW;AAAA,IACX,MAAM;AAAA,EACR;AAAA,EACA,QAAQ;AACN,UAAM,WAAW,YAAY;AAAA,MAC3B,UAAU;AAAA,MACV,aAAa,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQrB,CAAC;AAED,cAAU;AAAA,MACR,KAAK,SAAS;AAAA,MACd,MAAM;AAAA,IACR,CAAC;AAAA,EACH;AACF,CAAC;","names":[]}
|
package/dist/react/index.d.mts
CHANGED
|
@@ -8,7 +8,7 @@ interface CustomEvent {
|
|
|
8
8
|
}
|
|
9
9
|
type BeforeSendEvent = PageViewEvent | CustomEvent;
|
|
10
10
|
type Mode = 'auto' | 'development' | 'production';
|
|
11
|
-
type AllowedPropertyValues = string | number | boolean | null;
|
|
11
|
+
type AllowedPropertyValues = string | number | boolean | null | undefined;
|
|
12
12
|
type BeforeSend = (event: BeforeSendEvent) => BeforeSendEvent | null;
|
|
13
13
|
interface AnalyticsProps {
|
|
14
14
|
beforeSend?: BeforeSend;
|
package/dist/react/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ interface CustomEvent {
|
|
|
8
8
|
}
|
|
9
9
|
type BeforeSendEvent = PageViewEvent | CustomEvent;
|
|
10
10
|
type Mode = 'auto' | 'development' | 'production';
|
|
11
|
-
type AllowedPropertyValues = string | number | boolean | null;
|
|
11
|
+
type AllowedPropertyValues = string | number | boolean | null | undefined;
|
|
12
12
|
type BeforeSend = (event: BeforeSendEvent) => BeforeSendEvent | null;
|
|
13
13
|
interface AnalyticsProps {
|
|
14
14
|
beforeSend?: BeforeSend;
|