Skip to content

Commit

Permalink
Merge branch 'main' into tobiaslins/aly-1178-add-route-support-for-wa…
Browse files Browse the repository at this point in the history
…-dogfooding
  • Loading branch information
tobiaslins committed Feb 16, 2024
2 parents 0b83e9d + 8b1c58f commit bcdc694
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
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.2.0-beta.4",
"version": "1.2.0",
"description": "Gain real-time traffic insights with Vercel Web Analytics",
"keywords": [
"analytics",
Expand Down
26 changes: 18 additions & 8 deletions packages/web/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ export async function track(
properties?: Record<string, AllowedPropertyValues>,
context?: Context
): Promise<void> {
const ENDPOINT = process.env.VERCEL_URL || process.env.VERCEL_ANALYTICS_URL;
const ENDPOINT =
process.env.VERCEL_WEB_ANALYTICS_ENDPOINT || process.env.VERCEL_URL;
const DISABLE_LOGS = Boolean(process.env.VERCEL_WEB_ANALYTICS_DISABLE_LOGS);
const BYPASS_SECRET = process.env.VERCEL_AUTOMATION_BYPASS_SECRET;

if (typeof window !== 'undefined') {
if (!isProduction()) {
throw new Error(
Expand Down Expand Up @@ -125,16 +128,23 @@ export async function track(
: {
'x-va-server': '2',
}),
...(BYPASS_SECRET
? { 'x-vercel-protection-bypass': BYPASS_SECRET }
: {}),
},
body: JSON.stringify(body),
method: 'POST',
}).catch((err: unknown) => {
if (err instanceof Error && 'response' in err) {
console.error(err.response);
} else {
console.error(err);
}
});
})
// We want to always consume to body; some cloud providers track fetch concurrency
// and may not release the connection until the body is consumed.
.then((response) => response.text())
.catch((err: unknown) => {
if (err instanceof Error && 'response' in err) {
console.error(err.response);
} else {
console.error(err);
}
});

if (requestContext?.waitUntil) {
requestContext.waitUntil(promise);
Expand Down

0 comments on commit bcdc694

Please sign in to comment.