-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Load Breaks with Privacy Badger #554
Comments
@KeKs0r Thanks for creating this issue! Can you update the code to include a catch handler like this? export const analytics = SEGMENT_TOKEN
? await AnalyticsBrowser.load({ writeKey: SEGMENT_TOKEN }).catch(() => undefined)
: undefined That will prevent errors from breaking your code - instead
export const analytics = SEGMENT_TOKEN
? await AnalyticsBrowser.load({ writeKey: SEGMENT_TOKEN }).then(([analytics]) => analytics).catch(() => undefined)
: undefined |
Seems like a potentially common issue with blockers; we might want to just noop this kind of fetch error by default. I imagine most Segment users would prefer that this library avoid throwing wherever possible, especially when it’s due to something like this. |
@chrisradek @silesky |
@KeKs0r ... did you try using the synchronous API? export const analytics = SEGMENT_TOKEN
? AnalyticsBrowser.load({ writeKey: SEGMENT_TOKEN })
: undefined
analytics.track('foo') It should log load errors, but should not throw. edit: I added a test to confirm this behavior https://github.com/segmentio/analytics-next/pull/557/files#diff-47514c4c862cd4b0072c15f4bb644190a93539c5c089f647fd418239b4f928a4R189 |
@silesky yes I ran into this in production. Also updated to the newest version of this library. Only way to get around it in my codebase was to remove the throw part in the catch. Maybe it also depends on the bundling, since my analytics is defined on the top level of a module. So depending on how a bundler might wrap the file import, it potentially throws on a top level. |
@silesky My client breaks with an adblocker is present (uBlock origin in my case) - it blocks our Hubspot integration (The URL is from this format Any suggestions here? Thanks! |
If we're still just talking about catching any initial load errors and doing something with them (besides console logging), the new, documented way is: export const analytics = new AnalyticsBrowser();
analytics
.load({ writeKey: "MY_WRITE_KEY" })
.catch((err) => ...); Note: this catch clause will not handle device mode script blocked errors -- the only adblocking errors that it should handle would be if the settings CDN gets blocked. I am interested in this adblocker case -- some questions:
|
We have tried to upgrade the client to the latest version but still could not catch the failure under that
upgraded to this, and still can't get to the catch clause on failure:
Thanks @silesky! |
Try this const hasKey = Boolean(import.meta.env.SEGMENT_TOKEN)
export const track = async (...args: Parameters<typeof analytics.track>) => {
if (hasKey) {
await analytics.track(...args)
}
} |
I've just encountered this. The problem I had was that Segment would load but fail to fetch settings (request was blocked by browser). This would mean that To solve I had to wrap
|
I have Segment running via a proxy and it's working great based on the instructions here. https://segment.com/docs/connections/sources/catalog/libraries/website/javascript/custom-proxy/ However, the destinations I have set up (for example Mixpanel) also load a cdn (http://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js), which is not proxied and is therefore blocked. Is there a way to use the |
@georgebutter -- analytics.js is just a loader for destinations. Unless there's some mixpanel global you can modify to update that config, that option would be something that would need to be supported on the action side and likely passed to mixpanel via instantiation. Currently, there's no option for configuring api host / proxy options in mixpanel via segment. You could make a support request or a contribution to https://github.com/segmentio/action-destinations |
It seems that Privacy Badger blocks the call to get the settings.
The problem is, that means that the
load
call throws.And i have in my code the
analytics
as a var in the global spaceI am currently failing to wrap this call in a try catch. Because the error is async. So in order to "catch" it, I would need to make
analytics
a Promise instead of theAnalyticsBrowser
.Which then means, I have to make all calls to it async.
I think it would be beneficial to handle those kind of errors within the sdk, to prevent breaking user code.
This is the error that breaks my app:
analytics-next/packages/browser/src/browser/index.ts
Lines 85 to 91 in 7ea4c60
The text was updated successfully, but these errors were encountered: