Skip to content

Instantly share code, notes, and snippets.

@mrw34

mrw34/package.json

Created Apr 6, 2016
Embed
What would you like to do?
Mixpanel export
{
"dependencies": {
"moment": "^2.12.0",
"request": "^2.70.0",
"underscore": "^1.8.3"
}
}
var API_KEY = '...';
var API_SECRET = '...';
var EVENT = '...';
var moment = require('moment'),
_ = require('underscore'),
crypto = require('crypto'),
request = require('request');
var args = {
api_key: API_KEY,
event: '["' + EVENT + '"]',
expire: moment().add(1, 'minute').unix(),
from_date: moment().subtract(1, 'day').format('YYYY-MM-DD'),
to_date: moment().format('YYYY-MM-DD')
};
var str = _.pairs(args).reduce(function(memo, pair) {
return memo + pair.join('=');
}, '') + API_SECRET;
args.sig = crypto.createHash('md5').update(str).digest('hex');
request.get('http://data.mixpanel.com/api/2.0/export/', {qs: args}, function(error, response, body) {
console.log(error || body);
});
@mrw34

This comment has been minimized.

Copy link
Owner Author

@mrw34 mrw34 commented Apr 6, 2016

Set API_KEY, API_SECRET and EVENT and then run npm start

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment