Skip to content

Commit 68d0d13

Browse files
emspishakfeugy
andauthored
Add an option to prefix an endpoint path with an environment variable. (#153)
* Add an option to prefix an endpoint path with an environment variable. * prefiv environment variable with next_public_ so it gets inlined at build time * correct env name everywhere, and make more specific * chore: use correct name --------- Co-authored-by: feugy <damien@vercel.com>
1 parent c09b649 commit 68d0d13

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

packages/web/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@vercel/analytics",
3-
"version": "1.4.0",
3+
"version": "1.5.0-canary.1",
44
"description": "Gain real-time traffic insights with Vercel Web Analytics",
55
"keywords": [
66
"analytics",

packages/web/src/generic.ts

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export const DEV_SCRIPT_URL =
2020
'https://va.vercel-scripts.com/v1/script.debug.js';
2121
export const PROD_SCRIPT_URL = '/_vercel/insights/script.js';
2222

23+
export const basepathVariableName = 'NEXT_PUBLIC_WEB_ANALYTICS_BASEPATH';
24+
2325
/**
2426
* 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).
2527
* @param [props] - Analytics options.
@@ -67,6 +69,8 @@ function inject(
6769
}
6870
if (props.endpoint) {
6971
script.dataset.endpoint = props.endpoint;
72+
} else if (process.env[basepathVariableName]) {
73+
script.dataset.endpoint = `/${process.env[basepathVariableName]}/_vercel/insights`;
7074
}
7175
if (props.dsn) {
7276
script.dataset.dsn = props.dsn;

0 commit comments

Comments
 (0)