A simple server-side API for mixpanel
npm install mixpanel
// grab the Mixpanel factoryvar Mixpanel = ;// create an instance of the mixpanel clientvar mixpanel = Mixpanel;// initialize mixpanel client configured to communicate over httpsvar mixpanel = Mixpanel;// track an event with optional propertiesmixpanel;mixpanel;// create or update a user in Mixpanel Engagemixpanelpeople;// create or update a user in Mixpanel Engage without altering $last_seen// - pass option $ignore_time: true to prevent the $last_seen property from being updatedmixpanelpeople;// set a single property on a usermixpanelpeople;// set a single property on a user, don't overridemixpanelpeople;// increment a numeric propertymixpanelpeople;// increment a numeric property by a different amountmixpanelpeople;// increment multiple propertiesmixpanelpeople;// append value to a listmixpanelpeople;// append multiple values to a listmixpanelpeople;// merge value to a list (ignoring duplicates)mixpanelpeople;// merge multiple values to a list (ignoring duplicates)mixpanelpeople;// record a transaction for revenue analyticsmixpanelpeople;// clear a users transaction historymixpanelpeople;// delete a usermixpanelpeople;// delete a user in Mixpanel Engage without altering $last_seen or resolving aliases// - pass option $ignore_time: true to prevent the $last_seen property from being updated// (useful if you subsequently re-import data for the same distinct ID)mixpanelpeople;// Create an alias for an existing distinct idmixpanel;// all functions that send data to mixpanel take an optional// callback as the last argumentmixpanel;// import an old eventvar mixpanel_importer = Mixpanel;// needs to be in the system once for it to show up in the interfacemixpanel_importer;mixpanel_importer;// import multiple events at oncemixpanel_importer;
mixpanel-node is a server-side library, optimized for stateless shared usage; e.g.,
in a web application, the same mixpanel instance is used across requests for all users.
Rather than setting a
identify() calls like Mixpanel client-side
libraries (where a single Mixpanel instance is tied to a single user), this library
requires you to pass the
distinct_id with every tracking call. See
How do I get or set superproperties?
See the previous answer: the library does not maintain user state internally and so has no concept of superproperties for individual users. If you wish to preserve properties for users between requests, you will need to load these properties from a source specific to your app (e.g., your session store or database) and pass them explicitly with each tracking call.
# in the mixpanel directory npm install npm test
Heavily inspired by the original js library copyright Mixpanel, Inc. (http://mixpanel.com/)
Copyright (c) 2014-15 Mixpanel Original Library Copyright (c) 2012-14 Carl Sverre
Released under the MIT license. See file called LICENSE for more details.