Mixpanel-node
This library provides many of the features in the official JavaScript mixpanel library. It is easy to use, and fully async. It is intended to be used on the server (it is not a client module). The in-browser client library is available at https://github.com/mixpanel/mixpanel-js.
Installation
npm install mixpanel
Quick Start
// grab the Mixpanel factoryvar Mixpanel = ; // create an instance of the mixpanel clientvar 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; // 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// - 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;
FAQ
Where is mixpanel.identify()
?
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 distinct_id
through 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
https://github.com/mixpanel/mixpanel-node/issues/13.
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.
Tests
# in the mixpanel directory
npm install
npm test
Attribution/Credits
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
Contributions from:
- Andres Gottlieb
- Ken Perkins
- Nathan Rajlich
- Thomas Watson Steen
- Gabor Ratky
- wwlinx
- PierrickP
- lukapril
- sandinmyjoints
- Jyrki Laurila
- Zeevl
- Tobias Baunbæk
- Eduardo Sorribas
- Nick Chang
- Michael G
- Tejas Manohar
- Eelke Boezeman
License
Released under the MIT license. See file called LICENSE for more details.