diff --git a/packages/web/package.json b/packages/web/package.json index ef95d31..4d17fbf 100644 --- a/packages/web/package.json +++ b/packages/web/package.json @@ -1,6 +1,6 @@ { "name": "@vercel/analytics", - "version": "1.4.0", + "version": "1.5.0-canary.1", "description": "Gain real-time traffic insights with Vercel Web Analytics", "keywords": [ "analytics", diff --git a/packages/web/src/generic.ts b/packages/web/src/generic.ts index 555ca86..509a387 100644 --- a/packages/web/src/generic.ts +++ b/packages/web/src/generic.ts @@ -20,6 +20,8 @@ export const DEV_SCRIPT_URL = 'https://va.vercel-scripts.com/v1/script.debug.js'; export const PROD_SCRIPT_URL = '/_vercel/insights/script.js'; +export const basepathVariableName = 'NEXT_PUBLIC_WEB_ANALYTICS_BASEPATH'; + /** * 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). * @param [props] - Analytics options. @@ -67,6 +69,8 @@ function inject( } if (props.endpoint) { script.dataset.endpoint = props.endpoint; + } else if (process.env[basepathVariableName]) { + script.dataset.endpoint = `/${process.env[basepathVariableName]}/_vercel/insights`; } if (props.dsn) { script.dataset.dsn = props.dsn;