Skip to content

Commit

Permalink
Add an option to prefix an endpoint path with an environment variable. (
Browse files Browse the repository at this point in the history
#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 <[email protected]>
  • Loading branch information
emspishak and feugy authored Nov 14, 2024
1 parent c09b649 commit 68d0d13
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/web/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 4 additions & 0 deletions packages/web/src/generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 68d0d13

Please sign in to comment.