Created
January 24, 2019 08:20
-
-
Save tdwright/31b84ce23e61dc93b91c44eff28df31b to your computer and use it in GitHub Desktop.
Duplicate users by email address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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