This script queries all users in Mixpanel and $unset
s people properties.
- run
npm i mixpanel mixpanel-data-export-node
MIXPANEL_API_KEY=key MIXPANEL_API_SECRET=secret MIXPANEL_HASH=hash node mixpanel.js
var MixpanelExport = require('mixpanel-data-export-node'); | |
var panel = new MixpanelExport({ | |
api_key: process.env.MIXPANEL_API_KEY, | |
api_secret: process.env.MIXPANEL_API_SECRET | |
}); | |
var Mixpanel = require('mixpanel'); | |
var mixpanel = Mixpanel.init(process.env.MIXPANEL_HASH, { | |
protocol: 'http', | |
host: '169.54.33.205' // IP used instead of api.mixpanel.com to resolve network issues | |
}); | |
// the fields to unset | |
var uneset_fields = ['$first_name', '$last_name', '$name', 'name', 'address']; | |
var total, page_size; | |
panel.engage().then(processUsers); | |
function processUsers(response) { | |
total = total || response.total; | |
page_size = page_size || response.page_size; | |
console.log(`processing ${(response.page+1)*page_size} / ${total}`); | |
var update_count = 0; | |
response.results.forEach(function(user) { | |
mixpanel.people.unset(user.$distinct_id, uneset_fields, { | |
$ignore_time: true | |
}, function(e) { | |
if (e) { | |
console.log(e) | |
} | |
update_count++; | |
if (update_count >= page_size && response.results.length >= page_size) { | |
panel.engage({ | |
session_id: response.session_id, | |
page: response.page+1 | |
}).then(processUsers); | |
} | |
}); | |
}); | |
} |