Use process.env.ASSET_PREFIX when sending tracking data
officert opened this issue · 3 comments
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?
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!
@tobiaslins thank you!
I posted in the vercel analytics project too: vercel/analytics#139
but looks like the analytics project doesn't support the same endpoint
and scriptSrc
params.
I'm closing this ticket, feel free to re-open in case of need!