vercel / analytics

Privacy-friendly, real-time traffic insights
https://vercel.com/analytics
Mozilla Public License 2.0
422 stars 26 forks source link

projects with a basePath request the wrong url #59

Closed samuelcole closed 1 year ago

samuelcole commented 1 year ago

if i'm reading this line correctly: https://github.com/vercel/analytics/blob/5e3051aec49572a52b0688285a8349c6f5f51d0f/packages/web/src/generic.ts#L24

it does not consider the basePath of the vercel project, which results in 404s in my production application

image
tobiaslins commented 1 year ago

Hey @samuelcole! Have you enabled audiences in the dashboard for that domain? -> https://vercel.com/docs/concepts/analytics/audiences/quickstart

What's the basePath of your project?

Thanks!

samuelcole commented 1 year ago

so this app, directory has the basePath of /directory

foodhelpline.org is managed by another app, foodhelpline, which does not have analytics enabled at all. i would prefer not to have analytics enabled for both apps, but maybe you're saying it's required to have analytics enabled on the domain level as well as the project level?

tobiaslins commented 1 year ago

You could maybe add a rewrite to vercel.json or next.config.js that proxies /_vercel/insights/script.js to the subpath? Where is you're project with basePath accessible?

gsheppard commented 1 year ago

This is an issue for my team as well. We have basePath: '/collection', but <Analytics /> requests /_vercel/insights/script.js, not /collection/_vercel/insights/script.js.

We fixed it by proxying all /_vercel traffic to the appropriate app, but that is configured externally.

What is interesting though is that it is available under /collection/_vercel, it's just not being requested there.

gsheppard commented 1 year ago

Have there been any updates to this? We're about to be expanding into more of a multi-tenant setup and can't have the Vercel Analytics script loading from the same /_vercel route for 3 applications.

tobiaslins commented 1 year ago

Hey @gsheppard !

You can use the HTML integration to inject the script with a custom path + custom endpoint (instead of using inject or <Analytics />

For example:

<script data-endpoint="/blog/_vercel/insights" src="/blog/_vercel/insights/script.js" defer></script>

We will add support for the package later on.

Let me know if that helps!