Metrics.js is a simple script that will log events to Hone's server as well as Mixpanel's. It is written with some ES6 features so it needs to compiled using es6ify.
Right now it is small and will hopefully be inlined so no queueing is setup, but it can be used in sync form
<script src="/path-to/metrics.min.js"></script>
Then we need to initialize metrics with the keys using
- params
- options { Object }
- options.domain { String } - domain to log events to
- options.mixpanel { String } - mixpanel api key
- options { Object }
metrics.init( {
domain: 'http://localhost:8000',
mixpanel: 'FOOBARBAZQUX'
} );
To track an event
- params
- eventName { String } - Event name
- meta { Object } - An Object with meta data about event
metrics.track( 'foo' , {
bar: 'baz',
qux: 'foo'
} );
To identify a user
- params
- identity { Object } - An Object with id and email of a user
- identity.id { String } - An unique identifier
- identity.email { String } - The users email
- identity { Object } - An Object with id and email of a user
This fires both mixpanel.identify & mixpanel.name_tag
metrics.identify( {
id: 'foobar', // goes to mixpanel.identify
email: '[email protected]' // goes to mixpanel.name_tag
} );
To register a user
- params
- user { Object } - An Object with user information to register with mixpanel
This only fires an event to mixpanel since we should already have the user in our systems
metrics.register( { User } );
All the the dependencies to build the script can all be installed using npm.
$ npm install
To build the script all you need to run is.
$ npm run build
If your code looks good next to make sure it is all good run
$ npm test
to test your code. You will need Firefox to run the tests inside of.