Skip to content

Commit

Permalink
Rename variable names used in analytics for better understanding.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnirudhBhat committed Jan 30, 2025
1 parent dd61dda commit 91c4324
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@ import com.woocommerce.android.extensions.isTwoPanesShouldBeUsed

val Context.deviceTypeToAnalyticsString: String
get() = buildAnalyticsDeviceTypeValue(
IsScreenLargerThanCompactValue(value = isTwoPanesShouldBeUsed)
IsScreenInTwoPaneLayout(value = isTwoPanesShouldBeUsed)
)

val IsScreenLargerThanCompactValue.deviceTypeToAnalyticsString: String
val IsScreenInTwoPaneLayout.deviceTypeToAnalyticsString: String
get() = buildAnalyticsDeviceTypeValue(this)

private fun buildAnalyticsDeviceTypeValue(isScreenSizeLargerThanCompact: IsScreenLargerThanCompactValue) =
if (isScreenSizeLargerThanCompact.value) {
VALUE_DEVICE_TYPE_REGULAR
private fun buildAnalyticsDeviceTypeValue(isScreenInTwoPaneLayout: IsScreenInTwoPaneLayout) =
// Keeping the value as it is to maintain backward compatibility with the existing analytics data
if (isScreenInTwoPaneLayout.value) {
VALUE_DEVICE_TYPE_REGULAR // 2 pane layout
} else {
VALUE_DEVICE_TYPE_COMPACT
VALUE_DEVICE_TYPE_COMPACT // Single pane layout
}

@JvmInline
value class IsScreenLargerThanCompactValue(val value: Boolean)
value class IsScreenInTwoPaneLayout(val value: Boolean)
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ import com.woocommerce.android.analytics.AnalyticsTracker.Companion.VALUE_FLOW_C
import com.woocommerce.android.analytics.AnalyticsTracker.Companion.VALUE_FLOW_EDITING
import com.woocommerce.android.analytics.AnalyticsTracker.Companion.VALUE_PRODUCT_CARD
import com.woocommerce.android.analytics.AnalyticsTrackerWrapper
import com.woocommerce.android.analytics.IsScreenLargerThanCompactValue
import com.woocommerce.android.analytics.IsScreenInTwoPaneLayout
import com.woocommerce.android.analytics.deviceTypeToAnalyticsString
import com.woocommerce.android.extensions.isNotNullOrEmpty
import com.woocommerce.android.extensions.runWithContext
Expand Down Expand Up @@ -567,8 +567,8 @@ class OrderCreateEditViewModel @Inject constructor(
handleCouponEditResult(couponEditResult)
}

private fun getScreenSizeClassNameForAnalytics(isTwoPane: Boolean) =
IsScreenLargerThanCompactValue(isTwoPane).deviceTypeToAnalyticsString
private fun getAnalyticsPaneTypeName(isTwoPane: Boolean) =
IsScreenInTwoPaneLayout(isTwoPane).deviceTypeToAnalyticsString

fun onCustomerNoteEdited(newNote: String) {
_orderDraft.value.let { order ->
Expand All @@ -579,7 +579,7 @@ class OrderCreateEditViewModel @Inject constructor(
KEY_STATUS to order.status,
KEY_TYPE to CUSTOMER,
KEY_FLOW to flow,
KEY_HORIZONTAL_SIZE_CLASS to getScreenSizeClassNameForAnalytics(viewState.isTwoPaneLayout)
KEY_HORIZONTAL_SIZE_CLASS to getAnalyticsPaneTypeName(viewState.isTwoPaneLayout)
)
)
}
Expand All @@ -591,7 +591,7 @@ class OrderCreateEditViewModel @Inject constructor(
ORDER_PRODUCT_QUANTITY_CHANGE,
mapOf(
KEY_FLOW to flow,
KEY_HORIZONTAL_SIZE_CLASS to getScreenSizeClassNameForAnalytics(viewState.isTwoPaneLayout)
KEY_HORIZONTAL_SIZE_CLASS to getAnalyticsPaneTypeName(viewState.isTwoPaneLayout)
)
)
_orderDraft.update { adjustProductQuantity(it, id, +1) }
Expand All @@ -606,7 +606,7 @@ class OrderCreateEditViewModel @Inject constructor(
ORDER_PRODUCT_REMOVE,
mapOf(
KEY_FLOW to flow,
KEY_HORIZONTAL_SIZE_CLASS to getScreenSizeClassNameForAnalytics(
KEY_HORIZONTAL_SIZE_CLASS to getAnalyticsPaneTypeName(
viewState.isTwoPaneLayout
)
)
Expand All @@ -616,7 +616,7 @@ class OrderCreateEditViewModel @Inject constructor(
ORDER_PRODUCT_QUANTITY_CHANGE,
mapOf(
KEY_FLOW to flow,
KEY_HORIZONTAL_SIZE_CLASS to getScreenSizeClassNameForAnalytics(viewState.isTwoPaneLayout)
KEY_HORIZONTAL_SIZE_CLASS to getAnalyticsPaneTypeName(viewState.isTwoPaneLayout)
)
)
}
Expand All @@ -630,7 +630,7 @@ class OrderCreateEditViewModel @Inject constructor(
ORDER_PRODUCT_QUANTITY_CHANGE,
mapOf(
KEY_FLOW to flow,
KEY_HORIZONTAL_SIZE_CLASS to getScreenSizeClassNameForAnalytics(viewState.isTwoPaneLayout)
KEY_HORIZONTAL_SIZE_CLASS to getAnalyticsPaneTypeName(viewState.isTwoPaneLayout)
)
)
_orderDraft.update { adjustProductQuantity(it, product, +1) }
Expand All @@ -644,7 +644,7 @@ class OrderCreateEditViewModel @Inject constructor(
ORDER_PRODUCT_QUANTITY_CHANGE,
mapOf(
KEY_FLOW to flow,
KEY_HORIZONTAL_SIZE_CLASS to getScreenSizeClassNameForAnalytics(viewState.isTwoPaneLayout)
KEY_HORIZONTAL_SIZE_CLASS to getAnalyticsPaneTypeName(viewState.isTwoPaneLayout)
)
)
_orderDraft.update { adjustProductQuantity(it, product, -1) }
Expand All @@ -668,7 +668,7 @@ class OrderCreateEditViewModel @Inject constructor(
ORDER_PRODUCT_QUANTITY_CHANGE,
mapOf(
KEY_FLOW to flow,
KEY_HORIZONTAL_SIZE_CLASS to getScreenSizeClassNameForAnalytics(
KEY_HORIZONTAL_SIZE_CLASS to getAnalyticsPaneTypeName(
viewState.isTwoPaneLayout
)
)
Expand All @@ -694,7 +694,7 @@ class OrderCreateEditViewModel @Inject constructor(
KEY_FROM to _orderDraft.value.status.value,
KEY_TO to status.value,
KEY_FLOW to flow,
KEY_HORIZONTAL_SIZE_CLASS to getScreenSizeClassNameForAnalytics(viewState.isTwoPaneLayout),
KEY_HORIZONTAL_SIZE_CLASS to getAnalyticsPaneTypeName(viewState.isTwoPaneLayout),
)
)
_orderDraft.update { it.copy(status = status) }
Expand All @@ -705,7 +705,7 @@ class OrderCreateEditViewModel @Inject constructor(
ORDER_PRODUCT_REMOVE,
mapOf(
KEY_FLOW to flow,
KEY_HORIZONTAL_SIZE_CLASS to getScreenSizeClassNameForAnalytics(viewState.isTwoPaneLayout),
KEY_HORIZONTAL_SIZE_CLASS to getAnalyticsPaneTypeName(viewState.isTwoPaneLayout),
)
)
viewState = viewState.copy(isEditable = false)
Expand All @@ -721,7 +721,7 @@ class OrderCreateEditViewModel @Inject constructor(
mapOf(
KEY_FLOW to flow,
KEY_SOURCE to VALUE_PRODUCT_CARD,
KEY_HORIZONTAL_SIZE_CLASS to getScreenSizeClassNameForAnalytics(viewState.isTwoPaneLayout),
KEY_HORIZONTAL_SIZE_CLASS to getAnalyticsPaneTypeName(viewState.isTwoPaneLayout),
)
)
}
Expand All @@ -748,7 +748,7 @@ class OrderCreateEditViewModel @Inject constructor(
KEY_SCANNING_SOURCE to source.source,
KEY_PRODUCT_ADDED_VIA to addedVia.addedVia,
KEY_HAS_BUNDLE_CONFIGURATION to hasBundleConfiguration,
KEY_HORIZONTAL_SIZE_CLASS to getScreenSizeClassNameForAnalytics(viewState.isTwoPaneLayout),
KEY_HORIZONTAL_SIZE_CLASS to getAnalyticsPaneTypeName(viewState.isTwoPaneLayout),
)
)
} ?: run {
Expand All @@ -759,7 +759,7 @@ class OrderCreateEditViewModel @Inject constructor(
KEY_PRODUCT_COUNT to selectedItems.size,
KEY_PRODUCT_ADDED_VIA to addedVia.addedVia,
KEY_HAS_BUNDLE_CONFIGURATION to hasBundleConfiguration,
KEY_HORIZONTAL_SIZE_CLASS to getScreenSizeClassNameForAnalytics(viewState.isTwoPaneLayout),
KEY_HORIZONTAL_SIZE_CLASS to getAnalyticsPaneTypeName(viewState.isTwoPaneLayout),
)
)
}
Expand Down Expand Up @@ -870,7 +870,7 @@ class OrderCreateEditViewModel @Inject constructor(
tracker.track(
ORDER_CREATION_PRODUCT_BARCODE_SCANNING_TAPPED,
mapOf(
KEY_HORIZONTAL_SIZE_CLASS to getScreenSizeClassNameForAnalytics(viewState.isTwoPaneLayout)
KEY_HORIZONTAL_SIZE_CLASS to getAnalyticsPaneTypeName(viewState.isTwoPaneLayout)
)
)
}
Expand Down Expand Up @@ -1075,7 +1075,7 @@ class OrderCreateEditViewModel @Inject constructor(
PRODUCT_SEARCH_VIA_SKU_SUCCESS,
mapOf(
KEY_SCANNING_SOURCE to source.source,
KEY_HORIZONTAL_SIZE_CLASS to getScreenSizeClassNameForAnalytics(viewState.isTwoPaneLayout)
KEY_HORIZONTAL_SIZE_CLASS to getAnalyticsPaneTypeName(viewState.isTwoPaneLayout)
)
)
}
Expand Down Expand Up @@ -1130,7 +1130,7 @@ class OrderCreateEditViewModel @Inject constructor(
mapOf(
KEY_FLOW to flow,
KEY_HAS_DIFFERENT_SHIPPING_DETAILS to hasDifferentShippingDetails,
KEY_HORIZONTAL_SIZE_CLASS to getScreenSizeClassNameForAnalytics(viewState.isTwoPaneLayout)
KEY_HORIZONTAL_SIZE_CLASS to getAnalyticsPaneTypeName(viewState.isTwoPaneLayout)
)
)

Expand Down Expand Up @@ -1317,7 +1317,7 @@ class OrderCreateEditViewModel @Inject constructor(
mapOf(
KEY_FLOW to flow,
KEY_EXPANDED to newTotalsExpandedState,
KEY_HORIZONTAL_SIZE_CLASS to getScreenSizeClassNameForAnalytics(viewState.isTwoPaneLayout),
KEY_HORIZONTAL_SIZE_CLASS to getAnalyticsPaneTypeName(viewState.isTwoPaneLayout),
)
)
}
Expand All @@ -1337,7 +1337,7 @@ class OrderCreateEditViewModel @Inject constructor(
put(KEY_FLOW, flow)
put(
KEY_HORIZONTAL_SIZE_CLASS,
getScreenSizeClassNameForAnalytics(viewState.isTwoPaneLayout)
getAnalyticsPaneTypeName(viewState.isTwoPaneLayout)
)
}
)
Expand Down Expand Up @@ -1536,7 +1536,7 @@ class OrderCreateEditViewModel @Inject constructor(
KEY_ERROR_TYPE to (it as? WooException)?.error?.type?.name,
KEY_ERROR_DESC to it.message,
KEY_USE_GIFT_CARD to orderDraft.value?.selectedGiftCard.isNotNullOrEmpty(),
KEY_HORIZONTAL_SIZE_CLASS to getScreenSizeClassNameForAnalytics(viewState.isTwoPaneLayout),
KEY_HORIZONTAL_SIZE_CLASS to getAnalyticsPaneTypeName(viewState.isTwoPaneLayout),
)
)
}
Expand Down Expand Up @@ -1616,7 +1616,7 @@ class OrderCreateEditViewModel @Inject constructor(
ORDER_SHIPPING_METHOD_REMOVE,
mapOf(
KEY_FLOW to flow,
KEY_HORIZONTAL_SIZE_CLASS to getScreenSizeClassNameForAnalytics(viewState.isTwoPaneLayout)
KEY_HORIZONTAL_SIZE_CLASS to getAnalyticsPaneTypeName(viewState.isTwoPaneLayout)
)
)
_orderDraft.update { draft ->
Expand Down Expand Up @@ -1675,7 +1675,7 @@ class OrderCreateEditViewModel @Inject constructor(
true -> VALUE_CUSTOM_AMOUNT_TAX_STATUS_TAXABLE
false -> VALUE_CUSTOM_AMOUNT_TAX_STATUS_NONE
},
KEY_HORIZONTAL_SIZE_CLASS to getScreenSizeClassNameForAnalytics(viewState.isTwoPaneLayout),
KEY_HORIZONTAL_SIZE_CLASS to getAnalyticsPaneTypeName(viewState.isTwoPaneLayout),
)
)
updateCustomAmount(draft, customAmountUIModel)
Expand All @@ -1689,7 +1689,7 @@ class OrderCreateEditViewModel @Inject constructor(
true -> VALUE_CUSTOM_AMOUNT_TAX_STATUS_TAXABLE
false -> VALUE_CUSTOM_AMOUNT_TAX_STATUS_NONE
},
KEY_HORIZONTAL_SIZE_CLASS to getScreenSizeClassNameForAnalytics(viewState.isTwoPaneLayout),
KEY_HORIZONTAL_SIZE_CLASS to getAnalyticsPaneTypeName(viewState.isTwoPaneLayout),
)
)
addCustomAmount(draft, customAmountUIModel)
Expand All @@ -1699,7 +1699,7 @@ class OrderCreateEditViewModel @Inject constructor(
viewState = viewState.copy(isEditable = true)
tracker.track(
ADD_CUSTOM_AMOUNT_DONE_TAPPED,
mapOf(KEY_HORIZONTAL_SIZE_CLASS to getScreenSizeClassNameForAnalytics(viewState.isTwoPaneLayout))
mapOf(KEY_HORIZONTAL_SIZE_CLASS to getAnalyticsPaneTypeName(viewState.isTwoPaneLayout))
)
trackIfNameAdded(customAmountUIModel)
trackIfPercentageBasedCustomAmount(customAmountUIModel)
Expand Down Expand Up @@ -1772,7 +1772,7 @@ class OrderCreateEditViewModel @Inject constructor(
viewState = viewState.copy(isEditable = true)
tracker.track(
ORDER_CREATION_REMOVE_CUSTOM_AMOUNT_TAPPED,
mapOf(KEY_HORIZONTAL_SIZE_CLASS to getScreenSizeClassNameForAnalytics(viewState.isTwoPaneLayout))
mapOf(KEY_HORIZONTAL_SIZE_CLASS to getAnalyticsPaneTypeName(viewState.isTwoPaneLayout))
)
}

Expand All @@ -1781,7 +1781,7 @@ class OrderCreateEditViewModel @Inject constructor(
ORDER_FEE_REMOVE,
mapOf(
KEY_FLOW to flow,
KEY_HORIZONTAL_SIZE_CLASS to getScreenSizeClassNameForAnalytics(viewState.isTwoPaneLayout)
KEY_HORIZONTAL_SIZE_CLASS to getAnalyticsPaneTypeName(viewState.isTwoPaneLayout)
)
)
_orderDraft.update { draft ->
Expand Down Expand Up @@ -1843,7 +1843,7 @@ class OrderCreateEditViewModel @Inject constructor(
}
tracker.track(
AnalyticsEvent.ORDER_CREATION_SET_NEW_TAX_RATE_TAPPED,
mapOf(KEY_HORIZONTAL_SIZE_CLASS to getScreenSizeClassNameForAnalytics(viewState.isTwoPaneLayout))
mapOf(KEY_HORIZONTAL_SIZE_CLASS to getAnalyticsPaneTypeName(viewState.isTwoPaneLayout))
)
}

Expand Down Expand Up @@ -1887,7 +1887,7 @@ class OrderCreateEditViewModel @Inject constructor(
tracker.track(
AnalyticsEvent.TAX_RATE_AUTO_TAX_RATE_SET_NEW_RATE_FOR_ORDER_TAPPED,
mapOf(
KEY_HORIZONTAL_SIZE_CLASS to getScreenSizeClassNameForAnalytics(viewState.isTwoPaneLayout)
KEY_HORIZONTAL_SIZE_CLASS to getAnalyticsPaneTypeName(viewState.isTwoPaneLayout)
)
)
}
Expand All @@ -1900,7 +1900,7 @@ class OrderCreateEditViewModel @Inject constructor(
tracker.track(
AnalyticsEvent.TAX_RATE_AUTO_TAX_RATE_CLEAR_ADDRESS_TAPPED,
mapOf(
KEY_HORIZONTAL_SIZE_CLASS to getScreenSizeClassNameForAnalytics(viewState.isTwoPaneLayout)
KEY_HORIZONTAL_SIZE_CLASS to getAnalyticsPaneTypeName(viewState.isTwoPaneLayout)
)
)
}
Expand All @@ -1914,7 +1914,7 @@ class OrderCreateEditViewModel @Inject constructor(
}
tracker.track(
analyticsEvent,
mapOf(KEY_HORIZONTAL_SIZE_CLASS to getScreenSizeClassNameForAnalytics(viewState.isTwoPaneLayout))
mapOf(KEY_HORIZONTAL_SIZE_CLASS to getAnalyticsPaneTypeName(viewState.isTwoPaneLayout))
)
}

