Skip to content

Commit f19875a

Browse files
committed
Merge branch 'master' into release/7.0.0
2 parents e8e0b39 + 9ef33f0 commit f19875a

File tree

10 files changed

+68
-71
lines changed

10 files changed

+68
-71
lines changed

AndroidSDKCore/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ dependencies {
4242
api "androidx.legacy:legacy-support-v4:1.0.0"
4343
api "androidx.appcompat:appcompat:${APPCOMPAT_LIBRARY_VERSION}"
4444

45-
api "com.clevertap.android:clevertap-android-sdk:4.6.3"
45+
api "com.clevertap.android:clevertap-android-sdk:4.6.4"
4646
}
4747

4848
task generateJavadoc(type: Javadoc) {

AndroidSDKCore/src/main/java/com/leanplum/Leanplum.java

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,7 +1672,9 @@ private static void setTrafficSourceInfoInternal(HashMap<String, Object> params)
16721672
*/
16731673
public static void track(final String event, double value, String info,
16741674
Map<String, ?> params) {
1675-
MigrationManager.getWrapper().track(event, value, info, params);
1675+
LeanplumInternal.addStartIssuedHandler(() -> {
1676+
MigrationManager.getWrapper().track(event, value, info, params);
1677+
});
16761678
LeanplumInternal.track(event, value, info, params, null);
16771679
}
16781680

@@ -1698,7 +1700,9 @@ public static void trackPurchase(final String event, double value, String curren
16981700
requestArgs.put(Constants.Params.IAP_CURRENCY_CODE, currencyCode);
16991701
}
17001702

1701-
MigrationManager.getWrapper().trackPurchase(event, value, currencyCode, params);
1703+
LeanplumInternal.addStartIssuedHandler(() -> {
1704+
MigrationManager.getWrapper().trackPurchase(event, value, currencyCode, params);
1705+
});
17021706
LeanplumInternal.track(event, value, null, params, requestArgs);
17031707
} catch (Throwable t) {
17041708
Log.exception(t);
@@ -1768,17 +1772,19 @@ public static void trackGooglePlayPurchase(String eventName, String item, long p
17681772
}
17691773
modifiedParams.put(Constants.Params.IAP_ITEM, item);
17701774

1771-
if (MigrationManager.trackGooglePlayPurchases()) {
1772-
MigrationManager.getWrapper().trackGooglePlayPurchase(
1773-
eventName,
1774-
item,
1775-
priceMicros / 1000000.0,
1776-
currencyCode,
1777-
purchaseData,
1778-
dataSignature,
1779-
params
1780-
);
1781-
}
1775+
LeanplumInternal.addStartIssuedHandler(() -> {
1776+
if (MigrationManager.trackGooglePlayPurchases()) {
1777+
MigrationManager.getWrapper().trackGooglePlayPurchase(
1778+
eventName,
1779+
item,
1780+
priceMicros / 1000000.0,
1781+
currencyCode,
1782+
purchaseData,
1783+
dataSignature,
1784+
params
1785+
);
1786+
}
1787+
});
17821788
LeanplumInternal.track(eventName, priceMicros / 1000000.0, null, modifiedParams, requestArgs);
17831789
}
17841790

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ public static void setLogLevel(int level) {
4646
Log.level = level;
4747
}
4848

49+
public static int getLogLevel() {
50+
return level;
51+
}
52+
4953
public static void e(String msg, Object... args) {
5054
log(LogType.ERROR, msg, args);
5155
}
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.leanplum.migration
22

3+
import com.clevertap.android.sdk.CleverTapAPI
4+
import com.leanplum.internal.Log
5+
36
object MigrationConstants {
47
const val IDENTITY = "Identity"
58
const val STATE_PREFIX = "state_"
6-
const val UTM_VISITED = "UTM Visited"
79

810
const val CHARGED_EVENT_PARAM = "event"
911
const val VALUE_PARAM = "value"
@@ -12,4 +14,12 @@ object MigrationConstants {
1214
const val GP_PURCHASE_DATA_PARAM = "googlePlayPurchaseData"
1315
const val GP_PURCHASE_DATA_SIGNATURE_PARAM = "googlePlayPurchaseDataSignature"
1416
const val IAP_ITEM_PARAM = "item"
17+
18+
fun mapLogLevel(lpLevel: Int): CleverTapAPI.LogLevel = when (lpLevel) {
19+
Log.Level.OFF -> CleverTapAPI.LogLevel.OFF
20+
Log.Level.ERROR -> CleverTapAPI.LogLevel.INFO
21+
Log.Level.INFO -> CleverTapAPI.LogLevel.INFO
22+
Log.Level.DEBUG -> CleverTapAPI.LogLevel.VERBOSE
23+
else -> CleverTapAPI.LogLevel.INFO
24+
}
1525
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,17 @@ object MigrationManager {
2828

2929
@JvmStatic
3030
fun updateWrapper() {
31+
if (Constants.isNoop()) {
32+
wrapper = NullWrapper
33+
return
34+
}
35+
3136
if (getState().useCleverTap()
3237
&& (wrapper == NullWrapper || wrapper == StaticMethodsWrapper)
3338
) {
3439
wrapper = WrapperFactory.createWrapper(cleverTapInstanceCallback)
3540
} else if (wrapper != NullWrapper && !getState().useCleverTap()) {
36-
wrapper = WrapperFactory.createNullWrapper()
41+
wrapper = NullWrapper
3742
}
3843
}
3944

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

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import com.clevertap.android.sdk.ActivityLifecycleCallback
66
import com.clevertap.android.sdk.CleverTapAPI
77
import com.clevertap.android.sdk.CleverTapInstanceConfig
88
import com.leanplum.callbacks.CleverTapInstanceCallback
9-
import com.leanplum.internal.Constants
10-
import com.leanplum.internal.LeanplumInternal
119
import com.leanplum.internal.Log
1210
import com.leanplum.migration.MigrationConstants
1311
import com.leanplum.migration.MigrationManager
@@ -35,12 +33,17 @@ internal class CTWrapper(
3533
override fun launch(context: Context, callback: CleverTapInstanceCallback?) {
3634
instanceCallback = callback
3735

36+
val lpLevel = Log.getLogLevel()
37+
val ctLevel = MigrationConstants.mapLogLevel(lpLevel).intValue()
38+
3839
val config = CleverTapInstanceConfig.createInstance(
3940
context,
4041
accountId,
4142
accountToken,
4243
accountRegion).apply {
4344
enableCustomCleverTapId = true
45+
debugLevel = ctLevel // set instance log level
46+
setLogLevel(lpLevel) // set static log level, arg needs to be Leanplum's level
4447
}
4548

4649
val cleverTapId = identityManager.cleverTapId()
@@ -99,7 +102,6 @@ internal class CTWrapper(
99102
info: String?,
100103
params: Map<String, Any?>?
101104
) {
102-
if (Constants.isNoop()) return
103105
if (event == null) return
104106

105107
val properties =
@@ -112,10 +114,8 @@ internal class CTWrapper(
112114
properties[MigrationConstants.INFO_PARAM] = info
113115
}
114116

115-
LeanplumInternal.addStartIssuedHandler {
116-
Log.d("Wrapper: Leanplum.track will call pushEvent with $event and $properties")
117-
cleverTapInstance?.pushEvent(event, properties)
118-
}
117+
Log.d("Wrapper: Leanplum.track will call pushEvent with $event and $properties")
118+
cleverTapInstance?.pushEvent(event, properties)
119119
}
120120

121121
/**
@@ -127,8 +127,6 @@ internal class CTWrapper(
127127
currencyCode: String?,
128128
params: Map<String, Any?>?
129129
) {
130-
if (Constants.isNoop()) return
131-
132130
val filteredParams =
133131
params?.mapValues(::mapNotSupportedValues)?.toMutableMap()
134132
?: mutableMapOf()
@@ -143,10 +141,8 @@ internal class CTWrapper(
143141

144142
val items = arrayListOf<HashMap<String, Any?>>()
145143

146-
LeanplumInternal.addStartIssuedHandler {
147-
Log.d("Wrapper: Leanplum.trackPurchase will call pushChargedEvent with $details and $items")
148-
cleverTapInstance?.pushChargedEvent(details, items)
149-
}
144+
Log.d("Wrapper: Leanplum.trackPurchase will call pushChargedEvent with $details and $items")
145+
cleverTapInstance?.pushChargedEvent(details, items)
150146
}
151147

152148
/**
@@ -161,8 +157,6 @@ internal class CTWrapper(
161157
dataSignature: String?,
162158
params: Map<String, Any?>?
163159
) {
164-
if (Constants.isNoop()) return
165-
166160
val filteredParams =
167161
params?.mapValues(::mapNotSupportedValues)?.toMutableMap()
168162
?: mutableMapOf()
@@ -178,10 +172,8 @@ internal class CTWrapper(
178172

179173
val items = arrayListOf<HashMap<String, Any?>>()
180174

181-
LeanplumInternal.addStartIssuedHandler {
182-
Log.d("Wrapper: Leanplum.trackGooglePlayPurchase will call pushChargedEvent with $details and $items")
183-
cleverTapInstance?.pushChargedEvent(details, items)
184-
}
175+
Log.d("Wrapper: Leanplum.trackGooglePlayPurchase will call pushChargedEvent with $details and $items")
176+
cleverTapInstance?.pushChargedEvent(details, items)
185177
}
186178

187179
/**
@@ -230,29 +222,23 @@ internal class CTWrapper(
230222

231223
private fun mapNotSupportedValues(entry: Map.Entry<String, Any?>): Any? {
232224
return when (val value = entry.value) {
233-
is Iterable<*> -> value.joinToString(separator = ",", prefix = "[", postfix = "]")
225+
is Iterable<*> ->
226+
value
227+
.filterNotNull()
228+
.joinToString(separator = ",", prefix = "[", postfix = "]")
234229
is Byte -> value.toInt()
235230
is Short -> value.toInt()
236231
else -> value
237232
}
238233
}
239234

240235
override fun setTrafficSourceInfo(info: Map<String, String>) {
241-
val event = MigrationConstants.UTM_VISITED
242-
val properties = info.mapKeys { (key, _) ->
243-
when (key) {
244-
"publisherId" -> "utm_source_id"
245-
"publisherName" -> "utm_source"
246-
"publisherSubPublisher" -> "utm_medium"
247-
"publisherSubSite" -> "utm_subscribe.site"
248-
"publisherSubCampaign" -> "utm_campaign"
249-
"publisherSubAdGroup" -> "utm_sourcepublisher.ad_group"
250-
"publisherSubAd" -> "utm_SourcePublisher.ad"
251-
else -> key
252-
}
253-
}
254-
Log.d("Wrapper: Leanplum.setTrafficSourceInfo will call pushEvent with $event and $properties")
255-
cleverTapInstance?.pushEvent(event, properties)
236+
val source = info["publisherName"]
237+
val medium = info["publisherSubPublisher"]
238+
val campaign = info["publisherSubCampaign"]
239+
Log.d("Wrapper: Leanplum.setTrafficSourceInfo will call pushInstallReferrer with " +
240+
"$source, $medium, and $campaign")
241+
cleverTapInstance?.pushInstallReferrer(source, medium, campaign)
256242
}
257243

258244
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@ interface IWrapper {
5353

5454
fun registerLifecycleCallback(app: Application) = Unit
5555

56-
fun setLogLevel(level: Int) = Unit
56+
fun setLogLevel(lpLevel: Int) = Unit
5757

5858
}

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,7 @@ internal class IdentityManager(
7979
}
8080
}
8181

82-
private fun identity(): String {
83-
return when (val userId = userId) {
84-
deviceId -> deviceId
85-
else -> userId
86-
}
87-
}
88-
89-
fun profile() = mapOf(MigrationConstants.IDENTITY to identity())
82+
fun profile() = mapOf(MigrationConstants.IDENTITY to userId)
9083

9184
fun setUserId(userId: String) {
9285
if (state == ANONYMOUS) {

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.app.Application
44
import com.clevertap.android.sdk.ActivityLifecycleCallback
55
import com.clevertap.android.sdk.CleverTapAPI
66
import com.leanplum.internal.Log
7+
import com.leanplum.migration.MigrationConstants
78

89
/**
910
* Singleton wrapping the static utility methods of CT SDK, used as a delegate from [CTWrapper].
@@ -17,14 +18,8 @@ object StaticMethodsWrapper : IWrapper {
1718
ActivityLifecycleCallback.register(app)
1819
}
1920

20-
override fun setLogLevel(level: Int) {
21-
when(level) {
22-
Log.Level.OFF -> CleverTapAPI.setDebugLevel(CleverTapAPI.LogLevel.OFF)
23-
Log.Level.ERROR -> CleverTapAPI.setDebugLevel(CleverTapAPI.LogLevel.INFO)
24-
Log.Level.INFO -> CleverTapAPI.setDebugLevel(CleverTapAPI.LogLevel.INFO)
25-
Log.Level.DEBUG -> CleverTapAPI.setDebugLevel(CleverTapAPI.LogLevel.VERBOSE)
26-
else -> Unit
27-
}
21+
override fun setLogLevel(lpLevel: Int) {
22+
CleverTapAPI.setDebugLevel(MigrationConstants.mapLogLevel(lpLevel))
2823
}
2924

3025
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.leanplum.migration.wrapper
22

33
import com.leanplum.Leanplum
44
import com.leanplum.callbacks.CleverTapInstanceCallback
5+
import com.leanplum.internal.Constants
56
import com.leanplum.internal.LeanplumInternal
67
import com.leanplum.migration.model.MigrationConfig
78

@@ -33,7 +34,4 @@ internal object WrapperFactory {
3334
}
3435
}
3536

36-
fun createNullWrapper(): IWrapper {
37-
return NullWrapper
38-
}
3937
}

0 commit comments

Comments
 (0)