vercel / speed-insights

Vercel Speed Insights package
https://vercel.com/docs/speed-insights
Apache License 2.0
54 stars 6 forks source link

Use process.env.ASSET_PREFIX when sending tracking data #63

Closed officert closed 3 weeks ago

officert commented 3 months ago

I'm using Vercel speed-insights and analytics with NextJS. However, our sites are behind a cloudflare proxy, where clients can point any path they want off their domain to our NextJS app. Ex:

https://foobar.com/shop -> proxy to our NextJS app

Our NextJS then rewrites the incoming urls to map them to the folder structure of our NextJS app.

When using speed-insights the request for the Javascript file always points to https://foobar.com/_vercel/speed-insights/script.js, which returns a 404 because we don't control that path on their domain.

I was able to get around this by using the HTML version, and our process.env.ASSET_PATH like this:

<Script src={join(process.env.ASSET_PREFIX, '_vercel/speed-insights/script.js')} />

so that the script is served up from our Vercel provided domain name.

This works, however, all the tracking events are still pointing to https://foobar.com/_vercel.

Is it possible to have both the script tag and the tracking event use the process.env.ASSET_PATH if one is set? Or at least have a way to configure where speed-insights send the tracking events?

tobiaslins commented 3 months ago

Hey!

You can already overwrite both the script and endpoint scriptSrc and endpoint

https://github.com/vercel/speed-insights/blob/main/packages/web/src/types.ts#L9

Let me know if that works for you!

officert commented 3 months ago

@tobiaslins thank you!

I posted in the vercel analytics project too: https://github.com/vercel/analytics/issues/139 but looks like the analytics project doesn't support the same endpoint and scriptSrc params.

feugy commented 3 weeks ago

I'm closing this ticket, feel free to re-open in case of need!