Expand Down Expand Up @@ -1967,7 +1967,7 @@ class OrderCreateEditViewModel @Inject constructor(
val productTypes = if (!ids.isNullOrEmpty()) orderDetailRepository.getUniqueProductTypes(ids) else null
val productCount = products.value?.count() ?: 0
return buildMap {
put(KEY_HORIZONTAL_SIZE_CLASS, IsScreenLargerThanCompactValue(isTablet).deviceTypeToAnalyticsString)
put(KEY_HORIZONTAL_SIZE_CLASS, IsScreenInTwoPaneLayout(isTablet).deviceTypeToAnalyticsString)
put(KEY_STATUS, _orderDraft.value.status)
putIfNotNull(PRODUCT_TYPES to productTypes)
put(KEY_PRODUCT_COUNT, productCount)
Expand Down Expand Up @@ -2000,7 +2000,7 @@ class OrderCreateEditViewModel @Inject constructor(
mapOf(
KEY_FLOW to flow,
KEY_IS_GIFT_CARD_REMOVED to giftCardWasRemoved,
KEY_HORIZONTAL_SIZE_CLASS to getScreenSizeClassNameForAnalytics(viewState.isTwoPaneLayout)
KEY_HORIZONTAL_SIZE_CLASS to getAnalyticsPaneTypeName(viewState.isTwoPaneLayout)
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import com.woocommerce.android.R.string
import com.woocommerce.android.analytics.AnalyticsEvent
import com.woocommerce.android.analytics.AnalyticsTracker.Companion.KEY_SHIPPING_LINES_COUNT
import com.woocommerce.android.analytics.AnalyticsTrackerWrapper
import com.woocommerce.android.analytics.IsScreenLargerThanCompactValue
import com.woocommerce.android.analytics.IsScreenInTwoPaneLayout
import com.woocommerce.android.analytics.deviceTypeToAnalyticsString
import com.woocommerce.android.extensions.whenNotNullNorEmpty
import com.woocommerce.android.model.GiftCardSummary
Expand Down Expand Up @@ -418,7 +418,7 @@ class OrderDetailViewModel @Inject constructor(

fun onCollectPaymentClicked(isTablet: Boolean = false) {
paymentsFlowTracker.trackCollectPaymentTapped(
IsScreenLargerThanCompactValue(isTablet).deviceTypeToAnalyticsString
IsScreenInTwoPaneLayout(isTablet).deviceTypeToAnalyticsString
)
triggerEvent(
StartPaymentFlow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import com.woocommerce.android.analytics.AnalyticsEvent.ORDER_LIST_PRODUCT_BARCO
import com.woocommerce.android.analytics.AnalyticsTracker
import com.woocommerce.android.analytics.AnalyticsTracker.Companion.KEY_HORIZONTAL_SIZE_CLASS
import com.woocommerce.android.analytics.AnalyticsTrackerWrapper
import com.woocommerce.android.analytics.IsScreenLargerThanCompactValue
import com.woocommerce.android.analytics.IsScreenInTwoPaneLayout
import com.woocommerce.android.analytics.deviceTypeToAnalyticsString
import com.woocommerce.android.extensions.NotificationReceivedEvent
import com.woocommerce.android.extensions.drop
Expand Down Expand Up @@ -439,7 +439,7 @@ class OrderListViewModel @Inject constructor(
}

private fun getScreenSizeClassNameForAnalytics(isTwoPaneLayout: Boolean) =
IsScreenLargerThanCompactValue(isTwoPaneLayout).deviceTypeToAnalyticsString
IsScreenInTwoPaneLayout(isTwoPaneLayout).deviceTypeToAnalyticsString

/**
* Activates the provided list by first removing the LiveData sources for the active list,
Expand Down
Loading

0 comments on commit 91c4324

Please sign in to comment.