Instantly share code, notes, and snippets.

Embed
What would you like to do?
Duplicate users by email address
/**
* Duplicate People Profile Check
* Originally by Mixpanel
* Updated by tdwright 09/01/19
**/
var matchKey = "$email";
function main() {
return People()
.filter(function(user){
return user.properties[matchKey] ||
user.distinct_id == user.properties[matchKey] ||
user.distinct_id == encodeURIComponent(user.properties[matchKey]);
})
.map(function(user) {
return {
distinct_id : user.distinct_id,
match_key : user.properties[matchKey] ?
user.properties[matchKey] : ((user.distinct_id == user.properties[matchKey] ||
user.distinct_id == encodeURIComponent(user.properties[matchKey])) ? user.distinct_id : "")
};
})
.groupBy(["match_key"], function(accums, users) {
var holder = {profiles: []};
_.each(accums, function(v) {
_.each(v.profiles, function(profile) {
holder.profiles.push(profile);
});
});
_.each(users, function(v) {
holder.profiles.push(v.distinct_id);
});
return holder;
})
.filter(function(user){
return user.value.profiles && user.value.profiles.length >= 2;
})
.map(function(user) {
return {
"email": user.key[0],
"profiles" : user.value.profiles
}
})
.sortDesc('regDate');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment