Skip to content

Instantly share code, notes, and snippets.

@tdwright
Created January 24, 2019 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdwright/31b84ce23e61dc93b91c44eff28df31b to your computer and use it in GitHub Desktop.
Save tdwright/31b84ce23e61dc93b91c44eff28df31b to your computer and use it in GitHub Desktop.
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