diff --git a/.changeset/calm-ties-burn.md b/.changeset/calm-ties-burn.md new file mode 100644 index 0000000000..26a8a6cd2a --- /dev/null +++ b/.changeset/calm-ties-burn.md @@ -0,0 +1,5 @@ +--- +"gitbook": patch +--- + +Fix missing geo data in site insights because of incorrect proxying of events. diff --git a/packages/gitbook/src/lib/tracking.ts b/packages/gitbook/src/lib/tracking.ts index 04d27accf4..541cb9a7cf 100644 --- a/packages/gitbook/src/lib/tracking.ts +++ b/packages/gitbook/src/lib/tracking.ts @@ -1,5 +1,5 @@ import type { headers as nextHeaders } from 'next/headers'; -import { GITBOOK_API_URL, GITBOOK_DISABLE_TRACKING } from './env'; +import { GITBOOK_API_PUBLIC_URL, GITBOOK_DISABLE_TRACKING } from './env'; /** * Return true if events should be tracked on the site. @@ -36,7 +36,9 @@ export async function serveProxyAnalyticsEvent(req: Request) { headers: { 'content-type': 'text/plain' }, }); } - const url = new URL(`${GITBOOK_API_URL}/v1/orgs/${org}/sites/${site}/insights/events`); + + // We make the request to the public API URL to ensure the request is properly enriched by the router.. + const url = new URL(`${GITBOOK_API_PUBLIC_URL}/v1/orgs/${org}/sites/${site}/insights/events`); return await fetch(url.toString(), { method: 'POST', headers: {