Skip to content
50 changes: 49 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,52 @@ 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 emailSha = attributes.entries.find { it.key.equals(emailShaKey, ignoreCase = true) }?.value
Comment thread
Mansi-mParticle marked this conversation as resolved.
Outdated
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 {
!emailSha.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
// If "other" has a value, treat it as hashed email
val iterator = attributes.entries.iterator()
while (iterator.hasNext()) {
val entry = iterator.next()
if (entry.key.equals(emailKey, ignoreCase = true)) {
iterator.remove()
}
}
attributes[emailShaKey] = otherValue
val iterator2 = attributes.entries.iterator()
while (iterator2.hasNext()) {
val entry = iterator2.next()
if (entry.key.equals(otherKey, ignoreCase = true)) {
iterator2.remove()
}
}
Comment thread
Mansi-mParticle marked this conversation as resolved.
Outdated
}
// else: do nothing
}
Logger.debug("Mansi "+attributes.size)
Comment thread
Mansi-mParticle marked this conversation as resolved.
Outdated
}

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