segmentio / analytics-next

Segment Analytics.js 2.0
https://segment.com/docs/connections/sources/catalog/libraries/website/javascript
MIT License
389 stars 130 forks source link

Metrics Calls When using a Proxy #984

Open ChrisSargent opened 9 months ago

ChrisSargent commented 9 months ago

Hello,

We're using a proxy for our calls to Segment in order to prevent ad blockers from blocking calls and also to ease some CSP burden.

We have this setup correctly for everything in Segment to work (loading integrations, track calls, identify calls) but the SDK still tries to make regular calls to the Segment metrics url.

Is it possible to configure this already or would it require some PR?

Thanks.

chrisradek commented 9 months ago

@ChrisSargent Thanks for opening this issue. Taking a quick look - looks like the metrics endpoint should be configurable but it isn't exposed somewhere that's easy to access.

If you're using the library via the NPM package there's a rough workaround where you can pass a function in via options.updateCDNSettings that mutates the CDN settings to change the api host in metrics - but if you're using the CDN bundle there are some metrics around load failures that wouldn't be affected by this.

We should make this more easily configurable though for proxy users.