-
-
Notifications
You must be signed in to change notification settings - Fork 244
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
Mixpanel improvements #115
base: master
Are you sure you want to change the base?
Conversation
- Move the mixpanel load script to separate file - Modify the load script to be able to specify which context object the mixpanel instance should be loaded. Defaults to `window` for backward compatibility - Add `context` mixpanel plugin config option that specifies the context that's passed the refactored load script - Update hooks to get mixpanel instance from resolveMixpanel function instead of from `window`. This decouples the use of mixpanel instance from the window object
- Add option to be able to pass a mixpanel instance directly to mixpanel plugin instead of fetching it from mixpanel CDN
- Add option to pass Mixpanel config - The config is passed to mixpanel.init if the instance needs to be instantiated - The config is passed to mixpanel.set_config if the instance already exists
- Add option `pageEvent`, which allows to specify the name of the event that's tracked when mixpanelPlugin.page is called. Defautlts to 'page'
mixpanelPlugin.page
…able - If 'mixpanel-browser' npm package is installed, the @analytics/mixpanel plugin will try to use that if a mixpanel instance doesn't exist yet
current mixpanel instance
The idea of having |
Hey, (I'm using vercel rewrites for mixpanel proxy, and had to add Thanks for the package though, seems great so far |
@mossypaul Can you please share exactly how you used vercel rewrites with this library for Mixpanel proxy? |
Hi, here's a bunch of suggestions / improvements:
Background
When I was using Mixpanel with
analytics
package, I wanted to use@analytics/mixpanel
package with it to simplify the setup.While it did the job, I had to disable 2 hooks on
@analytics/mixpanel
simply because the implementation was too opinionated.The issue was that
@analytics/mixpanel
loads Mixpanel strictly via a browser script, while we were using themixpanel-browser
package. To work around that, we had to assign themixpanel
instance towindow
.Another issue with the initialization was that it did not allow any mixpanel config to be passed through. Although we could use
mixpanel.set_config
, we needed to set theapi_host
from the very beginning. If we usedmixpanel.set_config
, this was not guaranteed.Other issue was that the
page
hook implementation was too limited (onlysearch
property allowed), and having event name based on current path is an issue in downstream analytics, because you don't have a way to identify allpage
events (better solution is to have a constant event name, like'page'
, and pass the current path as an event attribute.So this MR introduces changes that to fix those issues, plus improve usability around specifying how the mixpanel instance should be loaded.
For individual changes, see the commits.
Changes
Add
pageEvent
mixpanel plugin config optionpageEvent
plugin config value.page
hook is called. Defaults to'page'
Refactor
page
hook to pass all properties tomixpanel.track
Try to load mixpanel from 'mixpanel-browser' if available
plugin will try to use that if a mixpanel instance doesn't exist yet, otherwise it uses the load script as before
Move the mixpanel load script to separate file
window
(same as before).Add
mixpanel
mixpanel plugin config optionmixpanel plugin instead of always fetching and initializing it from mixpanel CDN
Add
context
mixpanel plugin config optionAdd
context
mixpanel plugin config option that specifies the contextthat's passed the refactored load script
Update hooks to get mixpanel instance from resolveMixpanel function
instead of from
window
. This decouples the use of mixpanel instancefrom the window object
Add
config
mixpanel plugin config option to pass Mixpanel configmixpanel.init
if the instance needs to beinstantiated, or to
mixpanel.set_config
if the instance already existsAdd 'getMixpanel' plugin method that returns current mixpanel instance, instead of accessing the instance via
window