Created
April 6, 2016 16:45
-
-
Save mrw34/fe60e00fabde55a0c4513e5a9c7af228 to your computer and use it in GitHub Desktop.
Mixpanel export
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"dependencies": { | |
"moment": "^2.12.0", | |
"request": "^2.70.0", | |
"underscore": "^1.8.3" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Set
API_KEY
,API_SECRET
andEVENT
and then runnpm start