Skip to content
Snippets Groups Projects
Commit a5a0b3c1 authored by Mauro Pompilio's avatar Mauro Pompilio
Browse files

Move mixpanel alias out of updateUser, too risky.

parent b295e25a
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -2,3 +2,4 @@ dump.rdb
sentinel.dev.conf
npm-debug.log
node_modules
*.sw*
Loading
Loading
@@ -18,7 +18,8 @@ exports.create = function(options) {
eventHF: [],
gaugeHF: [],
userUpdate: [],
responseTime: []
responseTime: [],
alias: []
};
 
var mixpanelEnabled = config.get("stats:mixpanel:enabled");
Loading
Loading
@@ -283,10 +284,21 @@ exports.create = function(options) {
var token = config.get("stats:mixpanel:token");
var mixpanel = Mixpanel.init(token);
 
statsHandlers.alias.push(function(distinctId, userId, cb) {
mixpanel.alias(distinctId, userId, cb);
});
statsHandlers.event.push(function(eventName, properties) {
// Don't handle events that don't have a userId
if(!properties || !(properties.userId || properties.distinctId)) return;
if(mixpanelEventBlacklist[eventName]) return;
if(!properties || !(properties.userId || properties.distinctId)) {
console.log('[mixpanel] Event "' + eventName + '" not sent, missing userId or distinctId.');
return;
}
if(mixpanelEventBlacklist[eventName]) {
console.log('[mixpanel] Event "' + eventName + '" not sent, blacklisted.');
return;
}
 
properties.distinct_id = properties.distinctId || properties.userId;
 
Loading
Loading
@@ -303,28 +315,24 @@ exports.create = function(options) {
});
 
statsHandlers.userUpdate.push(function(user, properties) {
properties = properties || {};
var createdAt = Math.round(user._id.getTimestamp().getTime());
var mp_properties = {
$created_at: new Date(createdAt).toISOString(),
$name: user.displayName,
$username: user.username
};
 
// if we have a mixpanelId, we need to alias the user
if (user.mixpanelId) {
mixpanel.alias(user.mixpanelId, user._id);
}
if (user.email) mp_properties.$email = user.email;
 
if(properties) {
for (var attr in properties) {
var value = properties[attr] instanceof Date ? properties[attr].toISOString() : properties[attr];
mp_properties[attr] = value;
}
for (var attr in properties) {
var value = properties[attr] instanceof Date ? properties[attr].toISOString() : properties[attr];
mp_properties[attr] = value;
}
 
mixpanel.people.set(user.mixpanelId || user._id, mp_properties, function(err) {
mixpanel.people.set(user.id, mp_properties, function(err) {
if (err) emergencyLog('Mixpanel userUpdate: ' + err, { exception: err });
});
});
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment