Skip to content

[Min-Max Quantities Edit Support] Tracking #11752

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

Merged
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 @@ -932,6 +932,9 @@ enum class AnalyticsEvent(override val siteless: Boolean = false) : IAnalyticsEv
PRODUCT_DETAIL_VIEW_QUANTITY_RULES_TAPPED,
PRODUCT_VARIATION_VIEW_QUANTITY_RULES_TAPPED,

PRODUCT_DETAIL_QUANTITY_RULES_DONE_BUTTON_TAPPED,
PRODUCT_VARIATION_QUANTITY_RULES_DONE_BUTTON_TAPPED,

// Bundled products
PRODUCT_DETAIL_VIEW_BUNDLED_PRODUCTS_TAPPED,

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.woocommerce.android.ui.products

import com.woocommerce.android.analytics.AnalyticsEvent
import com.woocommerce.android.model.Component
import com.woocommerce.android.model.Product.Image
import com.woocommerce.android.model.ProductCategory
Expand Down Expand Up @@ -165,7 +166,10 @@ sealed class ProductNavigationTarget : Event() {
val subscription: SubscriptionDetails
) : ProductNavigationTarget()

data class ViewProductQuantityRules(val quantityRules: QuantityRules) : ProductNavigationTarget()
data class ViewProductQuantityRules(
val quantityRules: QuantityRules,
val exitAnalyticsEvent: AnalyticsEvent
) : ProductNavigationTarget()

