Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to prefix an endpoint path with an environment variable. #153

Merged
merged 5 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading