diff --git a/components-core/src/main/java/com/adyen/checkout/components/core/internal/analytics/AnalyticsManagerFactory.kt b/components-core/src/main/java/com/adyen/checkout/components/core/internal/analytics/AnalyticsManagerFactory.kt index 9171ee7c03..fb701287ba 100644 --- a/components-core/src/main/java/com/adyen/checkout/components/core/internal/analytics/AnalyticsManagerFactory.kt +++ b/components-core/src/main/java/com/adyen/checkout/components/core/internal/analytics/AnalyticsManagerFactory.kt @@ -74,6 +74,7 @@ class AnalyticsManagerFactory { application = application, shopperLocale = shopperLocale, isCreatedByDropIn = isCreatedByDropIn, + analyticsLevel = analyticsParams.level, amount = amount, source = source, sessionId = sessionId, diff --git a/components-core/src/main/java/com/adyen/checkout/components/core/internal/analytics/data/remote/DefaultAnalyticsSetupProvider.kt b/components-core/src/main/java/com/adyen/checkout/components/core/internal/analytics/data/remote/DefaultAnalyticsSetupProvider.kt index 50473beac8..a5d0927923 100644 --- a/components-core/src/main/java/com/adyen/checkout/components/core/internal/analytics/data/remote/DefaultAnalyticsSetupProvider.kt +++ b/components-core/src/main/java/com/adyen/checkout/components/core/internal/analytics/data/remote/DefaultAnalyticsSetupProvider.kt @@ -14,12 +14,15 @@ import com.adyen.checkout.components.core.Amount import com.adyen.checkout.components.core.internal.analytics.AnalyticsPlatformParams import com.adyen.checkout.components.core.internal.analytics.AnalyticsSource import com.adyen.checkout.components.core.internal.data.model.AnalyticsSetupRequest +import com.adyen.checkout.components.core.internal.ui.model.AnalyticsParamsLevel import java.util.Locale +@Suppress("LongParameterList") internal class DefaultAnalyticsSetupProvider( private val application: Application, private val shopperLocale: Locale, private val isCreatedByDropIn: Boolean, + private val analyticsLevel: AnalyticsParamsLevel, private val amount: Amount?, private val source: AnalyticsSource, private val sessionId: String?, @@ -33,6 +36,7 @@ internal class DefaultAnalyticsSetupProvider( locale = shopperLocale.toLanguageTag(), component = getComponentQueryParameter(source), flavor = getFlavorQueryParameter(isCreatedByDropIn), + level = getLevelQueryParameter(analyticsLevel), deviceBrand = Build.BRAND, deviceModel = Build.MODEL, referrer = application.packageName, @@ -57,8 +61,16 @@ internal class DefaultAnalyticsSetupProvider( is AnalyticsSource.PaymentComponent -> source.paymentMethodType } + private fun getLevelQueryParameter(analyticsParamsLevel: AnalyticsParamsLevel) = when (analyticsParamsLevel) { + AnalyticsParamsLevel.INITIAL -> ANALYTICS_LEVEL_INITIAL + AnalyticsParamsLevel.ALL -> ANALYTICS_LEVEL_ALL + } + companion object { private const val DROP_IN = "dropin" private const val COMPONENTS = "components" + + private const val ANALYTICS_LEVEL_INITIAL = "initial" + private const val ANALYTICS_LEVEL_ALL = "all" } } diff --git a/components-core/src/main/java/com/adyen/checkout/components/core/internal/data/model/AnalyticsSetupRequest.kt b/components-core/src/main/java/com/adyen/checkout/components/core/internal/data/model/AnalyticsSetupRequest.kt index cfedef7b1d..b5e62c5ef4 100644 --- a/components-core/src/main/java/com/adyen/checkout/components/core/internal/data/model/AnalyticsSetupRequest.kt +++ b/components-core/src/main/java/com/adyen/checkout/components/core/internal/data/model/AnalyticsSetupRequest.kt @@ -29,6 +29,7 @@ internal data class AnalyticsSetupRequest( val locale: String?, val component: String?, val flavor: String?, + val level: String?, val deviceBrand: String?, val deviceModel: String?, val referrer: String?, @@ -47,6 +48,7 @@ internal data class AnalyticsSetupRequest( private const val LOCALE = "locale" private const val COMPONENT = "component" private const val FLAVOR = "flavor" + private const val LEVEL = "level" private const val DEVICE_BRAND = "deviceBrand" private const val DEVICE_MODEL = "deviceModel" private const val REFERRER = "referrer" @@ -68,6 +70,7 @@ internal data class AnalyticsSetupRequest( putOpt(LOCALE, modelObject.locale) putOpt(COMPONENT, modelObject.component) putOpt(FLAVOR, modelObject.flavor) + putOpt(LEVEL, modelObject.level) putOpt(DEVICE_BRAND, modelObject.deviceBrand) putOpt(DEVICE_MODEL, modelObject.deviceModel) putOpt(REFERRER, modelObject.referrer) @@ -93,6 +96,7 @@ internal data class AnalyticsSetupRequest( locale = getStringOrNull(LOCALE), component = getStringOrNull(COMPONENT), flavor = getStringOrNull(FLAVOR), + level = getStringOrNull(LEVEL), deviceBrand = getStringOrNull(DEVICE_BRAND), deviceModel = getStringOrNull(DEVICE_MODEL), referrer = getStringOrNull(REFERRER), diff --git a/components-core/src/test/java/com/adyen/checkout/components/core/internal/analytics/data/remote/DefaultAnalyticsSetupProviderTest.kt b/components-core/src/test/java/com/adyen/checkout/components/core/internal/analytics/data/remote/DefaultAnalyticsSetupProviderTest.kt index 4ce23be7e7..e793cbb8ea 100644 --- a/components-core/src/test/java/com/adyen/checkout/components/core/internal/analytics/data/remote/DefaultAnalyticsSetupProviderTest.kt +++ b/components-core/src/test/java/com/adyen/checkout/components/core/internal/analytics/data/remote/DefaultAnalyticsSetupProviderTest.kt @@ -8,6 +8,7 @@ import com.adyen.checkout.components.core.Amount import com.adyen.checkout.components.core.internal.analytics.AnalyticsPlatformParams import com.adyen.checkout.components.core.internal.analytics.AnalyticsSource import com.adyen.checkout.components.core.internal.data.model.AnalyticsSetupRequest +import com.adyen.checkout.components.core.internal.ui.model.AnalyticsParamsLevel import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import org.mockito.kotlin.doReturn @@ -25,6 +26,7 @@ internal class DefaultAnalyticsSetupProviderTest { application = createMockApplication(), shopperLocale = Locale.US, isCreatedByDropIn = false, + analyticsLevel = AnalyticsParamsLevel.INITIAL, amount = Amount("USD", 123), source = AnalyticsSource.PaymentComponent("scheme"), sessionId = "sessionId", @@ -39,6 +41,7 @@ internal class DefaultAnalyticsSetupProviderTest { locale = Locale.US.toLanguageTag(), component = "scheme", flavor = "components", + level = "initial", deviceBrand = Build.BRAND, deviceModel = Build.MODEL, referrer = "com.adyen.checkout", @@ -58,6 +61,7 @@ internal class DefaultAnalyticsSetupProviderTest { application = createMockApplication(), shopperLocale = Locale.US, isCreatedByDropIn = true, + analyticsLevel = AnalyticsParamsLevel.INITIAL, amount = Amount("USD", 123), source = AnalyticsSource.PaymentComponent("scheme"), sessionId = "sessionId", @@ -74,6 +78,7 @@ internal class DefaultAnalyticsSetupProviderTest { application = createMockApplication(), shopperLocale = Locale.US, isCreatedByDropIn = false, + analyticsLevel = AnalyticsParamsLevel.INITIAL, amount = Amount("USD", 123), source = AnalyticsSource.PaymentComponent("scheme"), sessionId = "sessionId", @@ -90,6 +95,7 @@ internal class DefaultAnalyticsSetupProviderTest { application = createMockApplication(), shopperLocale = Locale.US, isCreatedByDropIn = true, + analyticsLevel = AnalyticsParamsLevel.INITIAL, amount = Amount("USD", 123), source = AnalyticsSource.DropIn(listOf()), sessionId = "sessionId", @@ -106,6 +112,7 @@ internal class DefaultAnalyticsSetupProviderTest { application = createMockApplication(), shopperLocale = Locale.US, isCreatedByDropIn = true, + analyticsLevel = AnalyticsParamsLevel.INITIAL, amount = Amount("USD", 123), source = AnalyticsSource.PaymentComponent("scheme"), sessionId = "sessionId", @@ -116,6 +123,40 @@ internal class DefaultAnalyticsSetupProviderTest { assertEquals("scheme", result.component) } + @Test + fun `when analytics params level is initial, then level should be initial`() { + analyticsSetupProvider = DefaultAnalyticsSetupProvider( + application = createMockApplication(), + shopperLocale = Locale.US, + isCreatedByDropIn = false, + analyticsLevel = AnalyticsParamsLevel.INITIAL, + amount = Amount("USD", 123), + source = AnalyticsSource.PaymentComponent("scheme"), + sessionId = "sessionId", + ) + + val result = analyticsSetupProvider.provide() + + assertEquals("initial", result.level) + } + + @Test + fun `when analytics params level is all, then level should be all`() { + analyticsSetupProvider = DefaultAnalyticsSetupProvider( + application = createMockApplication(), + shopperLocale = Locale.US, + isCreatedByDropIn = false, + analyticsLevel = AnalyticsParamsLevel.ALL, + amount = Amount("USD", 123), + source = AnalyticsSource.PaymentComponent("scheme"), + sessionId = "sessionId", + ) + + val result = analyticsSetupProvider.provide() + + assertEquals("all", result.level) + } + private fun createMockApplication(): Application { val application = mock() val resources = mock() diff --git a/components-core/src/test/java/com/adyen/checkout/components/core/internal/data/model/AnalyticsSetupRequestTest.kt b/components-core/src/test/java/com/adyen/checkout/components/core/internal/data/model/AnalyticsSetupRequestTest.kt index b533f02035..25da8403f1 100644 --- a/components-core/src/test/java/com/adyen/checkout/components/core/internal/data/model/AnalyticsSetupRequestTest.kt +++ b/components-core/src/test/java/com/adyen/checkout/components/core/internal/data/model/AnalyticsSetupRequestTest.kt @@ -17,6 +17,7 @@ internal class AnalyticsSetupRequestTest { locale = "en-US", component = "dropin", flavor = "dropin", + level = "all", deviceBrand = "Google", deviceModel = "Pixel", referrer = "unknown", @@ -37,6 +38,7 @@ internal class AnalyticsSetupRequestTest { .put("locale", "en-US") .put("component", "dropin") .put("flavor", "dropin") + .put("level", "all") .put("deviceBrand", "Google") .put("deviceModel", "Pixel") .put("referrer", "unknown") @@ -59,6 +61,7 @@ internal class AnalyticsSetupRequestTest { .put("locale", "en-US") .put("component", "dropin") .put("flavor", "dropin") + .put("level", "all") .put("deviceBrand", "Google") .put("deviceModel", "Pixel") .put("referrer", "unknown") @@ -78,6 +81,7 @@ internal class AnalyticsSetupRequestTest { locale = "en-US", component = "dropin", flavor = "dropin", + level = "all", deviceBrand = "Google", deviceModel = "Pixel", referrer = "unknown",