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
#85)

Co-authored-by: feugy <[email protected]>
  • Loading branch information
emspishak and feugy authored Nov 14, 2024
1 parent b5d2980 commit 5acf92b
Show file tree
Hide file tree
Showing 2 changed files with 4 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/speed-insights",
"version": "1.1.0",
"version": "1.2.0-canary.1",
"description": "Speed Insights is a tool for measuring web performance and providing suggestions for improvement.",
"keywords": [
"speed-insights",
Expand Down
3 changes: 3 additions & 0 deletions packages/web/src/generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const SCRIPT_URL = 'https://va.vercel-scripts.com/v1/speed-insights';
const PROD_SCRIPT_URL = `${SCRIPT_URL}/script.js`;
const DEV_SCRIPT_URL = `${SCRIPT_URL}/script.debug.js`;
const PROXY_SCRIPT_URL = '/_vercel/speed-insights/script.js';
const basepathVariableName = 'NEXT_PUBLIC_SPEED_INSIGHTS_BASEPATH';

/**
* Injects the Vercel Speed Insights script into the page head and starts tracking page views. Read more in our [documentation](https://vercel.com/docs/speed-insights).
Expand Down Expand Up @@ -57,6 +58,8 @@ function injectSpeedInsights(
}
if (props.endpoint) {
script.dataset.endpoint = props.endpoint;
} else if (process.env[basepathVariableName]) {
script.dataset.endpoint = `/${process.env[basepathVariableName]}/_vercel/speed-insights/vitals`;
}
if (props.dsn) {
script.dataset.dsn = props.dsn;
Expand Down

0 comments on commit 5acf92b

Please sign in to comment.