Skip to content

Commit c67e569

Browse files
feat: Handle hashed email for rokt
1 parent 448f3ca commit c67e569

1 file changed

Lines changed: 24 additions & 9 deletions

File tree

android-kit-base/src/main/java/com/mparticle/kits/KitManagerImpl.java

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,8 +1365,9 @@ public void execute(@NonNull String viewName,
13651365
MParticle instance = MParticle.getInstance();
13661366
MParticleUser user = instance.Identity().getCurrentUser();
13671367
String email = attributes.get("email");
1368+
String hashedEmail = attributes.get("other");
13681369
Map<String, String> finalAttributes = attributes;
1369-
confirmEmail(email,user,instance.Identity(), () -> {
1370+
confirmEmail(email,hashedEmail,user,instance.Identity(), () -> {
13701371
JSONArray jsonArray = new JSONArray();
13711372

13721373
KitConfiguration kitConfig = provider.getConfiguration();
@@ -1473,32 +1474,46 @@ public void close() {
14731474

14741475
private void confirmEmail(
14751476
@Nullable String email,
1477+
@Nullable String hashedEmail,
14761478
@Nullable MParticleUser user,
14771479
IdentityApi identityApi,
14781480
Runnable runnable
14791481
) {
1480-
if (email != null && user != null) {
1482+
if ((email != null || hashedEmail != null) && user != null) {
14811483
String existingEmail = user.getUserIdentities().get(MParticle.IdentityType.Email);
1484+
String existingHashedEmail = user.getUserIdentities().get(MParticle.IdentityType.Other);
14821485

1483-
if (!email.equals(existingEmail)) {
1486+
if (!Objects.equals(email, existingEmail) || !Objects.equals(hashedEmail, existingHashedEmail)) {
14841487
// If there's an existing email but it doesn't match the passed-in email, log a warning
1485-
if (existingEmail != null) {
1486-
Logger.warning( String.format(
1488+
if (existingEmail != null && email != null) {
1489+
Logger.warning(String.format(
14871490
"The existing email on the user (%s) does not match the email passed to selectPlacements (%s). " +
14881491
"Please make sure to sync the email identity to mParticle as soon as it's available. " +
14891492
"Identifying user with the provided email before continuing to selectPlacements.",
14901493
existingEmail, email
14911494
));
1495+
} else if (existingHashedEmail != null && hashedEmail != null) {
1496+
Logger.warning(String.format(
1497+
"The existing hashed email on the user (%s) does not match the hashed email passed to selectPlacements (%s). " +
1498+
"Please make sure to sync the email identity to mParticle as soon as it's available. " +
1499+
"Identifying user with the provided email before continuing to selectPlacements.",
1500+
existingHashedEmail, hashedEmail
1501+
));
14921502
}
14931503

1494-
IdentityApiRequest identityRequest = IdentityApiRequest.withUser(user)
1495-
.email(email)
1496-
.build();
1504+
IdentityApiRequest.Builder identityBuilder = IdentityApiRequest.withUser(user);
1505+
if (email != null) {
1506+
identityBuilder.email(email);
1507+
}
1508+
if (hashedEmail != null) {
1509+
identityBuilder.userIdentity(MParticle.IdentityType.Other, hashedEmail);
1510+
}
1511+
IdentityApiRequest identityRequest = identityBuilder.build();
14971512
MParticleTask<IdentityApiResult> task = identityApi.identify(identityRequest);
14981513
task.addFailureListener(new TaskFailureListener() {
14991514
@Override
15001515
public void onFailure(IdentityHttpResponse result) {
1501-
Logger.error( "Failed to sync email from selectPlacement to user: " + result.getErrors().toString());
1516+
Logger.error("Failed to sync email from selectPlacement to user: " + result.getErrors().toString());
15021517

15031518
runnable.run();
15041519
}

0 commit comments

Comments
 (0)