Skip to content

Commit 9b82749

Browse files
feat: Map selected identity to
1 parent 1d587f3 commit 9b82749

File tree

2 files changed

+68
-28
lines changed

2 files changed

+68
-28
lines changed

src/main/kotlin/com/mparticle/kits/RoktKit.kt

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class RoktKit :
5757
Rokt.RoktCallback {
5858
private var applicationContext: Context? = null
5959
private var mpRoktEventCallback: MpRoktEventCallback? = null
60+
private var hashedEmailUserIdentityType: String? = null
6061
override fun getName(): String = NAME
6162

6263
override fun getInstance(): RoktKit = this
@@ -70,6 +71,7 @@ class RoktKit :
7071
if (KitUtils.isEmpty(roktTagId)) {
7172
throwOnKitCreateError(NO_ROKT_ACCOUNT_ID)
7273
}
74+
hashedEmailUserIdentityType = settings[HASHED_EMAIL_USER_IDENTITY_TYPE]
7375
applicationContext?.let {
7476
val manager = context.packageManager
7577
if (roktTagId != null) {
@@ -343,7 +345,11 @@ class RoktKit :
343345
if (filterUser != null) {
344346
for ((identityNumberKey, identityValue) in filterUser.userIdentities) {
345347
val identityType = getStringForIdentity(identityNumberKey)
346-
identityAttributes[identityType] = identityValue
348+
if (identityType.equals(hashedEmailUserIdentityType)) {
349+
identityAttributes["emailsha256"] = identityValue
350+
} else {
351+
identityAttributes[identityType] = identityValue
352+
}
347353
}
348354
}
349355
if (attributes != null) {
@@ -377,28 +383,28 @@ class RoktKit :
377383
}
378384

379385
private fun getStringForIdentity(identityType: IdentityType): String = when (identityType) {
380-
IdentityType.Other -> "emailsha256"
381-
IdentityType.CustomerId -> "customerid"
382-
IdentityType.Facebook -> "facebook"
383-
IdentityType.Twitter -> "twitter"
384-
IdentityType.Google -> "google"
385-
IdentityType.Microsoft -> "microsoft"
386-
IdentityType.Yahoo -> "yahoo"
387-
IdentityType.Email -> "email"
388-
IdentityType.Alias -> "alias"
389-
IdentityType.FacebookCustomAudienceId -> "facebookcustomaudienceid"
390-
IdentityType.Other2 -> "other2"
391-
IdentityType.Other3 -> "other3"
392-
IdentityType.Other4 -> "other4"
393-
IdentityType.Other5 -> "other5"
394-
IdentityType.Other6 -> "other6"
395-
IdentityType.Other7 -> "other7"
396-
IdentityType.Other8 -> "other8"
397-
IdentityType.Other9 -> "other9"
398-
IdentityType.Other10 -> "other10"
399-
IdentityType.MobileNumber -> "mobilenumber"
400-
IdentityType.PhoneNumber2 -> "phonenumber2"
401-
IdentityType.PhoneNumber3 -> "phonenumber3"
386+
IdentityType.Other -> "Other"
387+
IdentityType.CustomerId -> "CustomerId"
388+
IdentityType.Facebook -> "Facebook"
389+
IdentityType.Twitter -> "Twitter"
390+
IdentityType.Google -> "Google"
391+
IdentityType.Microsoft -> "Microsoft"
392+
IdentityType.Yahoo -> "Yahoo"
393+
IdentityType.Email -> "Email"
394+
IdentityType.Alias -> "Alias"
395+
IdentityType.FacebookCustomAudienceId -> "FacebookCustomAudienceId"
396+
IdentityType.Other2 -> "Other2"
397+
IdentityType.Other3 -> "Other3"
398+
IdentityType.Other4 -> "Other4"
399+
IdentityType.Other5 -> "Other5"
400+
IdentityType.Other6 -> "Other6"
401+
IdentityType.Other7 -> "Other7"
402+
IdentityType.Other8 -> "Other8"
403+
IdentityType.Other9 -> "Other9"
404+
IdentityType.Other10 -> "Other10"
405+
IdentityType.MobileNumber -> "MobileNumber"
406+
IdentityType.PhoneNumber2 -> "PhoneNumber2"
407+
IdentityType.PhoneNumber3 -> "PhoneNumber3"
402408
else -> ""
403409
}
404410

@@ -413,6 +419,7 @@ class RoktKit :
413419

414420
const val NAME = "Rokt"
415421
const val ROKT_ACCOUNT_ID = "accountId"
422+
const val HASHED_EMAIL_USER_IDENTITY_TYPE = "hashedEmailUserIdentityType"
416423
const val MPID = "mpid"
417424
const val NO_ROKT_ACCOUNT_ID = "No Rokt account ID provided, can't initialize kit."
418425
const val NO_APP_VERSION_FOUND = "No App version found, can't initialize kit."

src/test/kotlin/com/mparticle/kits/RoktKitTests.kt

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ class RoktKitTests {
153153
assertTrue(result.containsKey("key2"))
154154
assertTrue(result.containsKey("key3"))
155155
assertTrue(result.containsKey("email"))
156+
assertTrue(result.containsKey("Email"))
156157
}
157158

158159
@Test
@@ -166,6 +167,7 @@ class RoktKitTests {
166167
"key2" to "value2",
167168
"key3" to "value3",
168169
"email" to "[email protected]",
170+
"Email" to "[email protected]",
169171
)
170172
val method: Method = RoktKit::class.java.getDeclaredMethod(
171173
"addIdentityAttributes",
@@ -179,13 +181,13 @@ class RoktKitTests {
179181
assertTrue(result.containsKey("key1"))
180182
assertTrue(result.containsKey("key2"))
181183
assertTrue(result.containsKey("key3"))
182-
assertTrue(result.containsKey("email"))
184+
assertTrue(result.containsKey("Email"))
183185
assertEquals(
184186
mapOf(
185187
"key1" to "value1",
186188
"key2" to "value2",
187189
"key3" to "value3",
188-
"email" to "[email protected]",
190+
"Email" to "[email protected]",
189191
),
190192
result,
191193
)
@@ -217,7 +219,7 @@ class RoktKitTests {
217219
method.isAccessible = true
218220
val result = method.invoke(roktKit, null, mockFilterUser) as Map<String, String>
219221
assertEquals(1, result.size)
220-
assertEquals(mapOf("email" to "[email protected]"), result)
222+
assertEquals(mapOf("Email" to "[email protected]"), result)
221223
}
222224

223225
@Test
@@ -264,7 +266,38 @@ class RoktKitTests {
264266
assertTrue(result.containsKey("key1"))
265267
assertTrue(result.containsKey("key2"))
266268
assertTrue(result.containsKey("key3"))
267-
assertTrue(result.containsKey("email"))
269+
assertTrue(result.containsKey("Email"))
270+
assertTrue(result.containsKey("Other"))
271+
}
272+
273+
@Test
274+
fun test_addIdentityAttributes_When_userIdentities_Other_map_To_Identity() {
275+
val mockFilterUser = mock(FilteredMParticleUser::class.java)
276+
val userIdentities = HashMap<IdentityType, String>()
277+
userIdentities.put(IdentityType.Email, "[email protected]")
278+
userIdentities.put(IdentityType.Other, "[email protected]")
279+
Mockito.`when`(mockFilterUser.userIdentities).thenReturn(userIdentities)
280+
val attributes: Map<String, String> = mapOf(
281+
"key1" to "value1",
282+
"key2" to "value2",
283+
"key3" to "value3",
284+
)
285+
val hashedField = RoktKit::class.java.getDeclaredField("hashedEmailUserIdentityType")
286+
hashedField.isAccessible = true
287+
hashedField.set(roktKit, "Other")
288+
val method: Method = RoktKit::class.java.getDeclaredMethod(
289+
"addIdentityAttributes",
290+
Map::class.java,
291+
FilteredMParticleUser::class.java,
292+
)
293+
method.isAccessible = true
294+
val result = method.invoke(roktKit, attributes, mockFilterUser) as Map<String, String>
295+
assertEquals(5, result.size)
296+
297+
assertTrue(result.containsKey("key1"))
298+
assertTrue(result.containsKey("key2"))
299+
assertTrue(result.containsKey("key3"))
300+
assertTrue(result.containsKey("Email"))
268301
assertTrue(result.containsKey("emailsha256"))
269302
}
270303

@@ -672,7 +705,7 @@ class RoktKitTests {
672705

673706
override fun setIntegrationAttributes(kitId: Int, integrationAttributes: Map<String, String>) {}
674707

675-
override fun getIntegrationAttributes(kitId: Int): Map<String, String>? = null
708+
override fun getIntegrationAttributes(i: Int): Map<String, String>? = null
676709

677710
override fun getCurrentActivity(): WeakReference<Activity> = WeakReference(activity)
678711

0 commit comments

Comments
 (0)