Skip to content

Commit

Permalink
Merge pull request #15 from edx/omer/LEARNER-10094
Browse files Browse the repository at this point in the history
fix: update IAP analytics keys for price
  • Loading branch information
omerhabib26 authored Jul 23, 2024
2 parents 0a0b1cf + 3d1b2dd commit 12056d2
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 7 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 @@ -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"),
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 @@ -337,7 +339,7 @@ class IAPViewModel(

private fun logIAPEvent(
event: IAPAnalyticsEvent,
params: MutableMap<String, Any?> = mutableMapOf()
params: MutableMap<String, Any?> = mutableMapOf(),
) {
analytics.logIAPEvent(
event = event,
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
)

0 comments on commit 12056d2

Please sign in to comment.