@vercel/analytics 1.2.0-beta.3 → 1.2.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 +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -3
- package/dist/index.mjs.map +1 -1
- package/dist/next/index.js +8 -6
- package/dist/next/index.js.map +1 -1
- package/dist/next/index.mjs +8 -6
- package/dist/next/index.mjs.map +1 -1
- package/dist/react/index.js +8 -6
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +8 -6
- package/dist/react/index.mjs.map +1 -1
- package/dist/server/index.js +5 -3
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +5 -3
- package/dist/server/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -52,8 +52,9 @@ declare function inject(props?: AnalyticsProps & {
|
|
|
52
52
|
* @param [properties] - Additional properties of the event. Nested objects are not supported. Allowed values are `string`, `number`, `boolean`, and `null`.
|
|
53
53
|
*/
|
|
54
54
|
declare function track(name: string, properties?: Record<string, AllowedPropertyValues>): void;
|
|
55
|
-
declare function pageview({ route }: {
|
|
55
|
+
declare function pageview({ route, path }: {
|
|
56
56
|
route?: string;
|
|
57
|
+
path?: string;
|
|
57
58
|
}): void;
|
|
58
59
|
|
|
59
60
|
declare const _default: {
|
package/dist/index.d.ts
CHANGED
|
@@ -52,8 +52,9 @@ declare function inject(props?: AnalyticsProps & {
|
|
|
52
52
|
* @param [properties] - Additional properties of the event. Nested objects are not supported. Allowed values are `string`, `number`, `boolean`, and `null`.
|
|
53
53
|
*/
|
|
54
54
|
declare function track(name: string, properties?: Record<string, AllowedPropertyValues>): void;
|
|
55
|
-
declare function pageview({ route }: {
|
|
55
|
+
declare function pageview({ route, path }: {
|
|
56
56
|
route?: string;
|
|
57
|
+
path?: string;
|
|
57
58
|
}): void;
|
|
58
59
|
|
|
59
60
|
declare const _default: {
|
package/dist/index.js
CHANGED
|
@@ -31,7 +31,7 @@ module.exports = __toCommonJS(generic_exports);
|
|
|
31
31
|
|
|
32
32
|
// package.json
|
|
33
33
|
var name = "@vercel/analytics";
|
|
34
|
-
var version = "1.2.0
|
|
34
|
+
var version = "1.2.0";
|
|
35
35
|
|
|
36
36
|
// src/queue.ts
|
|
37
37
|
var initQueue = () => {
|
|
@@ -171,10 +171,11 @@ function track(name2, properties) {
|
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
|
-
function pageview({ route }) {
|
|
174
|
+
function pageview({ route, path }) {
|
|
175
175
|
var _a;
|
|
176
176
|
(_a = window.va) == null ? void 0 : _a.call(window, "pageview", {
|
|
177
|
-
route
|
|
177
|
+
route,
|
|
178
|
+
path
|
|
178
179
|
});
|
|
179
180
|
}
|
|
180
181
|
var generic_default = {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/generic.ts","../package.json","../src/queue.ts","../src/utils.ts"],"sourcesContent":["import { name as packageName, version } from '../package.json';\nimport { initQueue } from './queue';\nimport type { AllowedPropertyValues, AnalyticsProps } from './types';\nimport {\n isBrowser,\n parseProperties,\n setMode,\n isDevelopment,\n isProduction,\n} from './utils';\n\nexport const DEV_SCRIPT_URL =\n 'https://va.vercel-scripts.com/v1/script.debug.js';\nexport const PROD_SCRIPT_URL = '/_vercel/insights/script.js';\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 */\nfunction inject(\n props: AnalyticsProps & {\n framework?: 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 =\n props.scriptSrc || (isDevelopment() ? DEV_SCRIPT_URL : PROD_SCRIPT_URL);\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 }\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): 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 });\n return;\n }\n\n try {\n const props = parseProperties(properties, {\n strip: isProduction(),\n });\n\n window.va?.('event', {\n name,\n data: props,\n });\n } catch (err) {\n if (err instanceof Error && isDevelopment()) {\n // eslint-disable-next-line no-console -- Logging to console is intentional\n console.error(err);\n }\n }\n}\n\nfunction pageview({ route }: { route?: string }): void {\n window.va?.('pageview', {\n route,\n });\n}\n\nexport { inject, track, pageview };\nexport type { AnalyticsProps };\n\n// eslint-disable-next-line import/no-default-export -- Default export is intentional\nexport default {\n inject,\n track,\n};\n","{\n \"name\": \"@vercel/analytics\",\n \"version\": \"1.2.0-beta.3\",\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.js\",\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n },\n \"./react\": {\n \"browser\": \"./dist/react/index.js\",\n \"import\": \"./dist/react/index.js\",\n \"require\": \"./dist/react/index.cjs\"\n },\n \"./next\": {\n \"browser\": \"./dist/next/index.mjs\",\n \"import\": \"./dist/next/index.mjs\",\n \"require\": \"./dist/next/index.js\"\n },\n \"./server\": {\n \"node\": \"./dist/server/index.js\",\n \"edge-light\": \"./dist/server/index.js\",\n \"import\": \"./dist/server/index.js\",\n \"require\": \"./dist/server/index.cjs\",\n \"default\": \"./dist/server/index.cjs\"\n }\n },\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"typesVersions\": {\n \"*\": {\n \"*\": [\n \"dist/index.d.ts\"\n ],\n \"react\": [\n \"dist/react/index.d.ts\"\n ],\n \"server\": [\n \"dist/server/index.d.ts\"\n ],\n \"next\": [\n \"dist/next/index.d.ts\"\n ]\n }\n },\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"lint\": \"eslint .\",\n \"lint-fix\": \"eslint . --fix\",\n \"test\": \"jest\",\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 \"dependencies\": {\n \"server-only\": \"^0.0.1\"\n },\n \"devDependencies\": {\n \"@swc/core\": \"^1.3.66\",\n \"@swc/jest\": \"^0.2.26\",\n \"@testing-library/jest-dom\": \"^5.16.5\",\n \"@testing-library/react\": \"^14.0.0\",\n \"@types/jest\": \"^29.5.2\",\n \"@types/node\": \"^20.3.1\",\n \"@types/react\": \"^18.2.14\",\n \"@types/testing-library__jest-dom\": \"^5.14.6\",\n \"@vercel/eslint-config\": \"workspace:0.0.0\",\n \"jest\": \"^29.5.0\",\n \"jest-environment-jsdom\": \"^29.5.0\",\n \"react\": \"^18.2.0\",\n \"react-dom\": \"^18.2.0\",\n \"tsup\": \"7.1.0\"\n },\n \"peerDependencies\": {\n \"next\": \">= 13\",\n \"react\": \"^18 || ^19\"\n },\n \"peerDependenciesMeta\": {\n \"next\": {\n \"optional\": true\n },\n \"react\": {\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, 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\n try {\n for (const [key, valueOrArray] of Object.entries(pathParams)) {\n const isValueArray = Array.isArray(valueOrArray);\n const value = isValueArray ? valueOrArray.join('/') : valueOrArray;\n const expr = isValueArray ? `...${key}` : key;\n\n const matcher = new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[${expr}]`);\n }\n }\n\n return result;\n } catch (e) {\n return pathname;\n }\n}\n\nfunction escapeRegExp(string: string): string {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCE,WAAQ;AACR,cAAW;;;ACFN,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO;AAAI;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,YAAY;AACf,iBAAO,OAAP,gCAAY,SAAS,EAAE,MAAAA,MAAK;AAC5B;AAAA,EACF;AAEA,MAAI;AACF,UAAM,QAAQ,gBAAgB,YAAY;AAAA,MACxC,OAAO,aAAa;AAAA,IACtB,CAAC;AAED,iBAAO,OAAP,gCAAY,SAAS;AAAA,MACnB,MAAAA;AAAA,MACA,MAAM;AAAA,IACR;AAAA,EACF,SAAS,KAAP;AACA,QAAI,eAAe,SAAS,cAAc,GAAG;AAE3C,cAAQ,MAAM,GAAG;AAAA,IACnB;AAAA,EACF;AACF;AAEA,SAAS,SAAS,EAAE,MAAM,GAA6B;AAjIvD;AAkIE,eAAO,OAAP,gCAAY,YAAY;AAAA,IACtB;AAAA,EACF;AACF;AAMA,IAAO,kBAAQ;AAAA,EACb;AAAA,EACA;AACF;","names":["name"]}
|
|
1
|
+
{"version":3,"sources":["../src/generic.ts","../package.json","../src/queue.ts","../src/utils.ts"],"sourcesContent":["import { name as packageName, version } from '../package.json';\nimport { initQueue } from './queue';\nimport type { AllowedPropertyValues, AnalyticsProps } from './types';\nimport {\n isBrowser,\n parseProperties,\n setMode,\n isDevelopment,\n isProduction,\n} from './utils';\n\nexport const DEV_SCRIPT_URL =\n 'https://va.vercel-scripts.com/v1/script.debug.js';\nexport const PROD_SCRIPT_URL = '/_vercel/insights/script.js';\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 */\nfunction inject(\n props: AnalyticsProps & {\n framework?: 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 =\n props.scriptSrc || (isDevelopment() ? DEV_SCRIPT_URL : PROD_SCRIPT_URL);\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 }\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): 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 });\n return;\n }\n\n try {\n const props = parseProperties(properties, {\n strip: isProduction(),\n });\n\n window.va?.('event', {\n name,\n data: props,\n });\n } catch (err) {\n if (err instanceof Error && isDevelopment()) {\n // eslint-disable-next-line no-console -- Logging to console is intentional\n console.error(err);\n }\n }\n}\n\nfunction pageview({ route, path }: { route?: string; path?: string }): void {\n window.va?.('pageview', {\n route,\n path,\n });\n}\n\nexport { inject, track, pageview };\nexport type { AnalyticsProps };\n\n// eslint-disable-next-line import/no-default-export -- Default export is intentional\nexport default {\n inject,\n track,\n};\n","{\n \"name\": \"@vercel/analytics\",\n \"version\": \"1.2.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.js\",\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n },\n \"./react\": {\n \"browser\": \"./dist/react/index.js\",\n \"import\": \"./dist/react/index.js\",\n \"require\": \"./dist/react/index.cjs\"\n },\n \"./next\": {\n \"browser\": \"./dist/next/index.mjs\",\n \"import\": \"./dist/next/index.mjs\",\n \"require\": \"./dist/next/index.js\"\n },\n \"./server\": {\n \"node\": \"./dist/server/index.js\",\n \"edge-light\": \"./dist/server/index.js\",\n \"import\": \"./dist/server/index.js\",\n \"require\": \"./dist/server/index.cjs\",\n \"default\": \"./dist/server/index.cjs\"\n }\n },\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"typesVersions\": {\n \"*\": {\n \"*\": [\n \"dist/index.d.ts\"\n ],\n \"react\": [\n \"dist/react/index.d.ts\"\n ],\n \"server\": [\n \"dist/server/index.d.ts\"\n ],\n \"next\": [\n \"dist/next/index.d.ts\"\n ]\n }\n },\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"lint\": \"eslint .\",\n \"lint-fix\": \"eslint . --fix\",\n \"test\": \"jest\",\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 \"dependencies\": {\n \"server-only\": \"^0.0.1\"\n },\n \"devDependencies\": {\n \"@swc/core\": \"^1.3.66\",\n \"@swc/jest\": \"^0.2.26\",\n \"@testing-library/jest-dom\": \"^5.16.5\",\n \"@testing-library/react\": \"^14.0.0\",\n \"@types/jest\": \"^29.5.2\",\n \"@types/node\": \"^20.3.1\",\n \"@types/react\": \"^18.2.14\",\n \"@types/testing-library__jest-dom\": \"^5.14.6\",\n \"@vercel/eslint-config\": \"workspace:0.0.0\",\n \"jest\": \"^29.5.0\",\n \"jest-environment-jsdom\": \"^29.5.0\",\n \"react\": \"^18.2.0\",\n \"react-dom\": \"^18.2.0\",\n \"tsup\": \"7.1.0\"\n },\n \"peerDependencies\": {\n \"next\": \">= 13\",\n \"react\": \"^18 || ^19\"\n },\n \"peerDependenciesMeta\": {\n \"next\": {\n \"optional\": true\n },\n \"react\": {\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, 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\n try {\n for (const [key, valueOrArray] of Object.entries(pathParams)) {\n const isValueArray = Array.isArray(valueOrArray);\n const value = isValueArray ? valueOrArray.join('/') : valueOrArray;\n const expr = isValueArray ? `...${key}` : key;\n\n const matcher = new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[${expr}]`);\n }\n }\n\n return result;\n } catch (e) {\n return pathname;\n }\n}\n\nfunction escapeRegExp(string: string): string {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCE,WAAQ;AACR,cAAW;;;ACFN,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO;AAAI;AAEf,SAAO,KAAK,SAAS,KAAK,QAAc;AACtC,KAAC,OAAO,MAAM,OAAO,OAAO,CAA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AAEA,MAAI;AACF,UAAM,QAAQ,gBAAgB,YAAY;AAAA,MACxC,OAAO,aAAa;AAAA,IACtB,CAAC;AAED,iBAAO,OAAP,gCAAY,SAAS;AAAA,MACnB,MAAAA;AAAA,MACA,MAAM;AAAA,IACR;AAAA,EACF,SAAS,KAAP;AACA,QAAI,eAAe,SAAS,cAAc,GAAG;AAE3C,cAAQ,MAAM,GAAG;AAAA,IACnB;AAAA,EACF;AACF;AAEA,SAAS,SAAS,EAAE,OAAO,KAAK,GAA4C;AAjI5E;AAkIE,eAAO,OAAP,gCAAY,YAAY;AAAA,IACtB;AAAA,IACA;AAAA,EACF;AACF;AAMA,IAAO,kBAAQ;AAAA,EACb;AAAA,EACA;AACF;","names":["name"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// package.json
|
|
2
2
|
var name = "@vercel/analytics";
|
|
3
|
-
var version = "1.2.0
|
|
3
|
+
var version = "1.2.0";
|
|
4
4
|
|
|
5
5
|
// src/queue.ts
|
|
6
6
|
var initQueue = () => {
|
|
@@ -140,10 +140,11 @@ function track(name2, properties) {
|
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
|
-
function pageview({ route }) {
|
|
143
|
+
function pageview({ route, path }) {
|
|
144
144
|
var _a;
|
|
145
145
|
(_a = window.va) == null ? void 0 : _a.call(window, "pageview", {
|
|
146
|
-
route
|
|
146
|
+
route,
|
|
147
|
+
path
|
|
147
148
|
});
|
|
148
149
|
}
|
|
149
150
|
var generic_default = {
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../package.json","../src/queue.ts","../src/utils.ts","../src/generic.ts"],"sourcesContent":["{\n \"name\": \"@vercel/analytics\",\n \"version\": \"1.2.0-beta.3\",\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.js\",\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n },\n \"./react\": {\n \"browser\": \"./dist/react/index.js\",\n \"import\": \"./dist/react/index.js\",\n \"require\": \"./dist/react/index.cjs\"\n },\n \"./next\": {\n \"browser\": \"./dist/next/index.mjs\",\n \"import\": \"./dist/next/index.mjs\",\n \"require\": \"./dist/next/index.js\"\n },\n \"./server\": {\n \"node\": \"./dist/server/index.js\",\n \"edge-light\": \"./dist/server/index.js\",\n \"import\": \"./dist/server/index.js\",\n \"require\": \"./dist/server/index.cjs\",\n \"default\": \"./dist/server/index.cjs\"\n }\n },\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"typesVersions\": {\n \"*\": {\n \"*\": [\n \"dist/index.d.ts\"\n ],\n \"react\": [\n \"dist/react/index.d.ts\"\n ],\n \"server\": [\n \"dist/server/index.d.ts\"\n ],\n \"next\": [\n \"dist/next/index.d.ts\"\n ]\n }\n },\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"lint\": \"eslint .\",\n \"lint-fix\": \"eslint . --fix\",\n \"test\": \"jest\",\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 \"dependencies\": {\n \"server-only\": \"^0.0.1\"\n },\n \"devDependencies\": {\n \"@swc/core\": \"^1.3.66\",\n \"@swc/jest\": \"^0.2.26\",\n \"@testing-library/jest-dom\": \"^5.16.5\",\n \"@testing-library/react\": \"^14.0.0\",\n \"@types/jest\": \"^29.5.2\",\n \"@types/node\": \"^20.3.1\",\n \"@types/react\": \"^18.2.14\",\n \"@types/testing-library__jest-dom\": \"^5.14.6\",\n \"@vercel/eslint-config\": \"workspace:0.0.0\",\n \"jest\": \"^29.5.0\",\n \"jest-environment-jsdom\": \"^29.5.0\",\n \"react\": \"^18.2.0\",\n \"react-dom\": \"^18.2.0\",\n \"tsup\": \"7.1.0\"\n },\n \"peerDependencies\": {\n \"next\": \">= 13\",\n \"react\": \"^18 || ^19\"\n },\n \"peerDependenciesMeta\": {\n \"next\": {\n \"optional\": true\n },\n \"react\": {\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, 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\n try {\n for (const [key, valueOrArray] of Object.entries(pathParams)) {\n const isValueArray = Array.isArray(valueOrArray);\n const value = isValueArray ? valueOrArray.join('/') : valueOrArray;\n const expr = isValueArray ? `...${key}` : key;\n\n const matcher = new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[${expr}]`);\n }\n }\n\n return result;\n } catch (e) {\n return pathname;\n }\n}\n\nfunction escapeRegExp(string: string): string {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n","import { name as packageName, version } from '../package.json';\nimport { initQueue } from './queue';\nimport type { AllowedPropertyValues, AnalyticsProps } from './types';\nimport {\n isBrowser,\n parseProperties,\n setMode,\n isDevelopment,\n isProduction,\n} from './utils';\n\nexport const DEV_SCRIPT_URL =\n 'https://va.vercel-scripts.com/v1/script.debug.js';\nexport const PROD_SCRIPT_URL = '/_vercel/insights/script.js';\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 */\nfunction inject(\n props: AnalyticsProps & {\n framework?: 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 =\n props.scriptSrc || (isDevelopment() ? DEV_SCRIPT_URL : PROD_SCRIPT_URL);\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 }\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): 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 });\n return;\n }\n\n try {\n const props = parseProperties(properties, {\n strip: isProduction(),\n });\n\n window.va?.('event', {\n name,\n data: props,\n });\n } catch (err) {\n if (err instanceof Error && isDevelopment()) {\n // eslint-disable-next-line no-console -- Logging to console is intentional\n console.error(err);\n }\n }\n}\n\nfunction pageview({ route }: { route?: string }): void {\n window.va?.('pageview', {\n route,\n });\n}\n\nexport { inject, track, pageview };\nexport type { AnalyticsProps };\n\n// eslint-disable-next-line import/no-default-export -- Default export is intentional\nexport default {\n inject,\n track,\n};\n"],"mappings":";AACE,WAAQ;AACR,cAAW;;;ACFN,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO;AAAI;AAEf,SAAO,KAAK,SAAS,KAAK,QAAc;AACtC,KAAC,OAAO,MAAM,OAAO,OAAO,CAAC,GAAG,KAAK,MAAM;AAAA,EAC7C;AACF;;;ACLO,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;AAEA,SAAS,oBAAkD;AACzD,MAAI;AACF,UAAM,MAAM,QAAQ,IAAI;AACxB,QAAI,QAAQ,iBAAiB,QAAQ,QAAQ;AAC3C,aAAO;AAAA,IACT;AAAA,EACF,SAAS,GAAP;AAAA,EAEF;AACA,SAAO;AACT;AAEO,SAAS,QAAQ,OAAa,QAAc;AACjD,MAAI,SAAS,QAAQ;AACnB,WAAO,MAAM,kBAAkB;AAC/B;AAAA,EACF;AAEA,SAAO,MAAM;AACf;AAEO,SAAS,UAAgB;AAC9B,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,GACK;AACzB,SAAO;AACT;AAEO,SAAS,gBACd,YACA,SAG2D;AAC3D,MAAI,CAAC;AAAY,WAAO;AACxB,MAAI,QAAQ;AACZ,QAAM,kBAA4B,CAAC;AACnC,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,UAA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M,UAAU,OAAO;AAC5C,WAAO,QAAQ,QAAQ;AAAA,EACzB;AAEA,WAAS,KAAK,YAAY,MAAM;AAClC;AAQA,SAAS,MACPA,OACA,YACM;AA5FR;AA6FE,MAAI,CAAC,UAAU,GAAG;AAChB,UAAM,MACJ;AAEF,QAAI,aAAa,GAAG;AAElB,cAAQ,KAAK,GAAG;AAAA,IAClB,OAAO;AACL,YAAM,IAAI,MAAM,GAAG;AAAA,IACrB;AAEA;AAAA,EACF;AAEA,MAAI,CAAC,YAAY;AACf,iBAAO,OAAP,gCAAY,SAAS,EAAE,MAAAA,MAAK;AAC5B;AAAA,EACF;AAEA,MAAI;AACF,UAAM,QAAQ,gBAAgB,YAAY;AAAA,MACxC,OAAO,aAAa;AAAA,IACtB,CAAC;AAED,iBAAO,OAAP,gCAAY,SAAS;AAAA,MACnB,MAAAA;AAAA,MACA,MAAM;AAAA,IACR;AAAA,EACF,SAAS,KAAP;AACA,QAAI,eAAe,SAAS,cAAc,GAAG;AAE3C,cAAQ,MAAM,GAAG;AAAA,IACnB;AAAA,EACF;AACF;AAEA,SAAS,SAAS,EAAE,MAAM,GAA6B;AAjIvD;AAkIE,eAAO,OAAP,gCAAY,YAAY;AAAA,IACtB;AAAA,EACF;AACF;AAMA,IAAO,kBAAQ;AAAA,EACb;AAAA,EACA;AACF;","names":["name"]}
|
|
1
|
+
{"version":3,"sources":["../package.json","../src/queue.ts","../src/utils.ts","../src/generic.ts"],"sourcesContent":["{\n \"name\": \"@vercel/analytics\",\n \"version\": \"1.2.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.js\",\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n },\n \"./react\": {\n \"browser\": \"./dist/react/index.js\",\n \"import\": \"./dist/react/index.js\",\n \"require\": \"./dist/react/index.cjs\"\n },\n \"./next\": {\n \"browser\": \"./dist/next/index.mjs\",\n \"import\": \"./dist/next/index.mjs\",\n \"require\": \"./dist/next/index.js\"\n },\n \"./server\": {\n \"node\": \"./dist/server/index.js\",\n \"edge-light\": \"./dist/server/index.js\",\n \"import\": \"./dist/server/index.js\",\n \"require\": \"./dist/server/index.cjs\",\n \"default\": \"./dist/server/index.cjs\"\n }\n },\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"typesVersions\": {\n \"*\": {\n \"*\": [\n \"dist/index.d.ts\"\n ],\n \"react\": [\n \"dist/react/index.d.ts\"\n ],\n \"server\": [\n \"dist/server/index.d.ts\"\n ],\n \"next\": [\n \"dist/next/index.d.ts\"\n ]\n }\n },\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"lint\": \"eslint .\",\n \"lint-fix\": \"eslint . --fix\",\n \"test\": \"jest\",\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 \"dependencies\": {\n \"server-only\": \"^0.0.1\"\n },\n \"devDependencies\": {\n \"@swc/core\": \"^1.3.66\",\n \"@swc/jest\": \"^0.2.26\",\n \"@testing-library/jest-dom\": \"^5.16.5\",\n \"@testing-library/react\": \"^14.0.0\",\n \"@types/jest\": \"^29.5.2\",\n \"@types/node\": \"^20.3.1\",\n \"@types/react\": \"^18.2.14\",\n \"@types/testing-library__jest-dom\": \"^5.14.6\",\n \"@vercel/eslint-config\": \"workspace:0.0.0\",\n \"jest\": \"^29.5.0\",\n \"jest-environment-jsdom\": \"^29.5.0\",\n \"react\": \"^18.2.0\",\n \"react-dom\": \"^18.2.0\",\n \"tsup\": \"7.1.0\"\n },\n \"peerDependencies\": {\n \"next\": \">= 13\",\n \"react\": \"^18 || ^19\"\n },\n \"peerDependenciesMeta\": {\n \"next\": {\n \"optional\": true\n },\n \"react\": {\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, 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\n try {\n for (const [key, valueOrArray] of Object.entries(pathParams)) {\n const isValueArray = Array.isArray(valueOrArray);\n const value = isValueArray ? valueOrArray.join('/') : valueOrArray;\n const expr = isValueArray ? `...${key}` : key;\n\n const matcher = new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[${expr}]`);\n }\n }\n\n return result;\n } catch (e) {\n return pathname;\n }\n}\n\nfunction escapeRegExp(string: string): string {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n","import { name as packageName, version } from '../package.json';\nimport { initQueue } from './queue';\nimport type { AllowedPropertyValues, AnalyticsProps } from './types';\nimport {\n isBrowser,\n parseProperties,\n setMode,\n isDevelopment,\n isProduction,\n} from './utils';\n\nexport const DEV_SCRIPT_URL =\n 'https://va.vercel-scripts.com/v1/script.debug.js';\nexport const PROD_SCRIPT_URL = '/_vercel/insights/script.js';\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 */\nfunction inject(\n props: AnalyticsProps & {\n framework?: 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 =\n props.scriptSrc || (isDevelopment() ? DEV_SCRIPT_URL : PROD_SCRIPT_URL);\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 }\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): 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 });\n return;\n }\n\n try {\n const props = parseProperties(properties, {\n strip: isProduction(),\n });\n\n window.va?.('event', {\n name,\n data: props,\n });\n } catch (err) {\n if (err instanceof Error && isDevelopment()) {\n // eslint-disable-next-line no-console -- Logging to console is intentional\n console.error(err);\n }\n }\n}\n\nfunction pageview({ route, path }: { route?: string; path?: string }): void {\n window.va?.('pageview', {\n route,\n path,\n });\n}\n\nexport { inject, track, pageview };\nexport type { AnalyticsProps };\n\n// eslint-disable-next-line import/no-default-export -- Default export is intentional\nexport default {\n inject,\n track,\n};\n"],"mappings":";AACE,WAAQ;AACR,cAAW;;;ACFN,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO;AAAI;AAEf,SAAO,KAAK,SAAS,KAAK,QAAc;AACtC,KAAC,OAAO,MAAM,OAAO,OAAO,CAAC,GAAG,KAAK,MAAM;AAAA,EAC7C;AACF;;;ACLO,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;AAEA,SAAS,oBAAkD;AACzD,MAAI;AACF,UAAM,MAAM,QAAQ,IAAI;AACxB,QAAI,QAAQ,iBAAiB,QAAQ,QAAQ;AAC3C,aAAO;AAAA,IACT;AAAA,EACF,SAAS,GAAP;AAAA,EAEF;AACA,SAAO;AACT;AAEO,SAAS,QAAQ,OAAa,QAAc;AACjD,MAAI,SAAS,QAAQ;AACnB,WAAO,MAAM,kBAAkB;AAC/B;AAAA,EACF;AAEA,SAAO,MAAM;AACf;AAEO,SAAS,UAAgB;AAC9B,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,GACK;AACzB,SAAO;AACT;AAEO,SAAS,gBACd,YACA,SAG2D;AAC3D,MAAI,CAAC;AAAY,WAAO;AACxB,MAAI,QAAQ;AACZ,QAAM,kBAA4B,CAAC;AACnC,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,UAAU,GAAG;AACrD,QAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,UAAI,QAAQ,OAAO;AACjB,gBAAQ,UAAU,KAAK,KAAK;AAAA,MAC9B,OAAO;AACL,wBAAgB,KAAK,GAAG;AAAA,MA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UAAM,MACJ;AAEF,QAAI,aAAa,GAAG;AAElB,cAAQ,KAAK,GAAG;AAAA,IAClB,OAAO;AACL,YAAM,IAAI,MAAM,GAAG;AAAA,IACrB;AAEA;AAAA,EACF;AAEA,MAAI,CAAC,YAAY;AACf,iBAAO,OAAP,gCAAY,SAAS,EAAE,MAAAA,MAAK;AAC5B;AAAA,EACF;AAEA,MAAI;AACF,UAAM,QAAQ,gBAAgB,YAAY;AAAA,MACxC,OAAO,aAAa;AAAA,IACtB,CAAC;AAED,iBAAO,OAAP,gCAAY,SAAS;AAAA,MACnB,MAAAA;AAAA,MACA,MAAM;AAAA,IACR;AAAA,EACF,SAAS,KAAP;AACA,QAAI,eAAe,SAAS,cAAc,GAAG;AAE3C,cAAQ,MAAM,GAAG;AAAA,IACnB;AAAA,EACF;AACF;AAEA,SAAS,SAAS,EAAE,OAAO,KAAK,GAA4C;AAjI5E;AAkIE,eAAO,OAAP,gCAAY,YAAY;AAAA,IACtB;AAAA,IACA;AAAA,EACF;AACF;AAMA,IAAO,kBAAQ;AAAA,EACb;AAAA,EACA;AACF;","names":["name"]}
|
package/dist/next/index.js
CHANGED
|
@@ -41,7 +41,7 @@ var import_react = require("react");
|
|
|
41
41
|
|
|
42
42
|
// package.json
|
|
43
43
|
var name = "@vercel/analytics";
|
|
44
|
-
var version = "1.2.0
|
|
44
|
+
var version = "1.2.0";
|
|
45
45
|
|
|
46
46
|
// src/queue.ts
|
|
47
47
|
var initQueue = () => {
|
|
@@ -146,10 +146,11 @@ function inject(props = {
|
|
|
146
146
|
}
|
|
147
147
|
document.head.appendChild(script);
|
|
148
148
|
}
|
|
149
|
-
function pageview({ route }) {
|
|
149
|
+
function pageview({ route, path }) {
|
|
150
150
|
var _a;
|
|
151
151
|
(_a = window.va) == null ? void 0 : _a.call(window, "pageview", {
|
|
152
|
-
route
|
|
152
|
+
route,
|
|
153
|
+
path
|
|
153
154
|
});
|
|
154
155
|
}
|
|
155
156
|
|
|
@@ -161,11 +162,12 @@ function Analytics(props) {
|
|
|
161
162
|
...props.route !== void 0 && { disableAutoTrack: true },
|
|
162
163
|
...props
|
|
163
164
|
});
|
|
164
|
-
}, [
|
|
165
|
+
}, []);
|
|
165
166
|
(0, import_react.useEffect)(() => {
|
|
166
|
-
if (props.route) {
|
|
167
|
+
if (props.route && props.path) {
|
|
167
168
|
pageview({
|
|
168
|
-
route: props.route
|
|
169
|
+
route: props.route,
|
|
170
|
+
path: props.path
|
|
169
171
|
});
|
|
170
172
|
}
|
|
171
173
|
}, [props.route, props.path]);
|
package/dist/next/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/nextjs/index.tsx","../../src/react.tsx","../../package.json","../../src/queue.ts","../../src/utils.ts","../../src/generic.ts","../../src/nextjs/utils.ts"],"sourcesContent":["import React, { Suspense } from 'react';\nimport { Analytics as AnalyticsScript } from '../react';\nimport type { AnalyticsProps } from '../types';\nimport { useRoute } from './utils';\n\ntype Props = Omit<AnalyticsProps, 'route'>;\n\nfunction AnalyticsComponent(props: Props): React.ReactElement {\n const { route, path } = useRoute();\n\n return (\n <AnalyticsScript path={path} route={route} {...props} framework=\"next\" />\n );\n}\n\nexport function Analytics(props: Props): React.ReactElement {\n return (\n <Suspense fallback={null}>\n <AnalyticsComponent {...props} />\n </Suspense>\n );\n}\n\nexport type { AnalyticsProps };\n","import { useEffect } from 'react';\nimport { inject, track, pageview } from './generic';\nimport type { AnalyticsProps } from './types';\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 path?: string | null;\n }\n): null {\n useEffect(() => {\n inject({\n framework: props.framework || 'react',\n ...(props.route !== undefined && { disableAutoTrack: true }),\n ...props,\n });\n }, [props]);\n\n useEffect(() => {\n if (props.route) {\n pageview({\n route: props.route,\n });\n }\n }, [props.route, props.path]);\n\n return null;\n}\n\nexport { track, Analytics };\nexport type { AnalyticsProps };\n","{\n \"name\": \"@vercel/analytics\",\n \"version\": \"1.2.0-beta.3\",\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.js\",\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n },\n \"./react\": {\n \"browser\": \"./dist/react/index.js\",\n \"import\": \"./dist/react/index.js\",\n \"require\": \"./dist/react/index.cjs\"\n },\n \"./next\": {\n \"browser\": \"./dist/next/index.mjs\",\n \"import\": \"./dist/next/index.mjs\",\n \"require\": \"./dist/next/index.js\"\n },\n \"./server\": {\n \"node\": \"./dist/server/index.js\",\n \"edge-light\": \"./dist/server/index.js\",\n \"import\": \"./dist/server/index.js\",\n \"require\": \"./dist/server/index.cjs\",\n \"default\": \"./dist/server/index.cjs\"\n }\n },\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"typesVersions\": {\n \"*\": {\n \"*\": [\n \"dist/index.d.ts\"\n ],\n \"react\": [\n \"dist/react/index.d.ts\"\n ],\n \"server\": [\n \"dist/server/index.d.ts\"\n ],\n \"next\": [\n \"dist/next/index.d.ts\"\n ]\n }\n },\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"lint\": \"eslint .\",\n \"lint-fix\": \"eslint . --fix\",\n \"test\": \"jest\",\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 \"dependencies\": {\n \"server-only\": \"^0.0.1\"\n },\n \"devDependencies\": {\n \"@swc/core\": \"^1.3.66\",\n \"@swc/jest\": \"^0.2.26\",\n \"@testing-library/jest-dom\": \"^5.16.5\",\n \"@testing-library/react\": \"^14.0.0\",\n \"@types/jest\": \"^29.5.2\",\n \"@types/node\": \"^20.3.1\",\n \"@types/react\": \"^18.2.14\",\n \"@types/testing-library__jest-dom\": \"^5.14.6\",\n \"@vercel/eslint-config\": \"workspace:0.0.0\",\n \"jest\": \"^29.5.0\",\n \"jest-environment-jsdom\": \"^29.5.0\",\n \"react\": \"^18.2.0\",\n \"react-dom\": \"^18.2.0\",\n \"tsup\": \"7.1.0\"\n },\n \"peerDependencies\": {\n \"next\": \">= 13\",\n \"react\": \"^18 || ^19\"\n },\n \"peerDependenciesMeta\": {\n \"next\": {\n \"optional\": true\n },\n \"react\": {\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, 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\n try {\n for (const [key, valueOrArray] of Object.entries(pathParams)) {\n const isValueArray = Array.isArray(valueOrArray);\n const value = isValueArray ? valueOrArray.join('/') : valueOrArray;\n const expr = isValueArray ? `...${key}` : key;\n\n const matcher = new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[${expr}]`);\n }\n }\n\n return result;\n } catch (e) {\n return pathname;\n }\n}\n\nfunction escapeRegExp(string: string): string {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n","import { name as packageName, version } from '../package.json';\nimport { initQueue } from './queue';\nimport type { AllowedPropertyValues, AnalyticsProps } from './types';\nimport {\n isBrowser,\n parseProperties,\n setMode,\n isDevelopment,\n isProduction,\n} from './utils';\n\nexport const DEV_SCRIPT_URL =\n 'https://va.vercel-scripts.com/v1/script.debug.js';\nexport const PROD_SCRIPT_URL = '/_vercel/insights/script.js';\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 */\nfunction inject(\n props: AnalyticsProps & {\n framework?: 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 =\n props.scriptSrc || (isDevelopment() ? DEV_SCRIPT_URL : PROD_SCRIPT_URL);\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 }\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): 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 });\n return;\n }\n\n try {\n const props = parseProperties(properties, {\n strip: isProduction(),\n });\n\n window.va?.('event', {\n name,\n data: props,\n });\n } catch (err) {\n if (err instanceof Error && isDevelopment()) {\n // eslint-disable-next-line no-console -- Logging to console is intentional\n console.error(err);\n }\n }\n}\n\nfunction pageview({ route }: { route?: string }): void {\n window.va?.('pageview', {\n route,\n });\n}\n\nexport { inject, track, pageview };\nexport type { AnalyticsProps };\n\n// eslint-disable-next-line import/no-default-export -- Default export is intentional\nexport default {\n inject,\n track,\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 const finalParams = {\n ...Object.fromEntries(searchParams.entries()),\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- can be empty in pages router\n ...(params || {}),\n };\n\n return {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- can be empty in pages router\n route: params ? computeRoute(path, finalParams) : null,\n path,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,mBAAAA;AAAA;AAAA;AAAA,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BAAU,MAAM;AACd,WAAO;AAAA,MACL,WAAW,MAAM,aAAa;AAAA,MAC9B,GAAI,MAAM,UAAU,UAAa,EAAE,kBAAkB,KAAK;AAAA,MAC1D,GAAG;AAAA,IACL,CAAC;AAAA,EACH,GAAG,CAAC,KAAK,CAAC;AAEV,8BAAU,MAAM;AACd,QAAI,MAAM,OAAO;AACf,eAAS;AAAA,QACP,OAAO,MAAM;AAAA,MACf,CAAC;AAAA,IACH;AAAA,EACF,GAAG,CAAC,MAAM,OAAO,MAAM,IAAI,CAAC;AAE5B,SAAO;AACT;;;AKjDA,wBAAwD;AAGjD,IAAM,WAAW,MAGnB;AACH,QAAM,aAAS,6BAAU;AACzB,QAAM,mBAAe,mCAAgB;AACrC,QAAM,WAAO,+BAAY;AAEzB,QAAM,cAAc;AAAA,IAClB,GAAG,OAAO,YAAY,aAAa,QAAQ,CAAC;AAAA;AAAA,IAE5C,GAAI,UAAU,CAAC;AAAA,EACjB;AAEA,SAAO;AAAA;AAAA,IAEL,OAAO,SAAS,aAAa,MAAM,WAAW,IAAI;AAAA,IAClD;AAAA,EACF;AACF;;;ANhBA,SAAS,mBAAmB,OAAkC;AAC5D,QAAM,EAAE,OAAO,KAAK,IAAI,SAAS;AAEjC,SACE,8BAAAC,QAAA,cAAC,aAAgB,MAAY,OAAe,GAAG,OAAO,WAAU,QAAO;AAE3E;AAEO,SAASC,WAAU,OAAkC;AAC1D,SACE,8BAAAD,QAAA,cAAC,0BAAS,UAAU,QAClB,8BAAAA,QAAA,cAAC,sBAAoB,GAAG,OAAO,CACjC;AAEJ;","names":["Analytics","import_react","React","Analytics"]}
|
|
1
|
+
{"version":3,"sources":["../../src/nextjs/index.tsx","../../src/react.tsx","../../package.json","../../src/queue.ts","../../src/utils.ts","../../src/generic.ts","../../src/nextjs/utils.ts"],"sourcesContent":["import React, { Suspense } from 'react';\nimport { Analytics as AnalyticsScript } from '../react';\nimport type { AnalyticsProps } from '../types';\nimport { useRoute } from './utils';\n\ntype Props = Omit<AnalyticsProps, 'route'>;\n\nfunction AnalyticsComponent(props: Props): React.ReactElement {\n const { route, path } = useRoute();\n\n return (\n <AnalyticsScript path={path} route={route} {...props} framework=\"next\" />\n );\n}\n\nexport function Analytics(props: Props): React.ReactElement {\n return (\n <Suspense fallback={null}>\n <AnalyticsComponent {...props} />\n </Suspense>\n );\n}\n\nexport type { AnalyticsProps };\n","import { useEffect } from 'react';\nimport { inject, track, pageview } from './generic';\nimport type { AnalyticsProps } from './types';\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 path?: string | null;\n }\n): null {\n useEffect(() => {\n inject({\n framework: props.framework || 'react',\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 if (props.route && props.path) {\n pageview({\n route: props.route,\n path: props.path,\n });\n }\n }, [props.route, props.path]);\n\n return null;\n}\n\nexport { track, Analytics };\nexport type { AnalyticsProps };\n","{\n \"name\": \"@vercel/analytics\",\n \"version\": \"1.2.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.js\",\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n },\n \"./react\": {\n \"browser\": \"./dist/react/index.js\",\n \"import\": \"./dist/react/index.js\",\n \"require\": \"./dist/react/index.cjs\"\n },\n \"./next\": {\n \"browser\": \"./dist/next/index.mjs\",\n \"import\": \"./dist/next/index.mjs\",\n \"require\": \"./dist/next/index.js\"\n },\n \"./server\": {\n \"node\": \"./dist/server/index.js\",\n \"edge-light\": \"./dist/server/index.js\",\n \"import\": \"./dist/server/index.js\",\n \"require\": \"./dist/server/index.cjs\",\n \"default\": \"./dist/server/index.cjs\"\n }\n },\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"typesVersions\": {\n \"*\": {\n \"*\": [\n \"dist/index.d.ts\"\n ],\n \"react\": [\n \"dist/react/index.d.ts\"\n ],\n \"server\": [\n \"dist/server/index.d.ts\"\n ],\n \"next\": [\n \"dist/next/index.d.ts\"\n ]\n }\n },\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"lint\": \"eslint .\",\n \"lint-fix\": \"eslint . --fix\",\n \"test\": \"jest\",\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 \"dependencies\": {\n \"server-only\": \"^0.0.1\"\n },\n \"devDependencies\": {\n \"@swc/core\": \"^1.3.66\",\n \"@swc/jest\": \"^0.2.26\",\n \"@testing-library/jest-dom\": \"^5.16.5\",\n \"@testing-library/react\": \"^14.0.0\",\n \"@types/jest\": \"^29.5.2\",\n \"@types/node\": \"^20.3.1\",\n \"@types/react\": \"^18.2.14\",\n \"@types/testing-library__jest-dom\": \"^5.14.6\",\n \"@vercel/eslint-config\": \"workspace:0.0.0\",\n \"jest\": \"^29.5.0\",\n \"jest-environment-jsdom\": \"^29.5.0\",\n \"react\": \"^18.2.0\",\n \"react-dom\": \"^18.2.0\",\n \"tsup\": \"7.1.0\"\n },\n \"peerDependencies\": {\n \"next\": \">= 13\",\n \"react\": \"^18 || ^19\"\n },\n \"peerDependenciesMeta\": {\n \"next\": {\n \"optional\": true\n },\n \"react\": {\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, 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\n try {\n for (const [key, valueOrArray] of Object.entries(pathParams)) {\n const isValueArray = Array.isArray(valueOrArray);\n const value = isValueArray ? valueOrArray.join('/') : valueOrArray;\n const expr = isValueArray ? `...${key}` : key;\n\n const matcher = new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[${expr}]`);\n }\n }\n\n return result;\n } catch (e) {\n return pathname;\n }\n}\n\nfunction escapeRegExp(string: string): string {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n","import { name as packageName, version } from '../package.json';\nimport { initQueue } from './queue';\nimport type { AllowedPropertyValues, AnalyticsProps } from './types';\nimport {\n isBrowser,\n parseProperties,\n setMode,\n isDevelopment,\n isProduction,\n} from './utils';\n\nexport const DEV_SCRIPT_URL =\n 'https://va.vercel-scripts.com/v1/script.debug.js';\nexport const PROD_SCRIPT_URL = '/_vercel/insights/script.js';\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 */\nfunction inject(\n props: AnalyticsProps & {\n framework?: 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 =\n props.scriptSrc || (isDevelopment() ? DEV_SCRIPT_URL : PROD_SCRIPT_URL);\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 }\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): 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 });\n return;\n }\n\n try {\n const props = parseProperties(properties, {\n strip: isProduction(),\n });\n\n window.va?.('event', {\n name,\n data: props,\n });\n } catch (err) {\n if (err instanceof Error && isDevelopment()) {\n // eslint-disable-next-line no-console -- Logging to console is intentional\n console.error(err);\n }\n }\n}\n\nfunction pageview({ route, path }: { route?: string; path?: string }): void {\n window.va?.('pageview', {\n route,\n path,\n });\n}\n\nexport { inject, track, pageview };\nexport type { AnalyticsProps };\n\n// eslint-disable-next-line import/no-default-export -- Default export is intentional\nexport default {\n inject,\n track,\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 const finalParams = {\n ...Object.fromEntries(searchParams.entries()),\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- can be empty in pages router\n ...(params || {}),\n };\n\n return {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- can be empty in pages router\n route: params ? computeRoute(path, finalParams) : null,\n path,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,mBAAAA;AAAA;AAAA;AAAA,IAAAC,gBAAgC;;;ACAhC,mBAA0B;;;ACCxB,WAAQ;AACR,cAAW;;;ACFN,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO;AAAI;AAEf,SAAO,KAAK,SAAS,KAAK,QAAc;AACtC,KAAC,OAAO,MAAM,OAAO,OAAO,CAAC,GAAG,KAAK,MAAM;AAAA,EAC7C;AACF;;;ACLO,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;AAEA,SAAS,oBAAkD;AACzD,MAAI;AACF,UAAM,MAAM,QAAQ,IAAI;AACxB,QAAI,QAAQ,iBAAiB,QAAQ,QAAQ;AAC3C,aAAO;AAAA,IACT;AAAA,EACF,SAAS,GAAP;AAAA,EAEF;AACA,SAAO;AACT;AAEO,SAAS,QAAQ,OAAa,QAAc;AACjD,MAAI,SAAS,QAAQ;AACnB,WAAO,MAAM,kBAAkB;AAC/B;A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IAClB,GAAG,OAAO,YAAY,aAAa,QAAQ,CAAC;AAAA;AAAA,IAE5C,GAAI,UAAU,CAAC;AAAA,EACjB;AAEA,SAAO;AAAA;AAAA,IAEL,OAAO,SAAS,aAAa,MAAM,WAAW,IAAI;AAAA,IAClD;AAAA,EACF;AACF;;;ANhBA,SAAS,mBAAmB,OAAkC;AAC5D,QAAM,EAAE,OAAO,KAAK,IAAI,SAAS;AAEjC,SACE,8BAAAC,QAAA,cAAC,aAAgB,MAAY,OAAe,GAAG,OAAO,WAAU,QAAO;AAE3E;AAEO,SAASC,WAAU,OAAkC;AAC1D,SACE,8BAAAD,QAAA,cAAC,0BAAS,UAAU,QAClB,8BAAAA,QAAA,cAAC,sBAAoB,GAAG,OAAO,CACjC;AAEJ;","names":["Analytics","import_react","React","Analytics"]}
|
package/dist/next/index.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import { useEffect } from "react";
|
|
|
8
8
|
|
|
9
9
|
// package.json
|
|
10
10
|
var name = "@vercel/analytics";
|
|
11
|
-
var version = "1.2.0
|
|
11
|
+
var version = "1.2.0";
|
|
12
12
|
|
|
13
13
|
// src/queue.ts
|
|
14
14
|
var initQueue = () => {
|
|
@@ -113,10 +113,11 @@ function inject(props = {
|
|
|
113
113
|
}
|
|
114
114
|
document.head.appendChild(script);
|
|
115
115
|
}
|
|
116
|
-
function pageview({ route }) {
|
|
116
|
+
function pageview({ route, path }) {
|
|
117
117
|
var _a;
|
|
118
118
|
(_a = window.va) == null ? void 0 : _a.call(window, "pageview", {
|
|
119
|
-
route
|
|
119
|
+
route,
|
|
120
|
+
path
|
|
120
121
|
});
|
|
121
122
|
}
|
|
122
123
|
|
|
@@ -128,11 +129,12 @@ function Analytics(props) {
|
|
|
128
129
|
...props.route !== void 0 && { disableAutoTrack: true },
|
|
129
130
|
...props
|
|
130
131
|
});
|
|
131
|
-
}, [
|
|
132
|
+
}, []);
|
|
132
133
|
useEffect(() => {
|
|
133
|
-
if (props.route) {
|
|
134
|
+
if (props.route && props.path) {
|
|
134
135
|
pageview({
|
|
135
|
-
route: props.route
|
|
136
|
+
route: props.route,
|
|
137
|
+
path: props.path
|
|
136
138
|
});
|
|
137
139
|
}
|
|
138
140
|
}, [props.route, props.path]);
|
package/dist/next/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/nextjs/index.tsx","../../src/react.tsx","../../package.json","../../src/queue.ts","../../src/utils.ts","../../src/generic.ts","../../src/nextjs/utils.ts"],"sourcesContent":["import React, { Suspense } from 'react';\nimport { Analytics as AnalyticsScript } from '../react';\nimport type { AnalyticsProps } from '../types';\nimport { useRoute } from './utils';\n\ntype Props = Omit<AnalyticsProps, 'route'>;\n\nfunction AnalyticsComponent(props: Props): React.ReactElement {\n const { route, path } = useRoute();\n\n return (\n <AnalyticsScript path={path} route={route} {...props} framework=\"next\" />\n );\n}\n\nexport function Analytics(props: Props): React.ReactElement {\n return (\n <Suspense fallback={null}>\n <AnalyticsComponent {...props} />\n </Suspense>\n );\n}\n\nexport type { AnalyticsProps };\n","import { useEffect } from 'react';\nimport { inject, track, pageview } from './generic';\nimport type { AnalyticsProps } from './types';\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 path?: string | null;\n }\n): null {\n useEffect(() => {\n inject({\n framework: props.framework || 'react',\n ...(props.route !== undefined && { disableAutoTrack: true }),\n ...props,\n });\n }, [props]);\n\n useEffect(() => {\n if (props.route) {\n pageview({\n route: props.route,\n });\n }\n }, [props.route, props.path]);\n\n return null;\n}\n\nexport { track, Analytics };\nexport type { AnalyticsProps };\n","{\n \"name\": \"@vercel/analytics\",\n \"version\": \"1.2.0-beta.3\",\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.js\",\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n },\n \"./react\": {\n \"browser\": \"./dist/react/index.js\",\n \"import\": \"./dist/react/index.js\",\n \"require\": \"./dist/react/index.cjs\"\n },\n \"./next\": {\n \"browser\": \"./dist/next/index.mjs\",\n \"import\": \"./dist/next/index.mjs\",\n \"require\": \"./dist/next/index.js\"\n },\n \"./server\": {\n \"node\": \"./dist/server/index.js\",\n \"edge-light\": \"./dist/server/index.js\",\n \"import\": \"./dist/server/index.js\",\n \"require\": \"./dist/server/index.cjs\",\n \"default\": \"./dist/server/index.cjs\"\n }\n },\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"typesVersions\": {\n \"*\": {\n \"*\": [\n \"dist/index.d.ts\"\n ],\n \"react\": [\n \"dist/react/index.d.ts\"\n ],\n \"server\": [\n \"dist/server/index.d.ts\"\n ],\n \"next\": [\n \"dist/next/index.d.ts\"\n ]\n }\n },\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"lint\": \"eslint .\",\n \"lint-fix\": \"eslint . --fix\",\n \"test\": \"jest\",\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 \"dependencies\": {\n \"server-only\": \"^0.0.1\"\n },\n \"devDependencies\": {\n \"@swc/core\": \"^1.3.66\",\n \"@swc/jest\": \"^0.2.26\",\n \"@testing-library/jest-dom\": \"^5.16.5\",\n \"@testing-library/react\": \"^14.0.0\",\n \"@types/jest\": \"^29.5.2\",\n \"@types/node\": \"^20.3.1\",\n \"@types/react\": \"^18.2.14\",\n \"@types/testing-library__jest-dom\": \"^5.14.6\",\n \"@vercel/eslint-config\": \"workspace:0.0.0\",\n \"jest\": \"^29.5.0\",\n \"jest-environment-jsdom\": \"^29.5.0\",\n \"react\": \"^18.2.0\",\n \"react-dom\": \"^18.2.0\",\n \"tsup\": \"7.1.0\"\n },\n \"peerDependencies\": {\n \"next\": \">= 13\",\n \"react\": \"^18 || ^19\"\n },\n \"peerDependenciesMeta\": {\n \"next\": {\n \"optional\": true\n },\n \"react\": {\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, 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\n try {\n for (const [key, valueOrArray] of Object.entries(pathParams)) {\n const isValueArray = Array.isArray(valueOrArray);\n const value = isValueArray ? valueOrArray.join('/') : valueOrArray;\n const expr = isValueArray ? `...${key}` : key;\n\n const matcher = new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[${expr}]`);\n }\n }\n\n return result;\n } catch (e) {\n return pathname;\n }\n}\n\nfunction escapeRegExp(string: string): string {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n","import { name as packageName, version } from '../package.json';\nimport { initQueue } from './queue';\nimport type { AllowedPropertyValues, AnalyticsProps } from './types';\nimport {\n isBrowser,\n parseProperties,\n setMode,\n isDevelopment,\n isProduction,\n} from './utils';\n\nexport const DEV_SCRIPT_URL =\n 'https://va.vercel-scripts.com/v1/script.debug.js';\nexport const PROD_SCRIPT_URL = '/_vercel/insights/script.js';\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 */\nfunction inject(\n props: AnalyticsProps & {\n framework?: 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 =\n props.scriptSrc || (isDevelopment() ? DEV_SCRIPT_URL : PROD_SCRIPT_URL);\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 }\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): 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 });\n return;\n }\n\n try {\n const props = parseProperties(properties, {\n strip: isProduction(),\n });\n\n window.va?.('event', {\n name,\n data: props,\n });\n } catch (err) {\n if (err instanceof Error && isDevelopment()) {\n // eslint-disable-next-line no-console -- Logging to console is intentional\n console.error(err);\n }\n }\n}\n\nfunction pageview({ route }: { route?: string }): void {\n window.va?.('pageview', {\n route,\n });\n}\n\nexport { inject, track, pageview };\nexport type { AnalyticsProps };\n\n// eslint-disable-next-line import/no-default-export -- Default export is intentional\nexport default {\n inject,\n track,\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 const finalParams = {\n ...Object.fromEntries(searchParams.entries()),\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- can be empty in pages router\n ...(params || {}),\n };\n\n return {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- can be empty in pages router\n route: params ? computeRoute(path, finalParams) : null,\n path,\n };\n};\n"],"mappings":";;;AAAA,OAAO,SAAS,gBAAgB;;;ACAhC,SAAS,iBAAiB;;;ACCxB,WAAQ;AACR,cAAW;;;ACFN,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO;AAAI;AAEf,SAAO,KAAK,SAAS,KAAK,QAAc;AACtC,KAAC,OAAO,MAAM,OAAO,OAAO,CAAC,GAAG,KAAK,MAAM;AAAA,EAC7C;AACF;;;ACLO,SAAS,YAAqB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MAAM;AAAA,MACf,CAAC;AAAA,IACH;AAAA,EACF,GAAG,CAAC,MAAM,OAAO,MAAM,IAAI,CAAC;AAE5B,SAAO;AACT;;;AKjDA,SAAS,WAAW,aAAa,uBAAuB;AAGjD,IAAM,WAAW,MAGnB;AACH,QAAM,SAAS,UAAU;AACzB,QAAM,eAAe,gBAAgB;AACrC,QAAM,OAAO,YAAY;AAEzB,QAAM,cAAc;AAAA,IAClB,GAAG,OAAO,YAAY,aAAa,QAAQ,CAAC;AAAA;AAAA,IAE5C,GAAI,UAAU,CAAC;AAAA,EACjB;AAEA,SAAO;AAAA;AAAA,IAEL,OAAO,SAAS,aAAa,MAAM,WAAW,IAAI;AAAA,IAClD;AAAA,EACF;AACF;;;ANhBA,SAAS,mBAAmB,OAAkC;AAC5D,QAAM,EAAE,OAAO,KAAK,IAAI,SAAS;AAEjC,SACE,oCAAC,aAAgB,MAAY,OAAe,GAAG,OAAO,WAAU,QAAO;AAE3E;AAEO,SAASA,WAAU,OAAkC;AAC1D,SACE,oCAAC,YAAS,UAAU,QAClB,oCAAC,sBAAoB,GAAG,OAAO,CACjC;AAEJ;","names":["Analytics"]}
|
|
1
|
+
{"version":3,"sources":["../../src/nextjs/index.tsx","../../src/react.tsx","../../package.json","../../src/queue.ts","../../src/utils.ts","../../src/generic.ts","../../src/nextjs/utils.ts"],"sourcesContent":["import React, { Suspense } from 'react';\nimport { Analytics as AnalyticsScript } from '../react';\nimport type { AnalyticsProps } from '../types';\nimport { useRoute } from './utils';\n\ntype Props = Omit<AnalyticsProps, 'route'>;\n\nfunction AnalyticsComponent(props: Props): React.ReactElement {\n const { route, path } = useRoute();\n\n return (\n <AnalyticsScript path={path} route={route} {...props} framework=\"next\" />\n );\n}\n\nexport function Analytics(props: Props): React.ReactElement {\n return (\n <Suspense fallback={null}>\n <AnalyticsComponent {...props} />\n </Suspense>\n );\n}\n\nexport type { AnalyticsProps };\n","import { useEffect } from 'react';\nimport { inject, track, pageview } from './generic';\nimport type { AnalyticsProps } from './types';\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 path?: string | null;\n }\n): null {\n useEffect(() => {\n inject({\n framework: props.framework || 'react',\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 if (props.route && props.path) {\n pageview({\n route: props.route,\n path: props.path,\n });\n }\n }, [props.route, props.path]);\n\n return null;\n}\n\nexport { track, Analytics };\nexport type { AnalyticsProps };\n","{\n \"name\": \"@vercel/analytics\",\n \"version\": \"1.2.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.js\",\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n },\n \"./react\": {\n \"browser\": \"./dist/react/index.js\",\n \"import\": \"./dist/react/index.js\",\n \"require\": \"./dist/react/index.cjs\"\n },\n \"./next\": {\n \"browser\": \"./dist/next/index.mjs\",\n \"import\": \"./dist/next/index.mjs\",\n \"require\": \"./dist/next/index.js\"\n },\n \"./server\": {\n \"node\": \"./dist/server/index.js\",\n \"edge-light\": \"./dist/server/index.js\",\n \"import\": \"./dist/server/index.js\",\n \"require\": \"./dist/server/index.cjs\",\n \"default\": \"./dist/server/index.cjs\"\n }\n },\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"typesVersions\": {\n \"*\": {\n \"*\": [\n \"dist/index.d.ts\"\n ],\n \"react\": [\n \"dist/react/index.d.ts\"\n ],\n \"server\": [\n \"dist/server/index.d.ts\"\n ],\n \"next\": [\n \"dist/next/index.d.ts\"\n ]\n }\n },\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"lint\": \"eslint .\",\n \"lint-fix\": \"eslint . --fix\",\n \"test\": \"jest\",\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 \"dependencies\": {\n \"server-only\": \"^0.0.1\"\n },\n \"devDependencies\": {\n \"@swc/core\": \"^1.3.66\",\n \"@swc/jest\": \"^0.2.26\",\n \"@testing-library/jest-dom\": \"^5.16.5\",\n \"@testing-library/react\": \"^14.0.0\",\n \"@types/jest\": \"^29.5.2\",\n \"@types/node\": \"^20.3.1\",\n \"@types/react\": \"^18.2.14\",\n \"@types/testing-library__jest-dom\": \"^5.14.6\",\n \"@vercel/eslint-config\": \"workspace:0.0.0\",\n \"jest\": \"^29.5.0\",\n \"jest-environment-jsdom\": \"^29.5.0\",\n \"react\": \"^18.2.0\",\n \"react-dom\": \"^18.2.0\",\n \"tsup\": \"7.1.0\"\n },\n \"peerDependencies\": {\n \"next\": \">= 13\",\n \"react\": \"^18 || ^19\"\n },\n \"peerDependenciesMeta\": {\n \"next\": {\n \"optional\": true\n },\n \"react\": {\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, 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\n try {\n for (const [key, valueOrArray] of Object.entries(pathParams)) {\n const isValueArray = Array.isArray(valueOrArray);\n const value = isValueArray ? valueOrArray.join('/') : valueOrArray;\n const expr = isValueArray ? `...${key}` : key;\n\n const matcher = new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[${expr}]`);\n }\n }\n\n return result;\n } catch (e) {\n return pathname;\n }\n}\n\nfunction escapeRegExp(string: string): string {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n","import { name as packageName, version } from '../package.json';\nimport { initQueue } from './queue';\nimport type { AllowedPropertyValues, AnalyticsProps } from './types';\nimport {\n isBrowser,\n parseProperties,\n setMode,\n isDevelopment,\n isProduction,\n} from './utils';\n\nexport const DEV_SCRIPT_URL =\n 'https://va.vercel-scripts.com/v1/script.debug.js';\nexport const PROD_SCRIPT_URL = '/_vercel/insights/script.js';\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 */\nfunction inject(\n props: AnalyticsProps & {\n framework?: 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 =\n props.scriptSrc || (isDevelopment() ? DEV_SCRIPT_URL : PROD_SCRIPT_URL);\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 }\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): 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 });\n return;\n }\n\n try {\n const props = parseProperties(properties, {\n strip: isProduction(),\n });\n\n window.va?.('event', {\n name,\n data: props,\n });\n } catch (err) {\n if (err instanceof Error && isDevelopment()) {\n // eslint-disable-next-line no-console -- Logging to console is intentional\n console.error(err);\n }\n }\n}\n\nfunction pageview({ route, path }: { route?: string; path?: string }): void {\n window.va?.('pageview', {\n route,\n path,\n });\n}\n\nexport { inject, track, pageview };\nexport type { AnalyticsProps };\n\n// eslint-disable-next-line import/no-default-export -- Default export is intentional\nexport default {\n inject,\n track,\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 const finalParams = {\n ...Object.fromEntries(searchParams.entries()),\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- can be empty in pages router\n ...(params || {}),\n };\n\n return {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- can be empty in pages router\n route: params ? computeRoute(path, finalParams) : null,\n path,\n };\n};\n"],"mappings":";;;AAAA,OAAO,SAAS,gBAAgB;;;ACAhC,SAAS,iBAAiB;;;ACCxB,WAAQ;AACR,cAAW;;;ACFN,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO;AAAI;AAEf,SAAO,KAAK,SAAS,KAAK,QAAc;AACtC,KAAC,OAAO,MAAM,OAAO,OAAO,CAAC,GAAG,KAAK,MAAM;AAAA,EAC7C;AACF;;;ACLO,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;AAEA,SAAS,oBAAkD;AACzD,MAAI;AACF,UAAM,MAAM,QAAQ,IAAI;AACxB,QAAI,QAAQ,iBAAiB,QAAQ,QAAQ;AAC3C,aAAO;AAAA,IACT;AAAA,EACF,SAAS,GAAP;AAAA,EAEF;AACA,SAAO;AACT;AAEO,SAAS,QAAQ,OAAa,QAAc;AACjD,MAAI,SAAS,QAAQ;AACnB,WAAO,MAAM,kBAAkB;AAC/B;AAAA,EACF;AAEA,SAAO,MAAM;AACf;AAEO,SAAS,UAAgB;AAC9B,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;AAEb,MAAI;AACF,eAAW,CAAC,KAAK,YAAY,KAAK,OAAO,QAAQ,UAAU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ASA,WAAU,OAAkC;AAC1D,SACE,oCAAC,YAAS,UAAU,QAClB,oCAAC,sBAAoB,GAAG,OAAO,CACjC;AAEJ;","names":["Analytics"]}
|
package/dist/react/index.js
CHANGED
|
@@ -29,7 +29,7 @@ var import_react = require("react");
|
|
|
29
29
|
|
|
30
30
|
// package.json
|
|
31
31
|
var name = "@vercel/analytics";
|
|
32
|
-
var version = "1.2.0
|
|
32
|
+
var version = "1.2.0";
|
|
33
33
|
|
|
34
34
|
// src/queue.ts
|
|
35
35
|
var initQueue = () => {
|
|
@@ -169,10 +169,11 @@ function track(name2, properties) {
|
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
|
-
function pageview({ route }) {
|
|
172
|
+
function pageview({ route, path }) {
|
|
173
173
|
var _a;
|
|
174
174
|
(_a = window.va) == null ? void 0 : _a.call(window, "pageview", {
|
|
175
|
-
route
|
|
175
|
+
route,
|
|
176
|
+
path
|
|
176
177
|
});
|
|
177
178
|
}
|
|
178
179
|
|
|
@@ -184,11 +185,12 @@ function Analytics(props) {
|
|
|
184
185
|
...props.route !== void 0 && { disableAutoTrack: true },
|
|
185
186
|
...props
|
|
186
187
|
});
|
|
187
|
-
}, [
|
|
188
|
+
}, []);
|
|
188
189
|
(0, import_react.useEffect)(() => {
|
|
189
|
-
if (props.route) {
|
|
190
|
+
if (props.route && props.path) {
|
|
190
191
|
pageview({
|
|
191
|
-
route: props.route
|
|
192
|
+
route: props.route,
|
|
193
|
+
path: props.path
|
|
192
194
|
});
|
|
193
195
|
}
|
|
194
196
|
}, [props.route, props.path]);
|
package/dist/react/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/react.tsx","../../package.json","../../src/queue.ts","../../src/utils.ts","../../src/generic.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport { inject, track, pageview } from './generic';\nimport type { AnalyticsProps } from './types';\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 path?: string | null;\n }\n): null {\n useEffect(() => {\n inject({\n framework: props.framework || 'react',\n ...(props.route !== undefined && { disableAutoTrack: true }),\n ...props,\n });\n }, [props]);\n\n useEffect(() => {\n if (props.route) {\n pageview({\n route: props.route,\n });\n }\n }, [props.route, props.path]);\n\n return null;\n}\n\nexport { track, Analytics };\nexport type { AnalyticsProps };\n","{\n \"name\": \"@vercel/analytics\",\n \"version\": \"1.2.0-beta.3\",\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.js\",\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n },\n \"./react\": {\n \"browser\": \"./dist/react/index.js\",\n \"import\": \"./dist/react/index.js\",\n \"require\": \"./dist/react/index.cjs\"\n },\n \"./next\": {\n \"browser\": \"./dist/next/index.mjs\",\n \"import\": \"./dist/next/index.mjs\",\n \"require\": \"./dist/next/index.js\"\n },\n \"./server\": {\n \"node\": \"./dist/server/index.js\",\n \"edge-light\": \"./dist/server/index.js\",\n \"import\": \"./dist/server/index.js\",\n \"require\": \"./dist/server/index.cjs\",\n \"default\": \"./dist/server/index.cjs\"\n }\n },\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"typesVersions\": {\n \"*\": {\n \"*\": [\n \"dist/index.d.ts\"\n ],\n \"react\": [\n \"dist/react/index.d.ts\"\n ],\n \"server\": [\n \"dist/server/index.d.ts\"\n ],\n \"next\": [\n \"dist/next/index.d.ts\"\n ]\n }\n },\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"lint\": \"eslint .\",\n \"lint-fix\": \"eslint . --fix\",\n \"test\": \"jest\",\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 \"dependencies\": {\n \"server-only\": \"^0.0.1\"\n },\n \"devDependencies\": {\n \"@swc/core\": \"^1.3.66\",\n \"@swc/jest\": \"^0.2.26\",\n \"@testing-library/jest-dom\": \"^5.16.5\",\n \"@testing-library/react\": \"^14.0.0\",\n \"@types/jest\": \"^29.5.2\",\n \"@types/node\": \"^20.3.1\",\n \"@types/react\": \"^18.2.14\",\n \"@types/testing-library__jest-dom\": \"^5.14.6\",\n \"@vercel/eslint-config\": \"workspace:0.0.0\",\n \"jest\": \"^29.5.0\",\n \"jest-environment-jsdom\": \"^29.5.0\",\n \"react\": \"^18.2.0\",\n \"react-dom\": \"^18.2.0\",\n \"tsup\": \"7.1.0\"\n },\n \"peerDependencies\": {\n \"next\": \">= 13\",\n \"react\": \"^18 || ^19\"\n },\n \"peerDependenciesMeta\": {\n \"next\": {\n \"optional\": true\n },\n \"react\": {\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, 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\n try {\n for (const [key, valueOrArray] of Object.entries(pathParams)) {\n const isValueArray = Array.isArray(valueOrArray);\n const value = isValueArray ? valueOrArray.join('/') : valueOrArray;\n const expr = isValueArray ? `...${key}` : key;\n\n const matcher = new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[${expr}]`);\n }\n }\n\n return result;\n } catch (e) {\n return pathname;\n }\n}\n\nfunction escapeRegExp(string: string): string {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n","import { name as packageName, version } from '../package.json';\nimport { initQueue } from './queue';\nimport type { AllowedPropertyValues, AnalyticsProps } from './types';\nimport {\n isBrowser,\n parseProperties,\n setMode,\n isDevelopment,\n isProduction,\n} from './utils';\n\nexport const DEV_SCRIPT_URL =\n 'https://va.vercel-scripts.com/v1/script.debug.js';\nexport const PROD_SCRIPT_URL = '/_vercel/insights/script.js';\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 */\nfunction inject(\n props: AnalyticsProps & {\n framework?: 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 =\n props.scriptSrc || (isDevelopment() ? DEV_SCRIPT_URL : PROD_SCRIPT_URL);\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 }\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): 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 });\n return;\n }\n\n try {\n const props = parseProperties(properties, {\n strip: isProduction(),\n });\n\n window.va?.('event', {\n name,\n data: props,\n });\n } catch (err) {\n if (err instanceof Error && isDevelopment()) {\n // eslint-disable-next-line no-console -- Logging to console is intentional\n console.error(err);\n }\n }\n}\n\nfunction pageview({ route }: { route?: string }): void {\n window.va?.('pageview', {\n route,\n });\n}\n\nexport { inject, track, pageview };\nexport type { AnalyticsProps };\n\n// eslint-disable-next-line import/no-default-export -- Default export is intentional\nexport default {\n inject,\n track,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;;;ACCxB,WAAQ;AACR,cAAW;;;ACFN,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO;AAAI;AAEf,SAA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f,iBAAO,OAAP,gCAAY,SAAS,EAAE,MAAAA,MAAK;AAC5B;AAAA,EACF;AAEA,MAAI;AACF,UAAM,QAAQ,gBAAgB,YAAY;AAAA,MACxC,OAAO,aAAa;AAAA,IACtB,CAAC;AAED,iBAAO,OAAP,gCAAY,SAAS;AAAA,MACnB,MAAAA;AAAA,MACA,MAAM;AAAA,IACR;AAAA,EACF,SAAS,KAAP;AACA,QAAI,eAAe,SAAS,cAAc,GAAG;AAE3C,cAAQ,MAAM,GAAG;AAAA,IACnB;AAAA,EACF;AACF;AAEA,SAAS,SAAS,EAAE,MAAM,GAA6B;AAjIvD;AAkIE,eAAO,OAAP,gCAAY,YAAY;AAAA,IACtB;AAAA,EACF;AACF;;;AJ1GA,SAAS,UACP,OAIM;AACN,8BAAU,MAAM;AACd,WAAO;AAAA,MACL,WAAW,MAAM,aAAa;AAAA,MAC9B,GAAI,MAAM,UAAU,UAAa,EAAE,kBAAkB,KAAK;AAAA,MAC1D,GAAG;AAAA,IACL,CAAC;AAAA,EACH,GAAG,CAAC,KAAK,CAAC;AAEV,8BAAU,MAAM;AACd,QAAI,MAAM,OAAO;AACf,eAAS;AAAA,QACP,OAAO,MAAM;AAAA,MACf,CAAC;AAAA,IACH;AAAA,EACF,GAAG,CAAC,MAAM,OAAO,MAAM,IAAI,CAAC;AAE5B,SAAO;AACT;","names":["name"]}
|
|
1
|
+
{"version":3,"sources":["../../src/react.tsx","../../package.json","../../src/queue.ts","../../src/utils.ts","../../src/generic.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport { inject, track, pageview } from './generic';\nimport type { AnalyticsProps } from './types';\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 path?: string | null;\n }\n): null {\n useEffect(() => {\n inject({\n framework: props.framework || 'react',\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 if (props.route && props.path) {\n pageview({\n route: props.route,\n path: props.path,\n });\n }\n }, [props.route, props.path]);\n\n return null;\n}\n\nexport { track, Analytics };\nexport type { AnalyticsProps };\n","{\n \"name\": \"@vercel/analytics\",\n \"version\": \"1.2.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.js\",\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n },\n \"./react\": {\n \"browser\": \"./dist/react/index.js\",\n \"import\": \"./dist/react/index.js\",\n \"require\": \"./dist/react/index.cjs\"\n },\n \"./next\": {\n \"browser\": \"./dist/next/index.mjs\",\n \"import\": \"./dist/next/index.mjs\",\n \"require\": \"./dist/next/index.js\"\n },\n \"./server\": {\n \"node\": \"./dist/server/index.js\",\n \"edge-light\": \"./dist/server/index.js\",\n \"import\": \"./dist/server/index.js\",\n \"require\": \"./dist/server/index.cjs\",\n \"default\": \"./dist/server/index.cjs\"\n }\n },\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"typesVersions\": {\n \"*\": {\n \"*\": [\n \"dist/index.d.ts\"\n ],\n \"react\": [\n \"dist/react/index.d.ts\"\n ],\n \"server\": [\n \"dist/server/index.d.ts\"\n ],\n \"next\": [\n \"dist/next/index.d.ts\"\n ]\n }\n },\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"lint\": \"eslint .\",\n \"lint-fix\": \"eslint . --fix\",\n \"test\": \"jest\",\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 \"dependencies\": {\n \"server-only\": \"^0.0.1\"\n },\n \"devDependencies\": {\n \"@swc/core\": \"^1.3.66\",\n \"@swc/jest\": \"^0.2.26\",\n \"@testing-library/jest-dom\": \"^5.16.5\",\n \"@testing-library/react\": \"^14.0.0\",\n \"@types/jest\": \"^29.5.2\",\n \"@types/node\": \"^20.3.1\",\n \"@types/react\": \"^18.2.14\",\n \"@types/testing-library__jest-dom\": \"^5.14.6\",\n \"@vercel/eslint-config\": \"workspace:0.0.0\",\n \"jest\": \"^29.5.0\",\n \"jest-environment-jsdom\": \"^29.5.0\",\n \"react\": \"^18.2.0\",\n \"react-dom\": \"^18.2.0\",\n \"tsup\": \"7.1.0\"\n },\n \"peerDependencies\": {\n \"next\": \">= 13\",\n \"react\": \"^18 || ^19\"\n },\n \"peerDependenciesMeta\": {\n \"next\": {\n \"optional\": true\n },\n \"react\": {\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, 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\n try {\n for (const [key, valueOrArray] of Object.entries(pathParams)) {\n const isValueArray = Array.isArray(valueOrArray);\n const value = isValueArray ? valueOrArray.join('/') : valueOrArray;\n const expr = isValueArray ? `...${key}` : key;\n\n const matcher = new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[${expr}]`);\n }\n }\n\n return result;\n } catch (e) {\n return pathname;\n }\n}\n\nfunction escapeRegExp(string: string): string {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n","import { name as packageName, version } from '../package.json';\nimport { initQueue } from './queue';\nimport type { AllowedPropertyValues, AnalyticsProps } from './types';\nimport {\n isBrowser,\n parseProperties,\n setMode,\n isDevelopment,\n isProduction,\n} from './utils';\n\nexport const DEV_SCRIPT_URL =\n 'https://va.vercel-scripts.com/v1/script.debug.js';\nexport const PROD_SCRIPT_URL = '/_vercel/insights/script.js';\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 */\nfunction inject(\n props: AnalyticsProps & {\n framework?: 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 =\n props.scriptSrc || (isDevelopment() ? DEV_SCRIPT_URL : PROD_SCRIPT_URL);\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 }\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): 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 });\n return;\n }\n\n try {\n const props = parseProperties(properties, {\n strip: isProduction(),\n });\n\n window.va?.('event', {\n name,\n data: props,\n });\n } catch (err) {\n if (err instanceof Error && isDevelopment()) {\n // eslint-disable-next-line no-console -- Logging to console is intentional\n console.error(err);\n }\n }\n}\n\nfunction pageview({ route, path }: { route?: string; path?: string }): void {\n window.va?.('pageview', {\n route,\n path,\n });\n}\n\nexport { inject, track, pageview };\nexport type { AnalyticsProps };\n\n// eslint-disable-next-line import/no-default-export -- Default export is intentional\nexport default {\n inject,\n track,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;;;ACCxB,WAAQ;AACR,cAAW;;;ACFN,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO;AAAI;AAEf,SAAO,KAAK,SAAS,KAAK,QAAc;AACtC,KAAC,OAAO,MAAM,OAAO,OAAO,CAAC,GAAG,KAAK,MAAM;AAAA,EAC7C;AACF;;;ACLO,SAAS,YA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,OAAO,aAAa;AAAA,IACtB,CAAC;AAED,iBAAO,OAAP,gCAAY,SAAS;AAAA,MACnB,MAAAA;AAAA,MACA,MAAM;AAAA,IACR;AAAA,EACF,SAAS,KAAP;AACA,QAAI,eAAe,SAAS,cAAc,GAAG;AAE3C,cAAQ,MAAM,GAAG;AAAA,IACnB;AAAA,EACF;AACF;AAEA,SAAS,SAAS,EAAE,OAAO,KAAK,GAA4C;AAjI5E;AAkIE,eAAO,OAAP,gCAAY,YAAY;AAAA,IACtB;AAAA,IACA;AAAA,EACF;AACF;;;AJ3GA,SAAS,UACP,OAIM;AACN,8BAAU,MAAM;AACd,WAAO;AAAA,MACL,WAAW,MAAM,aAAa;AAAA,MAC9B,GAAI,MAAM,UAAU,UAAa,EAAE,kBAAkB,KAAK;AAAA,MAC1D,GAAG;AAAA,IACL,CAAC;AAAA,EAEH,GAAG,CAAC,CAAC;AAEL,8BAAU,MAAM;AACd,QAAI,MAAM,SAAS,MAAM,MAAM;AAC7B,eAAS;AAAA,QACP,OAAO,MAAM;AAAA,QACb,MAAM,MAAM;AAAA,MACd,CAAC;AAAA,IACH;AAAA,EACF,GAAG,CAAC,MAAM,OAAO,MAAM,IAAI,CAAC;AAE5B,SAAO;AACT;","names":["name"]}
|
package/dist/react/index.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { useEffect } from "react";
|
|
|
5
5
|
|
|
6
6
|
// package.json
|
|
7
7
|
var name = "@vercel/analytics";
|
|
8
|
-
var version = "1.2.0
|
|
8
|
+
var version = "1.2.0";
|
|
9
9
|
|
|
10
10
|
// src/queue.ts
|
|
11
11
|
var initQueue = () => {
|
|
@@ -145,10 +145,11 @@ function track(name2, properties) {
|
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
|
-
function pageview({ route }) {
|
|
148
|
+
function pageview({ route, path }) {
|
|
149
149
|
var _a;
|
|
150
150
|
(_a = window.va) == null ? void 0 : _a.call(window, "pageview", {
|
|
151
|
-
route
|
|
151
|
+
route,
|
|
152
|
+
path
|
|
152
153
|
});
|
|
153
154
|
}
|
|
154
155
|
|
|
@@ -160,11 +161,12 @@ function Analytics(props) {
|
|
|
160
161
|
...props.route !== void 0 && { disableAutoTrack: true },
|
|
161
162
|
...props
|
|
162
163
|
});
|
|
163
|
-
}, [
|
|
164
|
+
}, []);
|
|
164
165
|
useEffect(() => {
|
|
165
|
-
if (props.route) {
|
|
166
|
+
if (props.route && props.path) {
|
|
166
167
|
pageview({
|
|
167
|
-
route: props.route
|
|
168
|
+
route: props.route,
|
|
169
|
+
path: props.path
|
|
168
170
|
});
|
|
169
171
|
}
|
|
170
172
|
}, [props.route, props.path]);
|
package/dist/react/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/react.tsx","../../package.json","../../src/queue.ts","../../src/utils.ts","../../src/generic.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport { inject, track, pageview } from './generic';\nimport type { AnalyticsProps } from './types';\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 path?: string | null;\n }\n): null {\n useEffect(() => {\n inject({\n framework: props.framework || 'react',\n ...(props.route !== undefined && { disableAutoTrack: true }),\n ...props,\n });\n }, [props]);\n\n useEffect(() => {\n if (props.route) {\n pageview({\n route: props.route,\n });\n }\n }, [props.route, props.path]);\n\n return null;\n}\n\nexport { track, Analytics };\nexport type { AnalyticsProps };\n","{\n \"name\": \"@vercel/analytics\",\n \"version\": \"1.2.0-beta.3\",\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.js\",\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n },\n \"./react\": {\n \"browser\": \"./dist/react/index.js\",\n \"import\": \"./dist/react/index.js\",\n \"require\": \"./dist/react/index.cjs\"\n },\n \"./next\": {\n \"browser\": \"./dist/next/index.mjs\",\n \"import\": \"./dist/next/index.mjs\",\n \"require\": \"./dist/next/index.js\"\n },\n \"./server\": {\n \"node\": \"./dist/server/index.js\",\n \"edge-light\": \"./dist/server/index.js\",\n \"import\": \"./dist/server/index.js\",\n \"require\": \"./dist/server/index.cjs\",\n \"default\": \"./dist/server/index.cjs\"\n }\n },\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"typesVersions\": {\n \"*\": {\n \"*\": [\n \"dist/index.d.ts\"\n ],\n \"react\": [\n \"dist/react/index.d.ts\"\n ],\n \"server\": [\n \"dist/server/index.d.ts\"\n ],\n \"next\": [\n \"dist/next/index.d.ts\"\n ]\n }\n },\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"lint\": \"eslint .\",\n \"lint-fix\": \"eslint . --fix\",\n \"test\": \"jest\",\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 \"dependencies\": {\n \"server-only\": \"^0.0.1\"\n },\n \"devDependencies\": {\n \"@swc/core\": \"^1.3.66\",\n \"@swc/jest\": \"^0.2.26\",\n \"@testing-library/jest-dom\": \"^5.16.5\",\n \"@testing-library/react\": \"^14.0.0\",\n \"@types/jest\": \"^29.5.2\",\n \"@types/node\": \"^20.3.1\",\n \"@types/react\": \"^18.2.14\",\n \"@types/testing-library__jest-dom\": \"^5.14.6\",\n \"@vercel/eslint-config\": \"workspace:0.0.0\",\n \"jest\": \"^29.5.0\",\n \"jest-environment-jsdom\": \"^29.5.0\",\n \"react\": \"^18.2.0\",\n \"react-dom\": \"^18.2.0\",\n \"tsup\": \"7.1.0\"\n },\n \"peerDependencies\": {\n \"next\": \">= 13\",\n \"react\": \"^18 || ^19\"\n },\n \"peerDependenciesMeta\": {\n \"next\": {\n \"optional\": true\n },\n \"react\": {\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, 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\n try {\n for (const [key, valueOrArray] of Object.entries(pathParams)) {\n const isValueArray = Array.isArray(valueOrArray);\n const value = isValueArray ? valueOrArray.join('/') : valueOrArray;\n const expr = isValueArray ? `...${key}` : key;\n\n const matcher = new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[${expr}]`);\n }\n }\n\n return result;\n } catch (e) {\n return pathname;\n }\n}\n\nfunction escapeRegExp(string: string): string {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n","import { name as packageName, version } from '../package.json';\nimport { initQueue } from './queue';\nimport type { AllowedPropertyValues, AnalyticsProps } from './types';\nimport {\n isBrowser,\n parseProperties,\n setMode,\n isDevelopment,\n isProduction,\n} from './utils';\n\nexport const DEV_SCRIPT_URL =\n 'https://va.vercel-scripts.com/v1/script.debug.js';\nexport const PROD_SCRIPT_URL = '/_vercel/insights/script.js';\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 */\nfunction inject(\n props: AnalyticsProps & {\n framework?: 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 =\n props.scriptSrc || (isDevelopment() ? DEV_SCRIPT_URL : PROD_SCRIPT_URL);\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 }\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): 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 });\n return;\n }\n\n try {\n const props = parseProperties(properties, {\n strip: isProduction(),\n });\n\n window.va?.('event', {\n name,\n data: props,\n });\n } catch (err) {\n if (err instanceof Error && isDevelopment()) {\n // eslint-disable-next-line no-console -- Logging to console is intentional\n console.error(err);\n }\n }\n}\n\nfunction pageview({ route }: { route?: string }): void {\n window.va?.('pageview', {\n route,\n });\n}\n\nexport { inject, track, pageview };\nexport type { AnalyticsProps };\n\n// eslint-disable-next-line import/no-default-export -- Default export is intentional\nexport default {\n inject,\n track,\n};\n"],"mappings":";;;AAAA,SAAS,iBAAiB;;;ACCxB,WAAQ;AACR,cAAW;;;ACFN,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO;AAAI;AAEf,SAAO,KAAK,SAAS,KAAK,QAAc;AACtC,KAAC,OAAO,MAAM,OAAO,OAAO,CAAC,GAAG,KAAK,MAAM;AAAA,EAC7C;AACF;;;ACLO,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;AAEA,SAAS,oBAAkD;AACzD,MAAI;AACF,UAAM,MAAM,QAAQ,IAAI;AACxB,QAAI,QAAQ,iBAAiB,QAAQ,QAAQ;AAC3C,aAAO;AAAA,IACT;AAAA,EACF,SAAS,GAAP;AAAA,EAEF;AACA,SAAO;AACT;AAEO,SAAS,QAAQ,OAAa,QAAc;AACjD,MAAI,SAAS,QAAQ;AACnB,WAAO,MAAM,kBAAkB;AAC/B;AAAA,EACF;AAEA,SAAO,MAAM;AACf;AAEO,SAAS,UAAgB;AAC9B,QAAM,OAAO,UAAU,IAAI,OAAO,MAAM,kBAAkB;AAC1D,SAAO,QAAQ;AACjB;AAEO,SAAS,eAAwB;AACtC,SAAO,QAAQ,MAAM;AACvB;AAEO,SAAS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,CAAC;AAAA,EACH,GAAG,CAAC,KAAK,CAAC;AAEV,YAAU,MAAM;AACd,QAAI,MAAM,OAAO;AACf,eAAS;AAAA,QACP,OAAO,MAAM;AAAA,MACf,CAAC;AAAA,IACH;AAAA,EACF,GAAG,CAAC,MAAM,OAAO,MAAM,IAAI,CAAC;AAE5B,SAAO;AACT;","names":["name"]}
|
|
1
|
+
{"version":3,"sources":["../../src/react.tsx","../../package.json","../../src/queue.ts","../../src/utils.ts","../../src/generic.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport { inject, track, pageview } from './generic';\nimport type { AnalyticsProps } from './types';\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 path?: string | null;\n }\n): null {\n useEffect(() => {\n inject({\n framework: props.framework || 'react',\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 if (props.route && props.path) {\n pageview({\n route: props.route,\n path: props.path,\n });\n }\n }, [props.route, props.path]);\n\n return null;\n}\n\nexport { track, Analytics };\nexport type { AnalyticsProps };\n","{\n \"name\": \"@vercel/analytics\",\n \"version\": \"1.2.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.js\",\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n },\n \"./react\": {\n \"browser\": \"./dist/react/index.js\",\n \"import\": \"./dist/react/index.js\",\n \"require\": \"./dist/react/index.cjs\"\n },\n \"./next\": {\n \"browser\": \"./dist/next/index.mjs\",\n \"import\": \"./dist/next/index.mjs\",\n \"require\": \"./dist/next/index.js\"\n },\n \"./server\": {\n \"node\": \"./dist/server/index.js\",\n \"edge-light\": \"./dist/server/index.js\",\n \"import\": \"./dist/server/index.js\",\n \"require\": \"./dist/server/index.cjs\",\n \"default\": \"./dist/server/index.cjs\"\n }\n },\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"typesVersions\": {\n \"*\": {\n \"*\": [\n \"dist/index.d.ts\"\n ],\n \"react\": [\n \"dist/react/index.d.ts\"\n ],\n \"server\": [\n \"dist/server/index.d.ts\"\n ],\n \"next\": [\n \"dist/next/index.d.ts\"\n ]\n }\n },\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"lint\": \"eslint .\",\n \"lint-fix\": \"eslint . --fix\",\n \"test\": \"jest\",\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 \"dependencies\": {\n \"server-only\": \"^0.0.1\"\n },\n \"devDependencies\": {\n \"@swc/core\": \"^1.3.66\",\n \"@swc/jest\": \"^0.2.26\",\n \"@testing-library/jest-dom\": \"^5.16.5\",\n \"@testing-library/react\": \"^14.0.0\",\n \"@types/jest\": \"^29.5.2\",\n \"@types/node\": \"^20.3.1\",\n \"@types/react\": \"^18.2.14\",\n \"@types/testing-library__jest-dom\": \"^5.14.6\",\n \"@vercel/eslint-config\": \"workspace:0.0.0\",\n \"jest\": \"^29.5.0\",\n \"jest-environment-jsdom\": \"^29.5.0\",\n \"react\": \"^18.2.0\",\n \"react-dom\": \"^18.2.0\",\n \"tsup\": \"7.1.0\"\n },\n \"peerDependencies\": {\n \"next\": \">= 13\",\n \"react\": \"^18 || ^19\"\n },\n \"peerDependenciesMeta\": {\n \"next\": {\n \"optional\": true\n },\n \"react\": {\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, 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\n try {\n for (const [key, valueOrArray] of Object.entries(pathParams)) {\n const isValueArray = Array.isArray(valueOrArray);\n const value = isValueArray ? valueOrArray.join('/') : valueOrArray;\n const expr = isValueArray ? `...${key}` : key;\n\n const matcher = new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[${expr}]`);\n }\n }\n\n return result;\n } catch (e) {\n return pathname;\n }\n}\n\nfunction escapeRegExp(string: string): string {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n","import { name as packageName, version } from '../package.json';\nimport { initQueue } from './queue';\nimport type { AllowedPropertyValues, AnalyticsProps } from './types';\nimport {\n isBrowser,\n parseProperties,\n setMode,\n isDevelopment,\n isProduction,\n} from './utils';\n\nexport const DEV_SCRIPT_URL =\n 'https://va.vercel-scripts.com/v1/script.debug.js';\nexport const PROD_SCRIPT_URL = '/_vercel/insights/script.js';\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 */\nfunction inject(\n props: AnalyticsProps & {\n framework?: 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 =\n props.scriptSrc || (isDevelopment() ? DEV_SCRIPT_URL : PROD_SCRIPT_URL);\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 }\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): 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 });\n return;\n }\n\n try {\n const props = parseProperties(properties, {\n strip: isProduction(),\n });\n\n window.va?.('event', {\n name,\n data: props,\n });\n } catch (err) {\n if (err instanceof Error && isDevelopment()) {\n // eslint-disable-next-line no-console -- Logging to console is intentional\n console.error(err);\n }\n }\n}\n\nfunction pageview({ route, path }: { route?: string; path?: string }): void {\n window.va?.('pageview', {\n route,\n path,\n });\n}\n\nexport { inject, track, pageview };\nexport type { AnalyticsProps };\n\n// eslint-disable-next-line import/no-default-export -- Default export is intentional\nexport default {\n inject,\n track,\n};\n"],"mappings":";;;AAAA,SAAS,iBAAiB;;;ACCxB,WAAQ;AACR,cAAW;;;ACFN,IAAM,YAAY,MAAY;AAEnC,MAAI,OAAO;AAAI;AAEf,SAAO,KAAK,SAAS,KAAK,QAAc;AACtC,KAAC,OAAO,MAAM,OAAO,OAAO,CAAC,GAAG,KAAK,MAAM;AAAA,EAC7C;AACF;;;ACLO,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;AAEA,SAAS,oBAAkD;AACzD,MAAI;AACF,UAAM,MAAM,QAAQ,IAAI;AACxB,QAAI,QAAQ,iBAAiB,QAAQ,QAAQ;AAC3C,aAAO;AAAA,IACT;AAAA,EACF,SAAS,GAAP;AAAA,EAEF;AACA,SAAO;AACT;AAEO,SAAS,QAAQ,OAAa,QAAc;AACjD,MAAI,SAAS,QAAQ;AACnB,WAAO,MAAM,kBAAkB;AAC/B;AAAA,EACF;AAEA,SAAO,MAAM;AACf;AAEO,SAAS,UAAgB;AAC9B,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,GACK;AACzB,SAAO;AACT;AAEO,SAAS,gBACd,YACA,SAG2D;AAC3D,MAAI,CAAC;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,CAAC;AAAA,IACH;AAAA,EACF,GAAG,CAAC,MAAM,OAAO,MAAM,IAAI,CAAC;AAE5B,SAAO;AACT;","names":["name"]}
|
package/dist/server/index.js
CHANGED
|
@@ -82,8 +82,9 @@ var symbol = Symbol.for("@vercel/request-context");
|
|
|
82
82
|
var logPrefix = "[Vercel Web Analytics]";
|
|
83
83
|
async function track(eventName, properties, context) {
|
|
84
84
|
var _a;
|
|
85
|
-
const ENDPOINT = process.env.
|
|
85
|
+
const ENDPOINT = process.env.VERCEL_WEB_ANALYTICS_ENDPOINT || process.env.VERCEL_URL;
|
|
86
86
|
const DISABLE_LOGS = Boolean(process.env.VERCEL_WEB_ANALYTICS_DISABLE_LOGS);
|
|
87
|
+
const BYPASS_SECRET = process.env.VERCEL_AUTOMATION_BYPASS_SECRET;
|
|
87
88
|
if (typeof window !== "undefined") {
|
|
88
89
|
if (!isProduction()) {
|
|
89
90
|
throw new Error(
|
|
@@ -151,11 +152,12 @@ async function track(eventName, properties, context) {
|
|
|
151
152
|
cookie: tmp.cookie
|
|
152
153
|
} : {
|
|
153
154
|
"x-va-server": "2"
|
|
154
|
-
}
|
|
155
|
+
},
|
|
156
|
+
...BYPASS_SECRET ? { "x-vercel-protection-bypass": BYPASS_SECRET } : {}
|
|
155
157
|
},
|
|
156
158
|
body: JSON.stringify(body),
|
|
157
159
|
method: "POST"
|
|
158
|
-
}).catch((err) => {
|
|
160
|
+
}).then((response) => response.text()).catch((err) => {
|
|
159
161
|
if (err instanceof Error && "response" in err) {
|
|
160
162
|
console.error(err.response);
|
|
161
163
|
} else {
|
package/dist/server/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/server/index.ts","../../src/utils.ts"],"sourcesContent":["/* eslint-disable no-console -- Allow logging on the server */\nimport type { AllowedPropertyValues } from '../types';\nimport { isProduction, parseProperties } from '../utils';\n\ntype HeadersObject = Record<string, string | string[] | undefined>;\ntype AllowedHeaders = Headers | HeadersObject;\n\nfunction isHeaders(headers?: AllowedHeaders): headers is Headers {\n if (!headers) return false;\n return typeof (headers as HeadersObject).entries === 'function';\n}\n\ninterface ContextWithRequest {\n request: { headers: AllowedHeaders };\n}\ninterface ContextWithHeaders {\n headers: AllowedHeaders;\n}\n\ntype Context = ContextWithRequest | ContextWithHeaders;\n\ninterface RequestContext {\n get: () => {\n headers: Record<string, string | undefined>;\n url: string;\n waitUntil?: (promise: Promise<unknown>) => void;\n };\n}\n\nconst symbol = Symbol.for('@vercel/request-context');\nconst logPrefix = '[Vercel Web Analytics]';\n\nexport async function track(\n eventName: string,\n properties?: Record<string, AllowedPropertyValues>,\n context?: Context\n): Promise<void> {\n const ENDPOINT = process.env.VERCEL_URL || process.env.VERCEL_ANALYTICS_URL;\n const DISABLE_LOGS = Boolean(process.env.VERCEL_WEB_ANALYTICS_DISABLE_LOGS);\n if (typeof window !== 'undefined') {\n if (!isProduction()) {\n throw new Error(\n `${logPrefix} It seems like you imported the \\`track\\` function from \\`@vercel/web-analytics/server\\` in a browser environment. This function is only meant to be used in a server environment.`\n );\n }\n\n return;\n }\n\n const props = parseProperties(properties, {\n strip: isProduction(),\n });\n\n if (!ENDPOINT) {\n if (isProduction()) {\n console.log(\n `${logPrefix} Can't find VERCEL_URL in environment variables.`\n );\n } else if (!DISABLE_LOGS) {\n console.log(\n `${logPrefix} Track \"${eventName}\" ${\n props ? `with data ${JSON.stringify(props)}` : ''\n }`\n );\n }\n return;\n }\n try {\n const requestContext = (\n (globalThis as never)[symbol] as RequestContext | undefined\n )?.get();\n\n let headers: AllowedHeaders | undefined;\n\n if (context && 'headers' in context) {\n headers = context.headers;\n } else if (context?.request) {\n headers = context.request.headers;\n } else if (requestContext?.headers) {\n // not explicitly passed in context, so take it from async storage\n headers = requestContext.headers;\n }\n\n let tmp: HeadersObject = {};\n if (headers && isHeaders(headers)) {\n headers.forEach((value, key) => {\n tmp[key] = value;\n });\n } else if (headers) {\n tmp = headers;\n }\n\n const origin =\n requestContext?.url || (tmp.referer as string) || `https://${ENDPOINT}`;\n\n const url = new URL(origin);\n\n const body = {\n o: origin,\n ts: new Date().getTime(),\n r: '',\n en: eventName,\n ed: props,\n };\n\n const hasHeaders = Boolean(headers);\n\n if (!hasHeaders) {\n throw new Error(\n 'No session context found. Pass `request` or `headers` to the `track` function.'\n );\n }\n\n const promise = fetch(`${url.origin}/_vercel/insights/event`, {\n headers: {\n 'content-type': 'application/json',\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- The throwing is temporary until we add support for non Vercel hosted environments\n ...(hasHeaders\n ? {\n 'user-agent': tmp['user-agent'] as string,\n 'x-vercel-ip': tmp['x-forwarded-for'] as string,\n 'x-va-server': '1',\n cookie: tmp.cookie as string,\n }\n : {\n 'x-va-server': '2',\n }),\n },\n body: JSON.stringify(body),\n method: 'POST',\n }).catch((err: unknown) => {\n if (err instanceof Error && 'response' in err) {\n console.error(err.response);\n } else {\n console.error(err);\n }\n });\n\n if (requestContext?.waitUntil) {\n requestContext.waitUntil(promise);\n } else {\n await promise;\n }\n\n return void 0;\n } catch (err) {\n console.error(err);\n }\n}\n","import type { AllowedPropertyValues, Mode } from './types';\n\nexport function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nfunction detectEnvironment(): 'development' | 'production' {\n try {\n const env = process.env.NODE_ENV;\n if (env === 'development' || env === 'test') {\n return 'development';\n }\n } catch (e) {\n // do nothing, this is okay\n }\n return 'production';\n}\n\nexport function setMode(mode: Mode = 'auto'): void {\n if (mode === 'auto') {\n window.vam = detectEnvironment();\n return;\n }\n\n window.vam = mode;\n}\n\nexport function getMode(): Mode {\n 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\n try {\n for (const [key, valueOrArray] of Object.entries(pathParams)) {\n const isValueArray = Array.isArray(valueOrArray);\n const value = isValueArray ? valueOrArray.join('/') : valueOrArray;\n const expr = isValueArray ? `...${key}` : key;\n\n const matcher = new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[${expr}]`);\n }\n }\n\n return result;\n } catch (e) {\n return pathname;\n }\n}\n\nfunction escapeRegExp(string: string): string {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;AAEA,SAAS,oBAAkD;AACzD,MAAI;AACF,UAAM,MAAM,QAAQ,IAAI;AACxB,QAAI,QAAQ,iBAAiB,QAAQ,QAAQ;AAC3C,aAAO;AAAA,IACT;AAAA,EACF,SAAS,GAAP;AAAA,EAEF;AACA,SAAO;AACT;AAWO,SAAS,UAAgB;AAC9B,QAAM,OAAO,UAAU,IAAI,OAAO,MAAM,kBAAkB;AAC1D,SAAO,QAAQ;AACjB;AAEO,SAAS,eAAwB;AACtC,SAAO,QAAQ,MA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AU,IAAI;AAAA,MACzB,QAAQ;AAAA,IACV,CAAC,EAAE,MAAM,CAAC,QAAiB;AACzB,UAAI,eAAe,SAAS,cAAc,KAAK;AAC7C,gBAAQ,MAAM,IAAI,QAAQ;AAAA,MAC5B,OAAO;AACL,gBAAQ,MAAM,GAAG;AAAA,MACnB;AAAA,IACF,CAAC;AAED,QAAI,iDAAgB,WAAW;AAC7B,qBAAe,UAAU,OAAO;AAAA,IAClC,OAAO;AACL,YAAM;AAAA,IACR;AAEA,WAAO;AAAA,EACT,SAAS,KAAP;AACA,YAAQ,MAAM,GAAG;AAAA,EACnB;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/server/index.ts","../../src/utils.ts"],"sourcesContent":["/* eslint-disable no-console -- Allow logging on the server */\nimport type { AllowedPropertyValues } from '../types';\nimport { isProduction, parseProperties } from '../utils';\n\ntype HeadersObject = Record<string, string | string[] | undefined>;\ntype AllowedHeaders = Headers | HeadersObject;\n\nfunction isHeaders(headers?: AllowedHeaders): headers is Headers {\n if (!headers) return false;\n return typeof (headers as HeadersObject).entries === 'function';\n}\n\ninterface ContextWithRequest {\n request: { headers: AllowedHeaders };\n}\ninterface ContextWithHeaders {\n headers: AllowedHeaders;\n}\n\ntype Context = ContextWithRequest | ContextWithHeaders;\n\ninterface RequestContext {\n get: () => {\n headers: Record<string, string | undefined>;\n url: string;\n waitUntil?: (promise: Promise<unknown>) => void;\n };\n}\n\nconst symbol = Symbol.for('@vercel/request-context');\nconst logPrefix = '[Vercel Web Analytics]';\n\nexport async function track(\n eventName: string,\n properties?: Record<string, AllowedPropertyValues>,\n context?: Context\n): Promise<void> {\n const ENDPOINT =\n process.env.VERCEL_WEB_ANALYTICS_ENDPOINT || process.env.VERCEL_URL;\n const DISABLE_LOGS = Boolean(process.env.VERCEL_WEB_ANALYTICS_DISABLE_LOGS);\n const BYPASS_SECRET = process.env.VERCEL_AUTOMATION_BYPASS_SECRET;\n\n if (typeof window !== 'undefined') {\n if (!isProduction()) {\n throw new Error(\n `${logPrefix} It seems like you imported the \\`track\\` function from \\`@vercel/web-analytics/server\\` in a browser environment. This function is only meant to be used in a server environment.`\n );\n }\n\n return;\n }\n\n const props = parseProperties(properties, {\n strip: isProduction(),\n });\n\n if (!ENDPOINT) {\n if (isProduction()) {\n console.log(\n `${logPrefix} Can't find VERCEL_URL in environment variables.`\n );\n } else if (!DISABLE_LOGS) {\n console.log(\n `${logPrefix} Track \"${eventName}\" ${\n props ? `with data ${JSON.stringify(props)}` : ''\n }`\n );\n }\n return;\n }\n try {\n const requestContext = (\n (globalThis as never)[symbol] as RequestContext | undefined\n )?.get();\n\n let headers: AllowedHeaders | undefined;\n\n if (context && 'headers' in context) {\n headers = context.headers;\n } else if (context?.request) {\n headers = context.request.headers;\n } else if (requestContext?.headers) {\n // not explicitly passed in context, so take it from async storage\n headers = requestContext.headers;\n }\n\n let tmp: HeadersObject = {};\n if (headers && isHeaders(headers)) {\n headers.forEach((value, key) => {\n tmp[key] = value;\n });\n } else if (headers) {\n tmp = headers;\n }\n\n const origin =\n requestContext?.url || (tmp.referer as string) || `https://${ENDPOINT}`;\n\n const url = new URL(origin);\n\n const body = {\n o: origin,\n ts: new Date().getTime(),\n r: '',\n en: eventName,\n ed: props,\n };\n\n const hasHeaders = Boolean(headers);\n\n if (!hasHeaders) {\n throw new Error(\n 'No session context found. Pass `request` or `headers` to the `track` function.'\n );\n }\n\n const promise = fetch(`${url.origin}/_vercel/insights/event`, {\n headers: {\n 'content-type': 'application/json',\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- The throwing is temporary until we add support for non Vercel hosted environments\n ...(hasHeaders\n ? {\n 'user-agent': tmp['user-agent'] as string,\n 'x-vercel-ip': tmp['x-forwarded-for'] as string,\n 'x-va-server': '1',\n cookie: tmp.cookie as string,\n }\n : {\n 'x-va-server': '2',\n }),\n ...(BYPASS_SECRET\n ? { 'x-vercel-protection-bypass': BYPASS_SECRET }\n : {}),\n },\n body: JSON.stringify(body),\n method: 'POST',\n })\n // We want to always consume to body; some cloud providers track fetch concurrency\n // and may not release the connection until the body is consumed.\n .then((response) => response.text())\n .catch((err: unknown) => {\n if (err instanceof Error && 'response' in err) {\n console.error(err.response);\n } else {\n console.error(err);\n }\n });\n\n if (requestContext?.waitUntil) {\n requestContext.waitUntil(promise);\n } else {\n await promise;\n }\n\n return void 0;\n } catch (err) {\n console.error(err);\n }\n}\n","import type { AllowedPropertyValues, Mode } from './types';\n\nexport function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nfunction detectEnvironment(): 'development' | 'production' {\n try {\n const env = process.env.NODE_ENV;\n if (env === 'development' || env === 'test') {\n return 'development';\n }\n } catch (e) {\n // do nothing, this is okay\n }\n return 'production';\n}\n\nexport function setMode(mode: Mode = 'auto'): void {\n if (mode === 'auto') {\n window.vam = detectEnvironment();\n return;\n }\n\n window.vam = mode;\n}\n\nexport function getMode(): Mode {\n 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\n try {\n for (const [key, valueOrArray] of Object.entries(pathParams)) {\n const isValueArray = Array.isArray(valueOrArray);\n const value = isValueArray ? valueOrArray.join('/') : valueOrArray;\n const expr = isValueArray ? `...${key}` : key;\n\n const matcher = new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[${expr}]`);\n }\n }\n\n return result;\n } catch (e) {\n return pathname;\n }\n}\n\nfunction escapeRegExp(string: string): string {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;AAEA,SAAS,oBAAkD;AACzD,MAAI;AACF,UAAM,MAAM,QAAQ,IAAI;AACxB,QAAI,QAAQ,iBAAiB,QAAQ,QAAQ;AAC3C,aAAO;AAAA,IACT;AAAA,EACF,SAAS,GAAP;AAAA,EAEF;AACA,SAAO;AACT;AAWO,SAAS,UAAgB;AAC9B,QAAM,OAAO,UAAU,IAAI,OAAO,MAAM,kBAAkB;AAC1D,SAAO,QAAQ;AACjB;AAEO,SAAS,eAAwB;AACtC,SAAO,QAAQ,MAAM;AACvB;AAMA,SAAS,UACP,KACA,EAAE,CAAC,GAAG,GAAG,GAAG,GAAG,KAAK,GACK;AACzB,SAAO;AACT;AAEO,SAAS,gBACd,YACA,SAG2D;AAC3D,MAAI,CAAC;AAAY,WAAO;AACxB,MAAI,QAAQ;AACZ,QAAM,kBAA4B,CAAC;AACnC,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,UAAU,GAAG;AACrD,QAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,UAAI,QAAQ,OAAO;AACjB,gBAAQ,UAAU,KAAK,KAAK;AAAA,MAC9B,OAAO;AACL,wBAAgB,KAAK,GAAG;AAAA,MAC1B;AAAA,IACF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M;AAAA,IACR;AAEA,WAAO;AAAA,EACT,SAAS,KAAP;AACA,YAAQ,MAAM,GAAG;AAAA,EACnB;AACF;","names":[]}
|
package/dist/server/index.mjs
CHANGED
|
@@ -56,8 +56,9 @@ var symbol = Symbol.for("@vercel/request-context");
|
|
|
56
56
|
var logPrefix = "[Vercel Web Analytics]";
|
|
57
57
|
async function track(eventName, properties, context) {
|
|
58
58
|
var _a;
|
|
59
|
-
const ENDPOINT = process.env.
|
|
59
|
+
const ENDPOINT = process.env.VERCEL_WEB_ANALYTICS_ENDPOINT || process.env.VERCEL_URL;
|
|
60
60
|
const DISABLE_LOGS = Boolean(process.env.VERCEL_WEB_ANALYTICS_DISABLE_LOGS);
|
|
61
|
+
const BYPASS_SECRET = process.env.VERCEL_AUTOMATION_BYPASS_SECRET;
|
|
61
62
|
if (typeof window !== "undefined") {
|
|
62
63
|
if (!isProduction()) {
|
|
63
64
|
throw new Error(
|
|
@@ -125,11 +126,12 @@ async function track(eventName, properties, context) {
|
|
|
125
126
|
cookie: tmp.cookie
|
|
126
127
|
} : {
|
|
127
128
|
"x-va-server": "2"
|
|
128
|
-
}
|
|
129
|
+
},
|
|
130
|
+
...BYPASS_SECRET ? { "x-vercel-protection-bypass": BYPASS_SECRET } : {}
|
|
129
131
|
},
|
|
130
132
|
body: JSON.stringify(body),
|
|
131
133
|
method: "POST"
|
|
132
|
-
}).catch((err) => {
|
|
134
|
+
}).then((response) => response.text()).catch((err) => {
|
|
133
135
|
if (err instanceof Error && "response" in err) {
|
|
134
136
|
console.error(err.response);
|
|
135
137
|
} else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils.ts","../../src/server/index.ts"],"sourcesContent":["import type { AllowedPropertyValues, Mode } from './types';\n\nexport function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nfunction detectEnvironment(): 'development' | 'production' {\n try {\n const env = process.env.NODE_ENV;\n if (env === 'development' || env === 'test') {\n return 'development';\n }\n } catch (e) {\n // do nothing, this is okay\n }\n return 'production';\n}\n\nexport function setMode(mode: Mode = 'auto'): void {\n if (mode === 'auto') {\n window.vam = detectEnvironment();\n return;\n }\n\n window.vam = mode;\n}\n\nexport function getMode(): Mode {\n 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\n try {\n for (const [key, valueOrArray] of Object.entries(pathParams)) {\n const isValueArray = Array.isArray(valueOrArray);\n const value = isValueArray ? valueOrArray.join('/') : valueOrArray;\n const expr = isValueArray ? `...${key}` : key;\n\n const matcher = new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[${expr}]`);\n }\n }\n\n return result;\n } catch (e) {\n return pathname;\n }\n}\n\nfunction escapeRegExp(string: string): string {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n","/* eslint-disable no-console -- Allow logging on the server */\nimport type { AllowedPropertyValues } from '../types';\nimport { isProduction, parseProperties } from '../utils';\n\ntype HeadersObject = Record<string, string | string[] | undefined>;\ntype AllowedHeaders = Headers | HeadersObject;\n\nfunction isHeaders(headers?: AllowedHeaders): headers is Headers {\n if (!headers) return false;\n return typeof (headers as HeadersObject).entries === 'function';\n}\n\ninterface ContextWithRequest {\n request: { headers: AllowedHeaders };\n}\ninterface ContextWithHeaders {\n headers: AllowedHeaders;\n}\n\ntype Context = ContextWithRequest | ContextWithHeaders;\n\ninterface RequestContext {\n get: () => {\n headers: Record<string, string | undefined>;\n url: string;\n waitUntil?: (promise: Promise<unknown>) => void;\n };\n}\n\nconst symbol = Symbol.for('@vercel/request-context');\nconst logPrefix = '[Vercel Web Analytics]';\n\nexport async function track(\n eventName: string,\n properties?: Record<string, AllowedPropertyValues>,\n context?: Context\n): Promise<void> {\n const ENDPOINT = process.env.VERCEL_URL || process.env.VERCEL_ANALYTICS_URL;\n const DISABLE_LOGS = Boolean(process.env.VERCEL_WEB_ANALYTICS_DISABLE_LOGS);\n if (typeof window !== 'undefined') {\n if (!isProduction()) {\n throw new Error(\n `${logPrefix} It seems like you imported the \\`track\\` function from \\`@vercel/web-analytics/server\\` in a browser environment. This function is only meant to be used in a server environment.`\n );\n }\n\n return;\n }\n\n const props = parseProperties(properties, {\n strip: isProduction(),\n });\n\n if (!ENDPOINT) {\n if (isProduction()) {\n console.log(\n `${logPrefix} Can't find VERCEL_URL in environment variables.`\n );\n } else if (!DISABLE_LOGS) {\n console.log(\n `${logPrefix} Track \"${eventName}\" ${\n props ? `with data ${JSON.stringify(props)}` : ''\n }`\n );\n }\n return;\n }\n try {\n const requestContext = (\n (globalThis as never)[symbol] as RequestContext | undefined\n )?.get();\n\n let headers: AllowedHeaders | undefined;\n\n if (context && 'headers' in context) {\n headers = context.headers;\n } else if (context?.request) {\n headers = context.request.headers;\n } else if (requestContext?.headers) {\n // not explicitly passed in context, so take it from async storage\n headers = requestContext.headers;\n }\n\n let tmp: HeadersObject = {};\n if (headers && isHeaders(headers)) {\n headers.forEach((value, key) => {\n tmp[key] = value;\n });\n } else if (headers) {\n tmp = headers;\n }\n\n const origin =\n requestContext?.url || (tmp.referer as string) || `https://${ENDPOINT}`;\n\n const url = new URL(origin);\n\n const body = {\n o: origin,\n ts: new Date().getTime(),\n r: '',\n en: eventName,\n ed: props,\n };\n\n const hasHeaders = Boolean(headers);\n\n if (!hasHeaders) {\n throw new Error(\n 'No session context found. Pass `request` or `headers` to the `track` function.'\n );\n }\n\n const promise = fetch(`${url.origin}/_vercel/insights/event`, {\n headers: {\n 'content-type': 'application/json',\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- The throwing is temporary until we add support for non Vercel hosted environments\n ...(hasHeaders\n ? {\n 'user-agent': tmp['user-agent'] as string,\n 'x-vercel-ip': tmp['x-forwarded-for'] as string,\n 'x-va-server': '1',\n cookie: tmp.cookie as string,\n }\n : {\n 'x-va-server': '2',\n }),\n },\n body: JSON.stringify(body),\n method: 'POST',\n }).catch((err: unknown) => {\n if (err instanceof Error && 'response' in err) {\n console.error(err.response);\n } else {\n console.error(err);\n }\n });\n\n if (requestContext?.waitUntil) {\n requestContext.waitUntil(promise);\n } else {\n await promise;\n }\n\n return void 0;\n } catch (err) {\n console.error(err);\n }\n}\n"],"mappings":";AAEO,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;AAEA,SAAS,oBAAkD;AACzD,MAAI;AACF,UAAM,MAAM,QAAQ,IAAI;AACxB,QAAI,QAAQ,iBAAiB,QAAQ,QAAQ;AAC3C,aAAO;AAAA,IACT;AAAA,EACF,SAAS,GAAP;AAAA,EAEF;AACA,SAAO;AACT;AAWO,SAAS,UAAgB;AAC9B,QAAM,OAAO,UAAU,IAAI,OAAO,MAAM,kBAAkB;AAC1D,SAAO,QAAQ;AACjB;AAEO,SAAS,eAAwB;AACtC,SAAO,QAAQ,MAAM;AACvB;AAMA,SAAS,UACP,KACA,EAAE,CAAC,GAAG,GAAG,GAAG,GAAG,KAAK,GACK;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AAI,eAAe,SAAS,cAAc,KAAK;AAC7C,gBAAQ,MAAM,IAAI,QAAQ;AAAA,MAC5B,OAAO;AACL,gBAAQ,MAAM,GAAG;AAAA,MACnB;AAAA,IACF,CAAC;AAED,QAAI,iDAAgB,WAAW;AAC7B,qBAAe,UAAU,OAAO;AAAA,IAClC,OAAO;AACL,YAAM;AAAA,IACR;AAEA,WAAO;AAAA,EACT,SAAS,KAAP;AACA,YAAQ,MAAM,GAAG;AAAA,EACnB;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/utils.ts","../../src/server/index.ts"],"sourcesContent":["import type { AllowedPropertyValues, Mode } from './types';\n\nexport function isBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\nfunction detectEnvironment(): 'development' | 'production' {\n try {\n const env = process.env.NODE_ENV;\n if (env === 'development' || env === 'test') {\n return 'development';\n }\n } catch (e) {\n // do nothing, this is okay\n }\n return 'production';\n}\n\nexport function setMode(mode: Mode = 'auto'): void {\n if (mode === 'auto') {\n window.vam = detectEnvironment();\n return;\n }\n\n window.vam = mode;\n}\n\nexport function getMode(): Mode {\n 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\n try {\n for (const [key, valueOrArray] of Object.entries(pathParams)) {\n const isValueArray = Array.isArray(valueOrArray);\n const value = isValueArray ? valueOrArray.join('/') : valueOrArray;\n const expr = isValueArray ? `...${key}` : key;\n\n const matcher = new RegExp(`/${escapeRegExp(value)}(?=[/?#]|$)`);\n if (matcher.test(result)) {\n result = result.replace(matcher, `/[${expr}]`);\n }\n }\n\n return result;\n } catch (e) {\n return pathname;\n }\n}\n\nfunction escapeRegExp(string: string): string {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n","/* eslint-disable no-console -- Allow logging on the server */\nimport type { AllowedPropertyValues } from '../types';\nimport { isProduction, parseProperties } from '../utils';\n\ntype HeadersObject = Record<string, string | string[] | undefined>;\ntype AllowedHeaders = Headers | HeadersObject;\n\nfunction isHeaders(headers?: AllowedHeaders): headers is Headers {\n if (!headers) return false;\n return typeof (headers as HeadersObject).entries === 'function';\n}\n\ninterface ContextWithRequest {\n request: { headers: AllowedHeaders };\n}\ninterface ContextWithHeaders {\n headers: AllowedHeaders;\n}\n\ntype Context = ContextWithRequest | ContextWithHeaders;\n\ninterface RequestContext {\n get: () => {\n headers: Record<string, string | undefined>;\n url: string;\n waitUntil?: (promise: Promise<unknown>) => void;\n };\n}\n\nconst symbol = Symbol.for('@vercel/request-context');\nconst logPrefix = '[Vercel Web Analytics]';\n\nexport async function track(\n eventName: string,\n properties?: Record<string, AllowedPropertyValues>,\n context?: Context\n): Promise<void> {\n const ENDPOINT =\n process.env.VERCEL_WEB_ANALYTICS_ENDPOINT || process.env.VERCEL_URL;\n const DISABLE_LOGS = Boolean(process.env.VERCEL_WEB_ANALYTICS_DISABLE_LOGS);\n const BYPASS_SECRET = process.env.VERCEL_AUTOMATION_BYPASS_SECRET;\n\n if (typeof window !== 'undefined') {\n if (!isProduction()) {\n throw new Error(\n `${logPrefix} It seems like you imported the \\`track\\` function from \\`@vercel/web-analytics/server\\` in a browser environment. This function is only meant to be used in a server environment.`\n );\n }\n\n return;\n }\n\n const props = parseProperties(properties, {\n strip: isProduction(),\n });\n\n if (!ENDPOINT) {\n if (isProduction()) {\n console.log(\n `${logPrefix} Can't find VERCEL_URL in environment variables.`\n );\n } else if (!DISABLE_LOGS) {\n console.log(\n `${logPrefix} Track \"${eventName}\" ${\n props ? `with data ${JSON.stringify(props)}` : ''\n }`\n );\n }\n return;\n }\n try {\n const requestContext = (\n (globalThis as never)[symbol] as RequestContext | undefined\n )?.get();\n\n let headers: AllowedHeaders | undefined;\n\n if (context && 'headers' in context) {\n headers = context.headers;\n } else if (context?.request) {\n headers = context.request.headers;\n } else if (requestContext?.headers) {\n // not explicitly passed in context, so take it from async storage\n headers = requestContext.headers;\n }\n\n let tmp: HeadersObject = {};\n if (headers && isHeaders(headers)) {\n headers.forEach((value, key) => {\n tmp[key] = value;\n });\n } else if (headers) {\n tmp = headers;\n }\n\n const origin =\n requestContext?.url || (tmp.referer as string) || `https://${ENDPOINT}`;\n\n const url = new URL(origin);\n\n const body = {\n o: origin,\n ts: new Date().getTime(),\n r: '',\n en: eventName,\n ed: props,\n };\n\n const hasHeaders = Boolean(headers);\n\n if (!hasHeaders) {\n throw new Error(\n 'No session context found. Pass `request` or `headers` to the `track` function.'\n );\n }\n\n const promise = fetch(`${url.origin}/_vercel/insights/event`, {\n headers: {\n 'content-type': 'application/json',\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- The throwing is temporary until we add support for non Vercel hosted environments\n ...(hasHeaders\n ? {\n 'user-agent': tmp['user-agent'] as string,\n 'x-vercel-ip': tmp['x-forwarded-for'] as string,\n 'x-va-server': '1',\n cookie: tmp.cookie as string,\n }\n : {\n 'x-va-server': '2',\n }),\n ...(BYPASS_SECRET\n ? { 'x-vercel-protection-bypass': BYPASS_SECRET }\n : {}),\n },\n body: JSON.stringify(body),\n method: 'POST',\n })\n // We want to always consume to body; some cloud providers track fetch concurrency\n // and may not release the connection until the body is consumed.\n .then((response) => response.text())\n .catch((err: unknown) => {\n if (err instanceof Error && 'response' in err) {\n console.error(err.response);\n } else {\n console.error(err);\n }\n });\n\n if (requestContext?.waitUntil) {\n requestContext.waitUntil(promise);\n } else {\n await promise;\n }\n\n return void 0;\n } catch (err) {\n console.error(err);\n }\n}\n"],"mappings":";AAEO,SAAS,YAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;AAEA,SAAS,oBAAkD;AACzD,MAAI;AACF,UAAM,MAAM,QAAQ,IAAI;AACxB,QAAI,QAAQ,iBAAiB,QAAQ,QAAQ;AAC3C,aAAO;AAAA,IACT;AAAA,EACF,SAAS,GAAP;AAAA,EAEF;AACA,SAAO;AACT;AAWO,SAAS,UAAgB;AAC9B,QAAM,OAAO,UAAU,IAAI,OAAO,MAAM,kBAAkB;AAC1D,SAAO,QAAQ;AACjB;AAEO,SAAS,eAAwB;AACtC,SAAO,QAAQ,MAAM;AACvB;AAMA,SAAS,UACP,KACA,EAAE,CAAC,GAAG,GAAG,GAAG,GAAG,KAAK,GACK;AACzB,SAAO;AACT;AAEO,SAAS,gBACd,YACA,SAG2D;AAC3D,MAAI,CAAC;AAAY,WAAO;AACxB,MAAI,QAAQ;AACZ,QAAM,kBAA4B,CAAC;AACnC,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,UAAU,GAAG;AACrD,QAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,UAAI,QAAQ,OAAO;AACjB,gBAAQ,UAAU,KAAK,KAAK;AAAA,MAC9B,OAAO;AACL,wBAAgB,KAAK,GAAG;AAAA,MAC1B;AAAA,IACF;AAAA,EACF;AAEA,MAAI,gBAAgB,SAAS,KAAK,CAAC,QAAQ,OAAO;AAChD,UAAM;AAAA,MACJ,2CAA2C,gBAAgB;AAAA,QACzD;AAAA,MACF,CAAC;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