Skip to content

Instantly share code, notes, and snippets.

@JeremyPlease
Created January 20, 2017 15:10
Show Gist options
  • Save JeremyPlease/948535d23dbe53d0948d71cae4839cb7 to your computer and use it in GitHub Desktop.
Save JeremyPlease/948535d23dbe53d0948d71cae4839cb7 to your computer and use it in GitHub Desktop.
Remove People Properties from Mixpanel

This script queries all users in Mixpanel and $unsets people properties.

  1. run npm i mixpanel mixpanel-data-export-node
  2. 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);
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment