vercel / analytics

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

Nextjs Optional Catch-All route at the Root level is intercepting `_vercel/insights/script.js` #58

Closed Saeris closed 1 year ago

Saeris commented 1 year ago

As the title suggests, when using an Optional Catch-All route (pages/[[,,,sllug]].tsx), network requests for _vercel/insights/script.js are unexpectedly intercepted by the dynamic route handler, resulting in this script not loading on the page.

Here is an example sandbox reproduction:

https://codesandbox.io/p/sandbox/empty-microservice-0li06m?file=%2FREADME.md&selection=%5B%7B%22endColumn%22%3A136%2C%22endLineNumber%22%3A11%2C%22startColumn%22%3A136%2C%22startLineNumber%22%3A11%7D%5D

Please follow along with the readme there for instructions to view this error in your browser.

If there is a workaround for this category of errors with optional catch-all routes, it would be excellent if the docs included more information on how to handle this situation. I can open an issue in the Nextjs repo instead if that would be a better place for this.

nautilytics commented 1 year ago

We are having this same issue. We have basePath defined in our Next.js app, so we would expect _vercel/insights/script.js to live at /base/path/_vercel/insights/script.js but instead it lives at the root which is routed to a different endpoint by our dynamic router handler.

tobiaslins commented 1 year ago

Hey @Saeris

The issue is that you've most probably not enabled Audiences in the Vercel dashboard before deploying the changes. The codesandbox can't work because it needs to be hosted on Vercel in order to use Vercel Web Analytics (Audiences) as it uses the proxy /_vercel/insights/

Let me know if that helps!

tobiaslins commented 1 year ago

Hey @nautilytics

Are you proxying all traffic from for example /base to the Vercel deployment? You can just add another proxy for /_vercel/insights/* to the deployment without /base.