Skip to content

Commit

Permalink
fix: update IAP analytics keys for price
Browse files Browse the repository at this point in the history
- Added lms_usd_price, localized_price, localized_currency_code in IAP analytics.

fix: LEARNER-10094
  • Loading branch information
omerhabib26 committed Jul 22, 2024
1 parent b206ef2 commit 24086ac
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ import kotlinx.parcelize.Parcelize
data class ProductInfo(
val courseSku: String,
val storeSku: String,
val lmsUSDPrice: Double,
) : Parcelable
5 changes: 5 additions & 0 deletions core/src/main/java/org/openedx/core/extension/DoubleExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.openedx.core.extension

fun Double.nonZero(): Double? {
return if (this != 0.0) this else null
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -348,8 +350,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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -736,5 +736,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
)
)

0 comments on commit 24086ac

Please sign in to comment.