Comments (25)
Thanks so much for getting in touch with us! Can you tell me
a bit
more about how AMD will help you and your implementation? If this
is a global use case we'll definitely consider supporting AMD in
the next library release. Are you having issues integrating the
standard library with your require.js app?
Please let me know if you need anything else!
Thanks,
Drew Ritter
from mixpanel-js.
Since you do not provide mixpanel as a module, people are trying to do it themselves (see http://stackoverflow.com/questions/15076489/how-can-i-integrate-mixpanel-and-requirejs and http://stackoverflow.com/questions/17729068/mixpanel-2-2-within-an-amd-structured-web-app-e-g-require-js/17918097#17918097).
This can cause issues with the mixpanel library in regards to the actual reporting, whether done before the library is loaded and/or in delaying the actual loading of the page.
My specific use case is a Backbone.js application, in which I created my own method of tracking events which I spread around the code. That method will call the actual mixpanel library' "track" method. (I also wrapped other libaray methods (such as super property setters, and identify) with my own methods. This will allow me to upgrade your library in the future and/or add more tracking/conversion libraries in the future.
As I do not want to keep track of every release you make to the library in a custom implementation as in the above SO questions, right now my only option is to load mixpanel outside of the require.js scope (and into the global scope), and trusting the browser that the mixpanel method already exists (due to "done" callback capabilities).
from mixpanel-js.
Hi @dorongutman . Does this mean you have an active fork of mixpanel-js that supports AMD? If so, I'd be willing to review a pull request with an implementation similar to underscore's jashkenas/underscore@d12b5be
from mixpanel-js.
Hi @malectro - no, I don't have an active fork. I didn't want to have any thing custom that can break when you change stuff.
While I can add a quick underscore.js style amd support for the mixpanel.js file (see https://github.com/dorongutman/mixpanel-js/blob/amd/mixpanel.js), I'm not quite sure about your snippet code that users need to put in the section as explained in the top of this page: https://mixpanel.com/help/reference/javascript
This underscore.js style AMD will depend on this snippet, which I believe makes the changes to mixpanel.js alone - a bit useless.
What do you think ?
from mixpanel-js.
@dorongutman Ah yes, the snippet. I'm guessing this will require a lot more thinking on my part, but I agree that being AMD compatible would make a lot of sense for our library. This might mean adding a way to bypass the snippet altogether in our lib (and a few more unit tests). I'm going put some energy into this over the coming week.
from mixpanel-js.
Nice.
Some thoughts I had that might interest you regarding this change:
- I saw you're copying some underscore.js's functionality. Since it supports AMD (since version 1.6.0, Feb, 2014) you could provide a smaller version of the library for those that already use underscore, specifically in an AMD environment.
- Errorception is a service that provides a JS library that catches exceptions and shows them to you in their dashboard. The code they provide you is very small, and only meant to store the exceptions until it loads the actual JS library (the equivalent of your "snippet"). The reason I'm saying this, is that it's much smaller than the snippet you provide and I think that you can indeed provide a much much smaller snippet code, that just stores the calls to all your methods (init, track, identify, etc..) in an array, which is parsed later when the library actually finishes loading and initializing.
While I know you're already doing this, you're also doing all sorts of other stuff, which makes the snippet quite large.
This is the minified code errorception provides:
(function(_,e,rr,s){_errs=[s];var c=_.onerror;_.onerror=function(){var a=arguments;_errs.push(a);
c&&c.apply(this,a)};var b=function(){var c=e.createElement(rr),b=e.getElementsByTagName(rr)[0];
c.src="//beacon.errorception.com/"+s+".js";c.async=!0;b.parentNode.insertBefore(c,b)};
_.addEventListener?_.addEventListener("load",b,!1):_.attachEvent("onload",b)})
(window,document,"script","TOKEN");
from mixpanel-js.
+1
from mixpanel-js.
+1
from mixpanel-js.
+1 and while at it, why not putting a UMD wrapper on it to support CommonJS too (browserify)?
from mixpanel-js.
+1 for UMD please
from mixpanel-js.
+1
Any updates with this?
from mixpanel-js.
+1
from mixpanel-js.
+1 Any updates from mixpanel?
from mixpanel-js.
Unfortunately it's still a bit up in the air. We're going to have an internal conversation about getting useful module support into the lib while staying future-proof for ES6 modules and not breaking the existing async 'snippet' loader. Will post back when there's news; thanks for your patience.
from mixpanel-js.
+1
from mixpanel-js.
+1. The workarounds are handy until you need to use the requirejs optimizer, then it just falls apart.
from mixpanel-js.
Any updates on this a few months later?
from mixpanel-js.
planning on getting this in before the end of april. sorry this is taking a while. will post back here when there's news.
from mixpanel-js.
@tdumitrescu April has been and gone, any news here?
from mixpanel-js.
Sorry, got a little overambitious wrt scheduling and mixpanel product priorities. There's a prototype but it's not ready for release; unfortunately can't give an ETA at the moment, but please trust that this isn't forgotten.
from mixpanel-js.
+1 I am really looking forward to an CommonJS version on NPM!
from mixpanel-js.
We now have a PR open with the necessary basic changes: #37 so it won't be too much longer. Thanks again for your patience.
from mixpanel-js.
+1 - any progress on this?
from mixpanel-js.
+1
from mixpanel-js.
AMD/CJS/UMD/ES2015 module support is available as of v2.7.0 (https://github.com/mixpanel/mixpanel-js/releases/tag/v2.7.0). See https://github.com/mixpanel/mixpanel-js/tree/master/examples for some usage examples; documentation in README coming soon.
from mixpanel-js.
Related Issues (20)
- JSON Encoder breaks unicode characters on emojis 🌳
- Bug: 'token' property added to objects sent to track() on Safari / Firefox HOT 3
- allow obfuscation of /track et al. apis HOT 3
- Support for Figma plugins or other Iframe enviroments HOT 15
- Issue with jest
- mixpanel.reset() can't clear Super Properties
- init loaded callback not always called.
- Mixpanel events inconsistently recorded HOT 1
- Documentation – outdated JavaScript example "Tracking Via Proxy" HOT 2
- Unwanted link navigation from `LinkTracker`
- The latest version of the library is different between NPM and CDN HOT 2
- unintended behavior with marketing campaign tracking in the minified version HOT 2
- Long urls are cut off
- Endpoint with track/? is not a valid URL with recent jars of spring boot 3, is there any chance to remove / after track in mixpanel.cjs.js HOT 1
- Allow async init HOT 6
- Can `api_host` contain a /path? HOT 4
- Cannot read properties of undefined (reading 'persistence')
- Reset not available on mixpanel instance
- Target attribute other than _blank is ignored. HOT 1
- Cannot add event properties to Page View event when track_pageview: true in SPA HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mixpanel-js.