Solved

I suspect I have duplicate profiles, how can I find them?

  • 12 September 2018
  • 1 reply
  • 48 views

Userlevel 3
Badge
icon

Best answer by michael 12 September 2018, 02:37

Hi @linda.kim- welcome to the community!

I have a query you can use below that will identify your duplicate profiles by a shared key.

As it stands, this will match duplicate profiles by the $email people property, but you can sub out your own property in that first line.

var matchKey = "$email"; // update matching people property here
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 {
"profiles" : user.value.profiles
}
})
}

View original

1 reply

Userlevel 4
Badge +1

Hi @linda.kim- welcome to the community!

I have a query you can use below that will identify your duplicate profiles by a shared key.

As it stands, this will match duplicate profiles by the $email people property, but you can sub out your own property in that first line.

var matchKey = "$email"; // update matching people property here
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 {
"profiles" : user.value.profiles
}
})
}

Reply