Skip to content
43 changes: 42 additions & 1 deletion src/main/kotlin/com/mparticle/kits/RoktKit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.content.pm.PackageManager
import android.graphics.Typeface
import android.os.Build
import com.mparticle.BuildConfig
import com.mparticle.MParticle
import com.mparticle.MParticle.IdentityType
import com.mparticle.MpRoktEventCallback
import com.mparticle.UnloadReasons
Expand Down Expand Up @@ -188,7 +189,7 @@ class RoktKit : KitIntegration(), CommerceListener, IdentityListener, RoktListen
}?.toMap()

this.mpRoktEventCallback = mpRoktEventCallback
val finalAttributes: HashMap<String, String> = HashMap<String, String>()
val finalAttributes = mutableMapOf<String, String>()
filterUser?.userAttributes?.let { userAttrs ->
for ((key, value) in userAttrs) {
finalAttributes[key] = value.toString()
Expand All @@ -206,6 +207,7 @@ class RoktKit : KitIntegration(), CommerceListener, IdentityListener, RoktListen
attributes?.get(SANDBOX_MODE_ROKT)?.let { value ->
finalAttributes.put(SANDBOX_MODE_ROKT, value)
}
verifyHashedEmail(finalAttributes)
val roktConfig = mpRoktConfig?.let { mapToRoktConfig(it) }
Rokt.execute(
viewName,
Expand Down Expand Up @@ -318,6 +320,45 @@ class RoktKit : KitIntegration(), CommerceListener, IdentityListener, RoktListen
}
}

private fun verifyHashedEmail(attributes: MutableMap<String, String>?) {
if (attributes == null) return

val emailKey = MParticle.IdentityType.Email.name.lowercase()
val otherKey = MParticle.IdentityType.Other.name.lowercase()
val emailShaKey = "emailsha256"

val emailShaValue = attributes.entries.find { it.key.equals(emailShaKey, ignoreCase = true) }?.value
val otherValue = attributes.entries.find { it.key.equals(otherKey, ignoreCase = true) }?.value
Comment thread
Mansi-mParticle marked this conversation as resolved.
Outdated
Comment thread
Mansi-mParticle marked this conversation as resolved.
Outdated

when {
!emailShaValue.isNullOrEmpty() -> {
// If emailsha256 is already present, remove entries with email and other keys
val iterator = attributes.entries.iterator()
while (iterator.hasNext()) {
val entry = iterator.next()
if (entry.key.equals(emailKey, ignoreCase = true) ||
entry.key.equals(otherKey, ignoreCase = true)) {
iterator.remove()
}
}
}

!otherValue.isNullOrEmpty() -> {
Comment thread
Mansi-mParticle marked this conversation as resolved.
Outdated
val iterator = attributes.entries.iterator()
while (iterator.hasNext()) {
val entry = iterator.next()
if (entry.key.equals(emailKey, ignoreCase = true)) {
iterator.remove()
}
if (entry.key.equals(otherKey, ignoreCase = true)) {
iterator.remove()
}
}
attributes[emailShaKey] = otherValue
}
}
}

private fun getStringForIdentity(identityType: IdentityType): String {
return when (identityType) {
IdentityType.Other -> "other"
Expand Down
Loading