Created
June 3, 2016 23:19
-
-
Save zoellner/b8c590d13cca33f32d630d0bf48f1d1b to your computer and use it in GitHub Desktop.
Delete people profiles from mixpanel based on distinct ids in csv file
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
'use strict'; | |
//Delete people profiles from mixpanel based on distinct ids in people.csv (id in first column) | |
//provide mixpanel token in environment variable MIXPANEL_TOKEN. change people.csv to your filename | |
//see https://mixpanel.com/help/reference/http for mixpanel API documentation | |
var request = require('request'); | |
var _h = require('highland'); | |
_h(_h.wrapCallback(require('fs').readFile)('./people.csv')) //change filename here | |
.split() | |
.map(function(line) { | |
return line.split(',')[0]; //change 0 if id is not in first column | |
}) | |
.compact() | |
.map(function(email) { | |
return { | |
$token: process.env.MIXPANEL_TOKEN, | |
$distinct_id: email, | |
$delete: '' | |
}; | |
}) | |
.batch(50) | |
.map(function(batch) { | |
return new Buffer(JSON.stringify(batch)).toString('base64'); | |
}) | |
.flatMap(_h.wrapCallback(function(encodedString, callback) { | |
var requestParams = { | |
url: 'http://api.mixpanel.com/engage/', | |
form: {data: encodedString} | |
}; | |
require('request').post(requestParams, function(err, res, body) { | |
callback(err, body); | |
}); | |
})) | |
.tap(_h.log) | |
.errors(function(err) { | |
console.log(err); | |
}) | |
.done(function() { | |
console.log('done'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment