mixpanel / mixpanel-js

Official Mixpanel JavaScript Client Library
https://mixpanel.com/help/reference/javascript
Other
884 stars 308 forks source link

In IE9, the library fails with a `mixpanel is not defined` error when mixpanel is not a global object #70

Open johanneslumpe opened 8 years ago

johanneslumpe commented 8 years ago

Interestingly this only happens in IE9, but not 10 or any other browser. Adding mixpanel to the window object solves it, but that seems like a rather dirty workaround. Any advice here? The issue seems to be a response from the mixpanel api which includes a piece of code like mixpanel._jsx[123123]....

tdumitrescu commented 8 years ago

Thanks for the report - surprised our browser matrix testing hasn't caught this. I presume you're using a module-based build (webpack, browserify, etc) rather than the async embed code? Either way, I'm afraid that any browser which needs JSONP instead of XHR for getting HTTP responses will need a global mixpanel object - so our patch will probably involve ensuring that mixpanel is available on window whenever USE_XHR is false (i.e. it will only be exposed for older browsers). Does that seem acceptable?

johanneslumpe commented 8 years ago

@tdumitrescu Yep we're using the module-based build. Luckily we today decided to drop IE9 support so for me personally it's not an issue anymore, but I do think that ensuring that mixpanel is available on the global object is a good workaround. And since it only needs to be exposed for really old browsers it shouldn't be an issue at all for modern browsers :+1:

mteodori commented 8 years ago

Same issue here, it happens when the sendEvent call is used with a callback in IE9

jonashaag commented 7 years ago

Same issue here

resurtm commented 6 years ago

Yep, I confirm I also have this issue.