Skip to content

Commit

Permalink
Send level as part of the initial analytics request
Browse files Browse the repository at this point in the history
COAND-1029
  • Loading branch information
araratthehero committed Oct 31, 2024
1 parent c76b396 commit 59083c1
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class AnalyticsManagerFactory {
application = application,
shopperLocale = shopperLocale,
isCreatedByDropIn = isCreatedByDropIn,
analyticsLevel = analyticsParams.level,
amount = amount,
source = source,
sessionId = sessionId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?,
Expand All @@ -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,
Expand All @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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?,
Expand All @@ -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"
Expand All @@ -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)
Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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<Application>()
val resources = mock<Resources>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ internal class AnalyticsSetupRequestTest {
locale = "en-US",
component = "dropin",
flavor = "dropin",
level = "all",
deviceBrand = "Google",
deviceModel = "Pixel",
referrer = "unknown",
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -78,6 +81,7 @@ internal class AnalyticsSetupRequestTest {
locale = "en-US",
component = "dropin",
flavor = "dropin",
level = "all",
deviceBrand = "Google",
deviceModel = "Pixel",
referrer = "unknown",
Expand Down

0 comments on commit 59083c1

Please sign in to comment.