data class ViewBundleProducts(val productId: Long) : ProductNavigationTarget()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,8 @@ class ProductNavigator @Inject constructor() {

is ProductNavigationTarget.ViewProductQuantityRules -> {
val action = ProductDetailFragmentDirections.actionProductDetailFragmentToProductQuantityRulesFragment(
target.quantityRules
target.quantityRules,
target.exitAnalyticsEvent
)
fragment.findNavController().navigateSafely(action)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ class ProductDetailCardBuilder(
showTitle = true,
onClick = {
viewModel.onEditProductCardClicked(
ViewProductQuantityRules(rules),
ViewProductQuantityRules(rules, AnalyticsEvent.PRODUCT_DETAIL_QUANTITY_RULES_DONE_BUTTON_TAPPED),
AnalyticsEvent.PRODUCT_DETAIL_VIEW_QUANTITY_RULES_TAPPED
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.woocommerce.android.ui.products.quantityRules

import android.os.Parcelable
import androidx.lifecycle.SavedStateHandle
import com.woocommerce.android.analytics.AnalyticsTracker
import com.woocommerce.android.analytics.AnalyticsTrackerWrapper
import com.woocommerce.android.ui.products.models.QuantityRules
import com.woocommerce.android.viewmodel.LiveDataDelegate
import com.woocommerce.android.viewmodel.MultiLiveEvent
Expand All @@ -13,7 +15,8 @@ import javax.inject.Inject

@HiltViewModel
class ProductQuantityRulesViewModel @Inject constructor(
savedState: SavedStateHandle
savedState: SavedStateHandle,
private val analyticsTracker: AnalyticsTrackerWrapper
) : ScopedViewModel(savedState) {

private val navArgs: ProductQuantityRulesFragmentArgs by savedState.navArgs()
Expand Down Expand Up @@ -49,6 +52,10 @@ class ProductQuantityRulesViewModel @Inject constructor(
}

fun onExit() {
analyticsTracker.track(
navArgs.exitAnalyticsEvent,
mapOf(AnalyticsTracker.KEY_HAS_CHANGED_DATA to hasChanges)
)
if (hasChanges) {
triggerEvent(MultiLiveEvent.Event.ExitWithResult(quantityRules))
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ class VariationDetailCardBuilder(
showTitle = true,
onClick = {
viewModel.onEditVariationCardClicked(
ViewProductQuantityRules(rules),
ViewProductQuantityRules(rules, AnalyticsEvent.PRODUCT_VARIATION_QUANTITY_RULES_DONE_BUTTON_TAPPED),
AnalyticsEvent.PRODUCT_VARIATION_VIEW_QUANTITY_RULES_TAPPED
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.woocommerce.android.ui.products.variations

import com.woocommerce.android.analytics.AnalyticsEvent
import com.woocommerce.android.model.Product.Image
import com.woocommerce.android.model.SubscriptionDetails
import com.woocommerce.android.ui.products.ProductInventoryViewModel.InventoryData
Expand Down Expand Up @@ -29,7 +30,10 @@ sealed class VariationNavigationTarget : Event() {
val subscription: SubscriptionDetails
) : VariationNavigationTarget()

data class ViewProductQuantityRules(val quantityRules: QuantityRules) : VariationNavigationTarget()
data class ViewProductQuantityRules(
val quantityRules: QuantityRules,
val exitAnalyticsEvent: AnalyticsEvent
) : VariationNavigationTarget()
data class ViewAttributes(
val remoteProductId: Long,
val remoteVariationId: Long
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ class VariationNavigator @Inject constructor() {

is ViewProductQuantityRules -> {
val action = VariationDetailFragmentDirections
.actionVariationDetailFragmentToProductQuantityRulesFragment(target.quantityRules)
.actionVariationDetailFragmentToProductQuantityRulesFragment(
target.quantityRules,
target.exitAnalyticsEvent
)
fragment.findNavController().navigateSafely(action)
}

Expand Down
3 changes: 3 additions & 0 deletions WooCommerce/src/main/res/navigation/nav_graph_products.xml
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,9 @@
<argument
android:name="quantityRules"
app:argType="com.woocommerce.android.ui.products.models.QuantityRules" />
<argument
android:name="exitAnalyticsEvent"
app:argType="com.woocommerce.android.analytics.AnalyticsEvent" />
</fragment>
<fragment
android:id="@+id/productBundleFragment"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,41 @@
package com.woocommerce.android.ui.products.quantityRules

import com.woocommerce.android.analytics.AnalyticsEvent
import com.woocommerce.android.analytics.AnalyticsTracker
import com.woocommerce.android.analytics.AnalyticsTrackerWrapper
import com.woocommerce.android.ui.products.models.QuantityRules
import com.woocommerce.android.viewmodel.BaseUnitTest
import com.woocommerce.android.viewmodel.MultiLiveEvent
import kotlinx.coroutines.ExperimentalCoroutinesApi
import org.assertj.core.api.Assertions
import org.junit.Before
import org.junit.Test
import org.mockito.kotlin.mock
import org.mockito.kotlin.spy
import org.mockito.kotlin.verify

@ExperimentalCoroutinesApi
class ProductQuantityRulesViewModelTest : BaseUnitTest() {
private val analyticsTracker: AnalyticsTrackerWrapper = mock()
private val initialData = QuantityRules(4, 8, 2)
private val expectedData = QuantityRules(8, 16, 4)
private val exitAnalyticsEvent = AnalyticsEvent.PRODUCT_DETAIL_QUANTITY_RULES_DONE_BUTTON_TAPPED
private lateinit var viewModel: ProductQuantityRulesViewModel

@Before
fun setup() {
viewModel = createViewModel(initialData)
viewModel = createViewModel(initialData, exitAnalyticsEvent)
}

private fun createViewModel(quantityRules: QuantityRules): ProductQuantityRulesViewModel {
val savedState = ProductQuantityRulesFragmentArgs(quantityRules).toSavedStateHandle()
private fun createViewModel(
quantityRules: QuantityRules,
exitAnalyticsEvent: AnalyticsEvent
): ProductQuantityRulesViewModel {
val savedState = ProductQuantityRulesFragmentArgs(quantityRules, exitAnalyticsEvent).toSavedStateHandle()
return spy(
ProductQuantityRulesViewModel(
savedState
savedState,
analyticsTracker
)
)
}
Expand Down Expand Up @@ -81,4 +92,29 @@ class ProductQuantityRulesViewModelTest : BaseUnitTest() {

Assertions.assertThat(result.data).isEqualTo(expectedData)
}

@Test
fun `Send tracks event upon exit if there was no changes`() {
// when
viewModel.onExit()

// then
verify(analyticsTracker).track(
exitAnalyticsEvent,
mapOf(AnalyticsTracker.KEY_HAS_CHANGED_DATA to false)
)
}

@Test
fun `Send tracks event upon exit if there was a change`() {
// when
viewModel.onDataChanged(min = initialData.min?.plus(2))
viewModel.onExit()

// then
verify(analyticsTracker).track(
exitAnalyticsEvent,
mapOf(AnalyticsTracker.KEY_HAS_CHANGED_DATA to true)
)
}
}
Loading