@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
package/dist/next/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/nextjs/index.tsx","../../src/react/index.tsx","../../package.json","../../src/queue.ts","../../src/utils.ts","../../src/generic.ts","../../src/react/utils.ts","../../src/nextjs/utils.ts"],"sourcesContent":["'use client';\nimport React, { Suspense, type ReactNode } from 'react';\nimport { Analytics as AnalyticsScript } from '../react';\nimport type { AnalyticsProps, BeforeSend, BeforeSendEvent } from '../types';\nimport { getBasePath, useRoute } from './utils';\n\ntype Props = Omit<AnalyticsProps, 'route' | 'disableAutoTrack'>;\n\nfunction AnalyticsComponent(props: Props): ReactNode {\n const { route, path } = useRoute();\n return (\n <AnalyticsScript\n path={path}\n route={route}\n {...props}\n basePath={getBasePath()}\n framework=\"next\"\n />\n );\n}\n\nexport function Analytics(props: Props): null {\n // Because of incompatible types between ReactNode in React 19 and React 18 we return null (which is also what we render)\n return (\n <Suspense fallback={null}>\n <AnalyticsComponent {...props} />\n </Suspense>\n ) as never;\n}\n\nexport type { AnalyticsProps, BeforeSend, BeforeSendEvent };\n","'use client';\nimport { useEffect } from 'react';\nimport { inject, track, pageview } from '../generic';\nimport type { AnalyticsProps, BeforeSend, BeforeSendEvent } from '../types';\nimport { getBasePath } 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 * @example\n * ```js\n * import { Analytics } from '@vercel/analytics/react';\n *\n * export default function App() {\n * return (\n * <div>\n * <Analytics />\n * <h1>My App</h1>\n * </div>\n * );\n * }\n * ```\n */\nfunction Analytics(\n props: AnalyticsProps & {\n framework?: string;\n route?: string | null;\n path?: string | null;\n basePath?: string;\n }\n): null {\n useEffect(() => {\n if (props.beforeSend) {\n window.va?.('beforeSend', props.beforeSend);\n }\n }, [props.beforeSend]);\n\n // biome-ignore lint/correctness/useExhaustiveDependencies: only run once\n useEffect(() => {\n inject({\n framework: props.framework || 'react',\n basePath: props.basePath ?? getBasePath(),\n ...(props.route !== undefined && { disableAutoTrack: true }),\n ...props,\n });\n // eslint-disable-next-line react-hooks/exhaustive-deps -- only run once\n }, []);\n\n useEffect(() => {\n // explicitely track page view, since we disabled auto tracking\n if (props.route && props.path) {\n pageview({ route: props.route, path: props.path });\n }\n }, [props.route, props.path]);\n\n return null;\n}\n\nexport { track, Analytics };\nexport type { AnalyticsProps, BeforeSend, BeforeSendEvent };\n","{\n \"name\": \"@vercel/analytics\",\n \"version\": \"1.6.1\",\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 process.env[varname]\n // some bundles won't replace the value at build time.\n // eslint-disable-next-line @typescript-eslint/prefer-optional-chain -- we can't use optionnal here, it'll break if process does not exist.\n if (typeof process === 'undefined' || typeof process.env === 'undefined') {\n return undefined;\n }\n return process.env.REACT_APP_VERCEL_OBSERVABILITY_BASEPATH;\n}\n","'use client';\n/* eslint-disable @typescript-eslint/no-unnecessary-condition -- can be empty in pages router */\nimport { useParams, usePathname, useSearchParams } from 'next/navigation.js';\nimport { computeRoute } from '../utils';\n\nexport const useRoute = (): {\n route: string | null;\n path: string;\n} => {\n const params = useParams();\n const searchParams = useSearchParams();\n const path = usePathname();\n\n // Until we have route parameters, we don't compute the route\n if (!params) {\n return { route: null, path };\n }\n // in Next.js@13, useParams() could return an empty object for pages router, and we default to searchParams.\n const finalParams = Object.keys(params).length\n ? params\n : Object.fromEntries(searchParams.entries());\n return { route: computeRoute(path, finalParams), path };\n};\n\nexport function getBasePath(): string | undefined {\n // !! important !!\n // do not access env variables using process.env[varname]\n // some bundles won't replace the value at build time.\n // eslint-disable-next-line @typescript-eslint/prefer-optional-chain -- we can't use optionnal here, it'll break if process does not exist.\n if (typeof process === 'undefined' || typeof process.env === 'undefined') {\n return undefined;\n }\n return process.env.NEXT_PUBLIC_VERCEL_OBSERVABILITY_BASEPATH;\n}\n"],"mappings":";;;AACA,OAAO,SAAS,gBAAgC;;;ACAhD,SAAS,iBAAiB;;;ACAxB,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,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a,MAAM,WAAW,GAAG,KAAK;AACxD;AAEO,SAASA,eAAkC;AAKhD,MAAI,OAAO,YAAY,eAAe,OAAO,QAAQ,QAAQ,aAAa;AACxE,WAAO;AAAA,EACT;AACA,SAAO,QAAQ,IAAI;AACrB;;;APzBA,SAAS,mBAAmB,OAAyB;AACnD,QAAM,EAAE,OAAO,KAAK,IAAI,SAAS;AACjC,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACC,GAAG;AAAA,MACJ,UAAUC,aAAY;AAAA,MACtB,WAAU;AAAA;AAAA,EACZ;AAEJ;AAEO,SAASC,WAAU,OAAoB;AAE5C,SACE,oCAAC,YAAS,UAAU,QAClB,oCAAC,sBAAoB,GAAG,OAAO,CACjC;AAEJ;","names":["getBasePath","getBasePath","Analytics"]}
|
|
1
|
+
{"version":3,"sources":["../../src/nextjs/index.tsx","../../src/react/index.tsx","../../src/queue.ts","../../package.json","../../src/utils.ts","../../src/generic.ts","../../src/react/utils.ts","../../src/nextjs/utils.ts"],"sourcesContent":["'use client';\nimport React, { type ReactNode, Suspense } from 'react';\nimport { Analytics as AnalyticsScript } from '../react';\nimport type { AnalyticsProps, BeforeSend, BeforeSendEvent } from '../types';\nimport { getBasePath, getConfigString, useRoute } from './utils';\n\ntype Props = Omit<AnalyticsProps, 'route' | 'disableAutoTrack'>;\n\nfunction AnalyticsComponent(props: Props): ReactNode {\n const { route, path } = useRoute();\n return (\n <AnalyticsScript\n path={path}\n route={route}\n {...props}\n basePath={getBasePath()}\n configString={getConfigString()}\n framework=\"next\"\n />\n );\n}\n\nexport function Analytics(props: Props): null {\n // Because of incompatible types between ReactNode in React 19 and React 18 we return null (which is also what we render)\n return (\n <Suspense fallback={null}>\n <AnalyticsComponent {...props} />\n </Suspense>\n ) as never;\n}\n\nexport type { AnalyticsProps, BeforeSend, BeforeSendEvent };\n","'use client';\nimport { useEffect } from 'react';\nimport { inject, pageview, track } from '../generic';\nimport type { AnalyticsProps, BeforeSend, BeforeSendEvent } from '../types';\nimport { getBasePath, getConfigString } 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 * @example\n * ```js\n * import { Analytics } from '@vercel/analytics/react';\n *\n * export default function App() {\n * return (\n * <div>\n * <Analytics />\n * <h1>My App</h1>\n * </div>\n * );\n * }\n * ```\n */\nfunction Analytics(\n props: AnalyticsProps & {\n framework?: string;\n route?: string | null;\n path?: string | null;\n basePath?: string;\n configString?: string;\n },\n): null {\n useEffect(() => {\n if (props.beforeSend) {\n window.va?.('beforeSend', props.beforeSend);\n }\n }, [props.beforeSend]);\n\n // biome-ignore lint/correctness/useExhaustiveDependencies: only run once\n useEffect(() => {\n inject(\n {\n framework: props.framework || 'react',\n basePath: props.basePath ?? getBasePath(),\n ...(props.route !== undefined && { disableAutoTrack: true }),\n ...props,\n },\n props.configString ?? getConfigString(),\n );\n }, []);\n\n useEffect(() => {\n // explicitely track page view, since we disabled auto tracking\n if (props.route && props.path) {\n pageview({ route: props.route, path: props.path });\n }\n }, [props.route, props.path]);\n\n return null;\n}\n\nexport { track, Analytics };\nexport type { AnalyticsProps, BeforeSend, BeforeSendEvent };\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","// !! important !!\n// do not access env variables using process.env[varname]\n// some bundlers won't replace the value at build time.\n\nexport function getBasePath(): string | undefined {\n if (typeof process === 'undefined' || typeof process.env === 'undefined') {\n return undefined;\n }\n return process.env.REACT_APP_VERCEL_OBSERVABILITY_BASEPATH;\n}\n\nexport function getConfigString(): string | undefined {\n if (typeof process === 'undefined' || typeof process.env === 'undefined') {\n return undefined;\n }\n return process.env.REACT_APP_VERCEL_OBSERVABILITY_CLIENT_CONFIG;\n}\n","'use client';\nimport { useParams, usePathname, useSearchParams } from 'next/navigation.js';\nimport { computeRoute } from '../utils';\n\nexport const useRoute = (): {\n route: string | null;\n path: string;\n} => {\n const params = useParams();\n const searchParams = useSearchParams();\n const path = usePathname();\n\n // Until we have route parameters, we don't compute the route\n if (!params) {\n return { route: null, path };\n }\n // in Next.js@13, useParams() could return an empty object for pages router, and we default to searchParams.\n const finalParams = Object.keys(params).length\n ? params\n : Object.fromEntries(searchParams.entries());\n return { route: computeRoute(path, finalParams), path };\n};\n\n// !! important !!\n// do not access env variables using process.env[varname]\n// some bundlers won't replace the value at build time.\n\nexport function getBasePath(): string | undefined {\n if (typeof process === 'undefined' || typeof process.env === 'undefined') {\n return undefined;\n }\n return process.env.NEXT_PUBLIC_VERCEL_OBSERVABILITY_BASEPATH;\n}\n\nexport function getConfigString(): string | undefined {\n if (typeof process === 'undefined' || typeof process.env === 'undefined') {\n return undefined;\n }\n return process.env.NEXT_PUBLIC_VERCEL_OBSERVABILITY_CLIENT_CONFIG;\n}\n"],"mappings":";;;AACA,OAAO,SAAyB,gBAAgB;;;ACAhD,SAAS,iBAAiB;;;ACDnB,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;AAMO,SAAS,gBAAyB;AACvC,SAAO,QAAQ,MAAM;AAC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 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
type: 'pageview';
|
|
3
|
-
url: string;
|
|
4
|
-
}
|
|
5
|
-
interface CustomEvent {
|
|
6
|
-
type: 'event';
|
|
7
|
-
url: string;
|
|
8
|
-
}
|
|
9
|
-
type BeforeSendEvent = PageViewEvent | CustomEvent;
|
|
10
|
-
type Mode = 'auto' | 'development' | 'production';
|
|
11
|
-
type BeforeSend = (event: BeforeSendEvent) => BeforeSendEvent | null;
|
|
12
|
-
interface AnalyticsProps {
|
|
13
|
-
beforeSend?: BeforeSend;
|
|
14
|
-
debug?: boolean;
|
|
15
|
-
mode?: Mode;
|
|
16
|
-
scriptSrc?: string;
|
|
17
|
-
endpoint?: string;
|
|
18
|
-
dsn?: string;
|
|
19
|
-
}
|
|
20
|
-
declare global {
|
|
21
|
-
interface Window {
|
|
22
|
-
va?: (event: 'beforeSend' | 'event' | 'pageview', properties?: unknown) => void;
|
|
23
|
-
vaq?: [string, unknown?][];
|
|
24
|
-
vai?: boolean;
|
|
25
|
-
vam?: Mode;
|
|
26
|
-
/** used by Astro component only */
|
|
27
|
-
webAnalyticsBeforeSend?: BeforeSend;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
1
|
+
import { NuxtModule } from '@nuxt/schema';
|
|
30
2
|
|
|
31
|
-
declare const
|
|
3
|
+
declare const _default: NuxtModule;
|
|
32
4
|
|
|
33
|
-
export {
|
|
5
|
+
export { _default as default };
|
package/dist/nuxt/index.d.ts
CHANGED
|
@@ -1,33 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
type: 'pageview';
|
|
3
|
-
url: string;
|
|
4
|
-
}
|
|
5
|
-
interface CustomEvent {
|
|
6
|
-
type: 'event';
|
|
7
|
-
url: string;
|
|
8
|
-
}
|
|
9
|
-
type BeforeSendEvent = PageViewEvent | CustomEvent;
|
|
10
|
-
type Mode = 'auto' | 'development' | 'production';
|
|
11
|
-
type BeforeSend = (event: BeforeSendEvent) => BeforeSendEvent | null;
|
|
12
|
-
interface AnalyticsProps {
|
|
13
|
-
beforeSend?: BeforeSend;
|
|
14
|
-
debug?: boolean;
|
|
15
|
-
mode?: Mode;
|
|
16
|
-
scriptSrc?: string;
|
|
17
|
-
endpoint?: string;
|
|
18
|
-
dsn?: string;
|
|
19
|
-
}
|
|
20
|
-
declare global {
|
|
21
|
-
interface Window {
|
|
22
|
-
va?: (event: 'beforeSend' | 'event' | 'pageview', properties?: unknown) => void;
|
|
23
|
-
vaq?: [string, unknown?][];
|
|
24
|
-
vai?: boolean;
|
|
25
|
-
vam?: Mode;
|
|
26
|
-
/** used by Astro component only */
|
|
27
|
-
webAnalyticsBeforeSend?: BeforeSend;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
1
|
+
import { NuxtModule } from '@nuxt/schema';
|
|
30
2
|
|
|
31
|
-
declare const
|
|
3
|
+
declare const _default: NuxtModule;
|
|
32
4
|
|
|
33
|
-
export {
|
|
5
|
+
export { _default as default };
|
package/dist/nuxt/index.js
CHANGED
|
@@ -4,8 +4,8 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
6
|
var __export = (target, all) => {
|
|
7
|
-
for (var
|
|
8
|
-
__defProp(target,
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
9
|
};
|
|
10
10
|
var __copyProps = (to, from, except, desc) => {
|
|
11
11
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
@@ -17,196 +17,35 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
|
-
// src/nuxt/
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
23
|
-
|
|
20
|
+
// src/nuxt/module.ts
|
|
21
|
+
var module_exports = {};
|
|
22
|
+
__export(module_exports, {
|
|
23
|
+
default: () => module_default
|
|
24
24
|
});
|
|
25
|
-
module.exports = __toCommonJS(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const env = process.env.NODE_ENV;
|
|
50
|
-
if (env === "development" || env === "test") {
|
|
51
|
-
return "development";
|
|
52
|
-
}
|
|
53
|
-
} catch (e) {
|
|
54
|
-
}
|
|
55
|
-
return "production";
|
|
56
|
-
}
|
|
57
|
-
function setMode(mode = "auto") {
|
|
58
|
-
if (mode === "auto") {
|
|
59
|
-
window.vam = detectEnvironment();
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
window.vam = mode;
|
|
63
|
-
}
|
|
64
|
-
function getMode() {
|
|
65
|
-
const mode = isBrowser() ? window.vam : detectEnvironment();
|
|
66
|
-
return mode || "production";
|
|
67
|
-
}
|
|
68
|
-
function isDevelopment() {
|
|
69
|
-
return getMode() === "development";
|
|
70
|
-
}
|
|
71
|
-
function computeRoute(pathname, pathParams) {
|
|
72
|
-
if (!pathname || !pathParams) {
|
|
73
|
-
return pathname;
|
|
74
|
-
}
|
|
75
|
-
let result = pathname;
|
|
76
|
-
try {
|
|
77
|
-
const entries = Object.entries(pathParams);
|
|
78
|
-
for (const [key, value] of entries) {
|
|
79
|
-
if (!Array.isArray(value)) {
|
|
80
|
-
const matcher = turnValueToRegExp(value);
|
|
81
|
-
if (matcher.test(result)) {
|
|
82
|
-
result = result.replace(matcher, `/[${key}]`);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
for (const [key, value] of entries) {
|
|
87
|
-
if (Array.isArray(value)) {
|
|
88
|
-
const matcher = turnValueToRegExp(value.join("/"));
|
|
89
|
-
if (matcher.test(result)) {
|
|
90
|
-
result = result.replace(matcher, `/[...${key}]`);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return result;
|
|
95
|
-
} catch (e) {
|
|
96
|
-
return pathname;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
function turnValueToRegExp(value) {
|
|
100
|
-
return new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);
|
|
101
|
-
}
|
|
102
|
-
function escapeRegExp(string) {
|
|
103
|
-
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
104
|
-
}
|
|
105
|
-
function getScriptSrc(props) {
|
|
106
|
-
if (props.scriptSrc) {
|
|
107
|
-
return props.scriptSrc;
|
|
108
|
-
}
|
|
109
|
-
if (isDevelopment()) {
|
|
110
|
-
return "https://va.vercel-scripts.com/v1/script.debug.js";
|
|
111
|
-
}
|
|
112
|
-
if (props.basePath) {
|
|
113
|
-
return `${props.basePath}/insights/script.js`;
|
|
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/runtime'
|
|
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
|
+
});
|
|
114
49
|
}
|
|
115
|
-
return "/_vercel/insights/script.js";
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// src/generic.ts
|
|
119
|
-
function inject(props = {
|
|
120
|
-
debug: true
|
|
121
|
-
}) {
|
|
122
|
-
var _a;
|
|
123
|
-
if (!isBrowser()) return;
|
|
124
|
-
setMode(props.mode);
|
|
125
|
-
initQueue();
|
|
126
|
-
if (props.beforeSend) {
|
|
127
|
-
(_a = window.va) == null ? void 0 : _a.call(window, "beforeSend", props.beforeSend);
|
|
128
|
-
}
|
|
129
|
-
const src = getScriptSrc(props);
|
|
130
|
-
if (document.head.querySelector(`script[src*="${src}"]`)) return;
|
|
131
|
-
const script = document.createElement("script");
|
|
132
|
-
script.src = src;
|
|
133
|
-
script.defer = true;
|
|
134
|
-
script.dataset.sdkn = name + (props.framework ? `/${props.framework}` : "");
|
|
135
|
-
script.dataset.sdkv = version;
|
|
136
|
-
if (props.disableAutoTrack) {
|
|
137
|
-
script.dataset.disableAutoTrack = "1";
|
|
138
|
-
}
|
|
139
|
-
if (props.endpoint) {
|
|
140
|
-
script.dataset.endpoint = props.endpoint;
|
|
141
|
-
} else if (props.basePath) {
|
|
142
|
-
script.dataset.endpoint = `${props.basePath}/insights`;
|
|
143
|
-
}
|
|
144
|
-
if (props.dsn) {
|
|
145
|
-
script.dataset.dsn = props.dsn;
|
|
146
|
-
}
|
|
147
|
-
script.onerror = () => {
|
|
148
|
-
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.";
|
|
149
|
-
console.log(
|
|
150
|
-
`[Vercel Web Analytics] Failed to load script from ${src}. ${errorMessage}`
|
|
151
|
-
);
|
|
152
|
-
};
|
|
153
|
-
if (isDevelopment() && props.debug === false) {
|
|
154
|
-
script.dataset.debug = "false";
|
|
155
|
-
}
|
|
156
|
-
document.head.appendChild(script);
|
|
157
|
-
}
|
|
158
|
-
function pageview({
|
|
159
|
-
route,
|
|
160
|
-
path
|
|
161
|
-
}) {
|
|
162
|
-
var _a;
|
|
163
|
-
(_a = window.va) == null ? void 0 : _a.call(window, "pageview", { route, path });
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// src/vue/utils.ts
|
|
167
|
-
var import_meta = {};
|
|
168
|
-
function getBasePath() {
|
|
169
|
-
try {
|
|
170
|
-
return import_meta.env.VITE_VERCEL_OBSERVABILITY_BASEPATH;
|
|
171
|
-
} catch {
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// src/vue/create-component.ts
|
|
176
|
-
function createComponent(framework = "vue") {
|
|
177
|
-
return (0, import_vue.defineComponent)({
|
|
178
|
-
props: ["dsn", "beforeSend", "debug", "scriptSrc", "endpoint", "mode"],
|
|
179
|
-
setup(props) {
|
|
180
|
-
const route = (0, import_vue_router.useRoute)();
|
|
181
|
-
inject({
|
|
182
|
-
...props,
|
|
183
|
-
basePath: getBasePath(),
|
|
184
|
-
// keep auto-tracking unless we have route support (Nuxt or vue-router).
|
|
185
|
-
disableAutoTrack: Boolean(route),
|
|
186
|
-
framework
|
|
187
|
-
});
|
|
188
|
-
if (route && typeof window !== "undefined") {
|
|
189
|
-
const changeRoute = () => {
|
|
190
|
-
pageview({
|
|
191
|
-
route: computeRoute(route.path, route.params),
|
|
192
|
-
path: route.path
|
|
193
|
-
});
|
|
194
|
-
};
|
|
195
|
-
changeRoute();
|
|
196
|
-
(0, import_vue.watch)(route, changeRoute);
|
|
197
|
-
}
|
|
198
|
-
},
|
|
199
|
-
// Vue component must have a render function, or a template.
|
|
200
|
-
render() {
|
|
201
|
-
return null;
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
// src/nuxt/index.ts
|
|
207
|
-
var Analytics = createComponent("nuxt");
|
|
208
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
209
|
-
0 && (module.exports = {
|
|
210
|
-
Analytics
|
|
211
50
|
});
|
|
212
51
|
//# 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.6.1\",\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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C,aAAO,4BAAgB;AAAA,IACrB,OAAO,CAAC,OAAO,cAAc,SAAS,aAAa,YAAY,MAAM;AAAA,IACrE,MAAM,OAA0C;AAE9C,YAAM,YAAQ,4BAAS;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,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/module.ts"],"sourcesContent":["import { addPlugin, addTemplate, defineNuxtModule } from '@nuxt/kit';\nimport type { NuxtModule } from '@nuxt/schema';\n\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/runtime'\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;AAGzD,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":[]}
|