From 3d1b2dd44b1ff4816f86fdd1dbcb2ae8e05a19cc Mon Sep 17 00:00:00 2001 From: "omer.habib" Date: Mon, 22 Jul 2024 18:05:55 +0500 Subject: [PATCH] fix: update IAP analytics keys for price - Added lms_usd_price, localized_price, localized_currency_code in IAP analytics. fix: LEARNER-10094 --- .../core/data/model/CourseStructureModel.kt | 6 +++++- .../org/openedx/core/data/model/EnrolledCourse.kt | 6 +++++- .../openedx/core/domain/model/iap/ProductInfo.kt | 1 + .../java/org/openedx/core/extension/DoubleExt.kt | 5 +++++ .../org/openedx/core/presentation/IAPAnalytics.kt | 4 +++- .../openedx/core/presentation/iap/IAPViewModel.kt | 14 +++++++++++--- .../presentation/DashboardListFragment.kt | 6 +++++- 7 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 core/src/main/java/org/openedx/core/extension/DoubleExt.kt diff --git a/core/src/main/java/org/openedx/core/data/model/CourseStructureModel.kt b/core/src/main/java/org/openedx/core/data/model/CourseStructureModel.kt index 1fca6e677..9aba5482b 100644 --- a/core/src/main/java/org/openedx/core/data/model/CourseStructureModel.kt +++ b/core/src/main/java/org/openedx/core/data/model/CourseStructureModel.kt @@ -77,7 +77,11 @@ data class CourseStructureModel( }?.takeIf { it.androidSku.isNullOrEmpty().not() && it.storeSku.isNullOrEmpty().not() }?.run { - ProductInfo(courseSku = androidSku!!, storeSku = storeSku!!) + ProductInfo( + courseSku = androidSku!!, + storeSku = storeSku!!, + lmsUSDPrice = price ?: 0.0 + ) } ) } diff --git a/core/src/main/java/org/openedx/core/data/model/EnrolledCourse.kt b/core/src/main/java/org/openedx/core/data/model/EnrolledCourse.kt index 54aa5e88a..05cb07fde 100644 --- a/core/src/main/java/org/openedx/core/data/model/EnrolledCourse.kt +++ b/core/src/main/java/org/openedx/core/data/model/EnrolledCourse.kt @@ -47,7 +47,11 @@ data class EnrolledCourse( }?.takeIf { it.androidSku.isNullOrEmpty().not() && it.storeSku.isNullOrEmpty().not() }?.run { - ProductInfo(courseSku = androidSku!!, storeSku = storeSku!!) + ProductInfo( + courseSku = androidSku!!, + storeSku = storeSku!!, + lmsUSDPrice = price ?: 0.0 + ) } ) } diff --git a/core/src/main/java/org/openedx/core/domain/model/iap/ProductInfo.kt b/core/src/main/java/org/openedx/core/domain/model/iap/ProductInfo.kt index b9e5da3d4..0969e1090 100644 --- a/core/src/main/java/org/openedx/core/domain/model/iap/ProductInfo.kt +++ b/core/src/main/java/org/openedx/core/domain/model/iap/ProductInfo.kt @@ -7,4 +7,5 @@ import kotlinx.parcelize.Parcelize data class ProductInfo( val courseSku: String, val storeSku: String, + val lmsUSDPrice: Double, ) : Parcelable diff --git a/core/src/main/java/org/openedx/core/extension/DoubleExt.kt b/core/src/main/java/org/openedx/core/extension/DoubleExt.kt new file mode 100644 index 000000000..62505f618 --- /dev/null +++ b/core/src/main/java/org/openedx/core/extension/DoubleExt.kt @@ -0,0 +1,5 @@ +package org.openedx.core.extension + +fun Double.nonZero(): Double? { + return if (this != 0.0) this else null +} diff --git a/core/src/main/java/org/openedx/core/presentation/IAPAnalytics.kt b/core/src/main/java/org/openedx/core/presentation/IAPAnalytics.kt index 63f548b95..87d2e8ad2 100644 --- a/core/src/main/java/org/openedx/core/presentation/IAPAnalytics.kt +++ b/core/src/main/java/org/openedx/core/presentation/IAPAnalytics.kt @@ -57,7 +57,9 @@ enum class IAPAnalyticsKeys(val key: String) { SELF("self"), INSTRUCTOR("instructor"), IAP_FLOW_TYPE("flow_type"), - PRICE("price"), + LMS_USD_PRICE("lms_usd_price"), + LOCALIZED_PRICE("localized_price"), + CURRENCY_CODE("localized_currency_code"), COMPONENT_ID("component_id"), ELAPSED_TIME("elapsed_time"), ERROR("error"), diff --git a/core/src/main/java/org/openedx/core/presentation/iap/IAPViewModel.kt b/core/src/main/java/org/openedx/core/presentation/iap/IAPViewModel.kt index 5ea0a4964..1f0592de3 100644 --- a/core/src/main/java/org/openedx/core/presentation/iap/IAPViewModel.kt +++ b/core/src/main/java/org/openedx/core/presentation/iap/IAPViewModel.kt @@ -24,6 +24,8 @@ import org.openedx.core.data.storage.CorePreferences import org.openedx.core.domain.interactor.IAPInteractor import org.openedx.core.domain.model.iap.PurchaseFlowData import org.openedx.core.exception.iap.IAPException +import org.openedx.core.extension.nonZero +import org.openedx.core.extension.takeIfNotEmpty import org.openedx.core.module.billing.BillingProcessor import org.openedx.core.module.billing.getCourseSku import org.openedx.core.module.billing.getPriceAmount @@ -337,7 +339,7 @@ class IAPViewModel( private fun logIAPEvent( event: IAPAnalyticsEvent, - params: MutableMap = mutableMapOf() + params: MutableMap = mutableMapOf(), ) { analytics.logIAPEvent( event = event, @@ -350,8 +352,14 @@ class IAPViewModel( if (purchaseFlowData.isSelfPaced == true) IAPAnalyticsKeys.SELF.key else IAPAnalyticsKeys.INSTRUCTOR.key ) } - purchaseFlowData.formattedPrice?.takeIf { it.isNotBlank() }?.let { formattedPrice -> - put(IAPAnalyticsKeys.PRICE.key, formattedPrice) + purchaseFlowData.productInfo?.lmsUSDPrice?.nonZero()?.let { lmsUSDPrice -> + put(IAPAnalyticsKeys.LMS_USD_PRICE.key, lmsUSDPrice) + } + purchaseFlowData.price.nonZero()?.let { localizedPrice -> + put(IAPAnalyticsKeys.LOCALIZED_PRICE.key, localizedPrice) + } + purchaseFlowData.currencyCode.takeIfNotEmpty()?.let { currencyCode -> + put(IAPAnalyticsKeys.CURRENCY_CODE.key, currencyCode) } purchaseFlowData.componentId?.takeIf { it.isNotBlank() }?.let { componentId -> put(IAPAnalyticsKeys.COMPONENT_ID.key, componentId) diff --git a/dashboard/src/main/java/org/openedx/dashboard/presentation/DashboardListFragment.kt b/dashboard/src/main/java/org/openedx/dashboard/presentation/DashboardListFragment.kt index e89427607..1a38fad14 100644 --- a/dashboard/src/main/java/org/openedx/dashboard/presentation/DashboardListFragment.kt +++ b/dashboard/src/main/java/org/openedx/dashboard/presentation/DashboardListFragment.kt @@ -687,5 +687,9 @@ private val mockCourseEnrolled = EnrolledCourse( videoOutline = "", isSelfPaced = false ), - productInfo = ProductInfo(courseSku = "example_sku", storeSku = "mobile.android.example_100") + productInfo = ProductInfo( + courseSku = "example_sku", + storeSku = "mobile.android.example_100", + lmsUSDPrice = 99.9 + ) )