Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analytics - Level field #1856

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ internal class Adyen3DS2ComponentParamsMapperTest {
shopperLocale = Locale.GERMAN,
environment = Environment.EUROPE,
clientKey = TEST_CLIENT_KEY_2,
analyticsParams = AnalyticsParams(AnalyticsParamsLevel.NONE, TEST_CLIENT_KEY_2),
analyticsParams = AnalyticsParams(AnalyticsParamsLevel.INITIAL, TEST_CLIENT_KEY_2),
isCreatedByDropIn = true,
amount = Amount(
currency = "CAD",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ internal class ACHDirectDebitComponentParamsMapperTest {
shopperLocale = Locale.GERMAN,
environment = Environment.EUROPE,
clientKey = TEST_CLIENT_KEY_2,
analyticsParams = AnalyticsParams(AnalyticsParamsLevel.NONE, TEST_CLIENT_KEY_2),
analyticsParams = AnalyticsParams(AnalyticsParamsLevel.INITIAL, TEST_CLIENT_KEY_2),
isCreatedByDropIn = true,
amount = Amount(
currency = "EUR",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ internal class BcmcComponentParamsMapperTest {
shopperLocale = Locale.GERMAN,
environment = Environment.EUROPE,
clientKey = TEST_CLIENT_KEY_2,
analyticsParams = AnalyticsParams(AnalyticsParamsLevel.NONE, TEST_CLIENT_KEY_2),
analyticsParams = AnalyticsParams(AnalyticsParamsLevel.INITIAL, TEST_CLIENT_KEY_2),
isCreatedByDropIn = true,
amount = Amount(
currency = "CAD",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ internal class BoletoComponentParamsMapperTest {
shopperLocale = Locale.GERMAN,
environment = Environment.EUROPE,
clientKey = TEST_CLIENT_KEY_2,
analyticsParams = AnalyticsParams(AnalyticsParamsLevel.NONE, TEST_CLIENT_KEY_2),
analyticsParams = AnalyticsParams(AnalyticsParamsLevel.INITIAL, TEST_CLIENT_KEY_2),
isCreatedByDropIn = true,
amount = Amount(
currency = "EUR",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ internal class CardComponentParamsMapperTest {
shopperLocale = Locale.GERMAN,
environment = Environment.EUROPE,
clientKey = TEST_CLIENT_KEY_2,
analyticsParams = AnalyticsParams(AnalyticsParamsLevel.NONE, TEST_CLIENT_KEY_2),
analyticsParams = AnalyticsParams(AnalyticsParamsLevel.INITIAL, TEST_CLIENT_KEY_2),
isCreatedByDropIn = true,
amount = Amount(
currency = "EUR",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ internal class CashAppPayComponentParamsMapperTest {
environment = Environment.EUROPE,
cashAppPayEnvironment = CashAppPayEnvironment.PRODUCTION,
clientKey = TEST_CLIENT_KEY_2,
analyticsParams = AnalyticsParams(AnalyticsParamsLevel.NONE, TEST_CLIENT_KEY_2),
analyticsParams = AnalyticsParams(AnalyticsParamsLevel.INITIAL, TEST_CLIENT_KEY_2),
isCreatedByDropIn = true,
amount = Amount(
currency = "EUR",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class CheckoutConfiguration(
environment = requireNotNull(parcel.readParcelable(Environment::class.java.classLoader)),
clientKey = requireNotNull(parcel.readString()),
amount = parcel.readParcelable(Amount::class.java.classLoader),
analyticsConfiguration = parcel.readParcelable(Amount::class.java.classLoader),
analyticsConfiguration = parcel.readParcelable(AnalyticsConfiguration::class.java.classLoader),
) {
val size = parcel.readInt()

Expand Down
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 @@ -125,7 +125,7 @@ internal class DefaultAnalyticsManager(
CheckoutAttemptIdState.NotAvailable -> CHECKOUT_ATTEMPT_ID_NOT_FETCHED
}

private fun cannotSendEvents() = analyticsParams.level.priority <= AnalyticsParamsLevel.NONE.priority
private fun cannotSendEvents() = analyticsParams.level.priority <= AnalyticsParamsLevel.INITIAL.priority

override fun clear(owner: Any) {
if (ownerReference != owner::class.qualifiedName) {
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 @@ -26,14 +26,14 @@ data class AnalyticsParams(

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
enum class AnalyticsParamsLevel(val priority: Int) {
NONE(1),
INITIAL(1),
ALL(2),
}

private fun getLevel(analyticsConfiguration: AnalyticsConfiguration?): AnalyticsParamsLevel {
return when (analyticsConfiguration?.level) {
null -> AnalyticsParamsLevel.ALL // default is ALL
AnalyticsLevel.ALL -> AnalyticsParamsLevel.ALL
AnalyticsLevel.NONE -> AnalyticsParamsLevel.NONE
AnalyticsLevel.NONE -> AnalyticsParamsLevel.INITIAL
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ internal class DefaultAnalyticsManagerTest(
}

@Test
fun `sending events is disabled, then checkoutAttemptId is still set`() = runTest {
analyticsManager = createAnalyticsManager(AnalyticsParamsLevel.NONE)
fun `analytics level is initial, then checkoutAttemptId is still set`() = runTest {
analyticsManager = createAnalyticsManager(AnalyticsParamsLevel.INITIAL)
whenever(analyticsRepository.fetchCheckoutAttemptId()) doReturn "test value"

analyticsManager.initialize(this@InitializeTest, this)
Expand Down Expand Up @@ -95,8 +95,8 @@ internal class DefaultAnalyticsManagerTest(
inner class TrackEventTest {

@Test
fun `sending events is disabled, then events should not be stored`() = runTest {
analyticsManager = createAnalyticsManager(AnalyticsParamsLevel.NONE)
fun `analytics level is initial, then events should not be stored`() = runTest {
analyticsManager = createAnalyticsManager(AnalyticsParamsLevel.INITIAL)
analyticsManager.initialize(this@TrackEventTest, this)

analyticsManager.trackEvent(GenericEvents.rendered("dropin", false))
Expand Down Expand Up @@ -140,8 +140,8 @@ internal class DefaultAnalyticsManagerTest(
inner class SendEventTest {

@Test
fun `sending events is disabled, then events are not sent`() = runTest {
analyticsManager = createAnalyticsManager(AnalyticsParamsLevel.NONE)
fun `analytics level is initial, then events are not sent`() = runTest {
analyticsManager = createAnalyticsManager(AnalyticsParamsLevel.INITIAL)
analyticsManager.initialize(this@SendEventTest, this)
val event = AnalyticsEvent.Info(
component = "test",
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
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ internal class ButtonComponentParamsMapperTest {
shopperLocale = Locale.GERMAN,
environment = Environment.EUROPE,
clientKey = TEST_CLIENT_KEY_2,
analyticsParams = AnalyticsParams(AnalyticsParamsLevel.NONE, TEST_CLIENT_KEY_2),
analyticsParams = AnalyticsParams(AnalyticsParamsLevel.INITIAL, TEST_CLIENT_KEY_2),
isCreatedByDropIn = true,
amount = Amount(
currency = "USD",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ internal class GenericComponentParamsMapperTest {
shopperLocale = Locale.GERMAN,
environment = Environment.EUROPE,
clientKey = TEST_CLIENT_KEY_2,
analyticsParams = AnalyticsParams(AnalyticsParamsLevel.NONE, TEST_CLIENT_KEY_2),
analyticsParams = AnalyticsParams(AnalyticsParamsLevel.INITIAL, TEST_CLIENT_KEY_2),
isCreatedByDropIn = true,
amount = Amount(
currency = "CAD",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ internal class DropInParamsMapperTest {
shopperLocale = Locale.GERMAN,
environment = Environment.EUROPE,
clientKey = TEST_CLIENT_KEY_2,
analyticsParams = AnalyticsParams(AnalyticsParamsLevel.NONE, TEST_CLIENT_KEY_2),
analyticsParams = AnalyticsParams(AnalyticsParamsLevel.INITIAL, TEST_CLIENT_KEY_2),
amount = Amount(
currency = "EUR",
value = 49_00L,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ internal class GiftCardComponentParamsMapperTest {
shopperLocale = Locale.GERMAN,
environment = Environment.EUROPE,
clientKey = TEST_CLIENT_KEY_2,
analyticsParams = AnalyticsParams(AnalyticsParamsLevel.NONE, TEST_CLIENT_KEY_2),
analyticsParams = AnalyticsParams(AnalyticsParamsLevel.INITIAL, TEST_CLIENT_KEY_2),
isCreatedByDropIn = true,
amount = Amount(
currency = "CAD",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ internal class GooglePayComponentParamsMapperTest {
environment = Environment.EUROPE,
clientKey = TEST_CLIENT_KEY_2,
googlePayEnvironment = WalletConstants.ENVIRONMENT_PRODUCTION,
analyticsParams = AnalyticsParams(AnalyticsParamsLevel.NONE, TEST_CLIENT_KEY_2),
analyticsParams = AnalyticsParams(AnalyticsParamsLevel.INITIAL, TEST_CLIENT_KEY_2),
isCreatedByDropIn = true,
amount = Amount(
currency = "CAD",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ internal class GooglePayUtilsTest {
shopperLocale = Locale.GERMAN,
environment = Environment.EUROPE,
clientKey = "CLIENT_KEY_CUSTOM",
analyticsParams = AnalyticsParams(AnalyticsParamsLevel.NONE, "CLIENT_KEY_CUSTOM"),
analyticsParams = AnalyticsParams(AnalyticsParamsLevel.INITIAL, "CLIENT_KEY_CUSTOM"),
isCreatedByDropIn = true,
amount = Amount("EUR", 13_37),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ internal class IssuerListComponentParamsMapperTest {
shopperLocale = Locale.GERMAN,
environment = Environment.EUROPE,
clientKey = TEST_CLIENT_KEY_2,
analyticsParams = AnalyticsParams(AnalyticsParamsLevel.NONE, TEST_CLIENT_KEY_2),
analyticsParams = AnalyticsParams(AnalyticsParamsLevel.INITIAL, TEST_CLIENT_KEY_2),
isCreatedByDropIn = true,
viewType = IssuerListViewType.SPINNER_VIEW,
hideIssuerLogos = true,
Expand Down
Loading