Skip to content

Commit 2887ca0

Browse files
authored
Use identity keys in CT configuration (#540)
* Read identity keys from migration config * Do not handle empty keys array * Update example
1 parent 8ad7f57 commit 2887ca0

File tree

6 files changed

+42
-3
lines changed

6 files changed

+42
-3
lines changed

AndroidSDKCore/src/main/java/com/leanplum/internal/Constants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ public static class Params {
167167
public static final String CT_TOKEN = "token";
168168
public static final String CT_REGION_CODE = "regionCode";
169169
public static final String CT_ATTRIBUTE_MAPPINGS = "attributeMappings";
170+
public static final String CT_IDENTITY_KEYS = "identityKeys";
170171
public static final String API_EVENTS_STATE = "events";
171172
}
172173

AndroidSDKCore/src/main/java/com/leanplum/migration/ResponseHandler.kt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import com.leanplum.internal.Constants.Params
2525
import com.leanplum.internal.Log
2626
import com.leanplum.migration.model.MigrationState
2727
import com.leanplum.migration.model.ResponseData
28+
import org.json.JSONArray
2829
import org.json.JSONException
2930
import org.json.JSONObject
3031

@@ -41,7 +42,11 @@ class ResponseHandler {
4142
* "x": "y",
4243
* "a": "b"
4344
* },
44-
* "token": "..."
45+
* "token": "...",
46+
* "identityKeys": [
47+
* "Identity",
48+
* "Phone"
49+
* ]
4550
* },
4651
* "sha256": "...",
4752
* "success": true,
@@ -68,15 +73,25 @@ class ResponseHandler {
6873
var token: String? = null
6974
var regionCode: String? = null
7075
var attributeMappings: String? = null
76+
var identityKeysCsv: String? = null
7177
json.optJSONObject(Params.CLEVERTAP)?.apply {
7278
accountId = optString(Params.CT_ACCOUNT_ID)
7379
token = optString(Params.CT_TOKEN)
7480
regionCode = optString(Params.CT_REGION_CODE)
7581
optJSONObject(Params.CT_ATTRIBUTE_MAPPINGS)?.let {
7682
attributeMappings = it.toString()
7783
}
84+
optJSONArray(Params.CT_IDENTITY_KEYS)?.let {
85+
val keys = mutableListOf<String>()
86+
for (i in 0 until it.length()) {
87+
keys += it.optString(i)
88+
}
89+
if (keys.isNotEmpty()) {
90+
identityKeysCsv = keys.joinToString(separator = ",")
91+
}
92+
}
7893
}
79-
ResponseData(state, hash, accountId, token, regionCode, attributeMappings)
94+
ResponseData(state, hash, accountId, token, regionCode, attributeMappings, identityKeysCsv)
8095
} else {
8196
ResponseData(state, hash)
8297
}

AndroidSDKCore/src/main/java/com/leanplum/migration/model/MigrationConfig.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ object MigrationConfig {
5353
return field
5454
}
5555

56+
private var identityKeysCsv: String? by StringPreferenceNullable(key = "ct_identity_keys")
57+
var identityList: List<String>? = null
58+
private set
59+
get() {
60+
if (field == null) {
61+
field = identityKeysCsv?.split(",") ?: listOf("Identity")
62+
}
63+
return field
64+
}
65+
5666
var trackGooglePlayPurchases = true
5767
private set
5868

@@ -68,6 +78,10 @@ object MigrationConfig {
6878
attributeMappings = data.attributeMappings.also {
6979
attributeMap = null
7080
}
81+
data.identityKeysCsv?.also { // remove question sign if you want a resettable value from server
82+
identityKeysCsv = it
83+
identityList = null
84+
}
7185
}
7286

7387
}

AndroidSDKCore/src/main/java/com/leanplum/migration/model/ResponseData.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ data class ResponseData(
2828
val token: String? = null,
2929
val regionCode: String? = null,
3030
val attributeMappings: String? = null,
31+
val identityKeysCsv: String? = null,
3132
)

AndroidSDKCore/src/main/java/com/leanplum/migration/wrapper/CTWrapper.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
package com.leanplum.migration.wrapper
2323

24+
import android.annotation.SuppressLint
2425
import android.app.Application
2526
import android.content.Context
2627
import android.text.TextUtils
@@ -44,6 +45,7 @@ internal class CTWrapper(
4445
private val accountId: String,
4546
private val accountToken: String,
4647
private val accountRegion: String,
48+
private val identityList: List<String>?,
4749
deviceId: String,
4850
userId: String?
4951
) : IWrapper by StaticMethodsWrapper {
@@ -58,6 +60,7 @@ internal class CTWrapper(
5860
private var identityManager = IdentityManager(deviceId, userId ?: deviceId)
5961
private var firstTimeStart = identityManager.isFirstTimeStart()
6062

63+
@SuppressLint("WrongConstant")
6164
override fun launch(context: Context, callbacks: List<CleverTapInstanceCallback>) {
6265
instanceCallbackList.addAll(callbacks)
6366

@@ -72,6 +75,9 @@ internal class CTWrapper(
7275
enableCustomCleverTapId = true
7376
debugLevel = ctLevel // set instance log level
7477
setLogLevel(lpLevel) // set static log level, arg needs to be Leanplum's level
78+
identityList?.also { // setting IdentityKeys
79+
setIdentityKeys(*it.toTypedArray())
80+
}
7581
}
7682

7783
val cleverTapId = identityManager.cleverTapId()

AndroidSDKCore/src/main/java/com/leanplum/migration/wrapper/WrapperFactory.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ internal object WrapperFactory {
5959
return StaticMethodsWrapper
6060
}
6161

62-
return CTWrapper(account, token, region, deviceId, userId).apply {
62+
val identityList = MigrationConfig.identityList
63+
64+
return CTWrapper(account, token, region, identityList, deviceId, userId).apply {
6365
val timeToLaunch = measureTimeMillis {
6466
launch(context, callbacks)
6567
}

0 commit comments

Comments
 (0)