Skip to content

Commit

Permalink
Merge pull request #13054 from woocommerce/fix/dashboard-custom-range…
Browse files Browse the repository at this point in the history
…-tracking

Fix/dashboard custom range tracking
  • Loading branch information
hafizrahman authored Dec 5, 2024
2 parents 2d10aff + f4e045c commit 94898b9
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,14 @@ enum class AnalyticsEvent(override val siteless: Boolean = false) : IAnalyticsEv
DASHBOARD_SHARE_YOUR_STORE_BUTTON_TAPPED,
DASHBOARD_MAIN_STATS_DATE,
DASHBOARD_MAIN_STATS_LOADED,
DASHBOARD_TOP_PERFORMERS_DATE,
DASHBOARD_TOP_PERFORMERS_LOADED,
DASHBOARD_NEW_STATS_REVERTED_BANNER_DISMISS_TAPPED,
DASHBOARD_NEW_STATS_REVERTED_BANNER_LEARN_MORE_TAPPED,
DASHBOARD_WAITING_TIME_LOADED,
DASHBOARD_SEE_MORE_ANALYTICS_TAPPED,
DASHBOARD_STORE_TIMEZONE_DIFFER_FROM_DEVICE,
USED_ANALYTICS,
STATS_UNEXPECTED_FORMAT,
DASHBOARD_STATS_CUSTOM_RANGE_ADD_BUTTON_TAPPED,
DASHBOARD_STATS_CUSTOM_RANGE_CONFIRMED,
DASHBOARD_STATS_CUSTOM_RANGE_TAB_SELECTED,
DASHBOARD_STATS_CUSTOM_RANGE_EDIT_BUTTON_TAPPED,
DASHBOARD_STATS_CUSTOM_RANGE_INTERACTED,
DYNAMIC_DASHBOARD_EDIT_LAYOUT_BUTTON_TAPPED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ fun DashboardStatsCard(
currencyFormatter = viewModel.currencyFormatter,
usageTracksEventEmitter = viewModel.usageTracksEventEmitter,
onAddCustomRangeClick = viewModel::onAddCustomRangeClicked,
onTabSelected = viewModel::onTabSelected,
onTabSelected = viewModel::onRangeChanged,
onChartDateSelected = viewModel::onChartDateSelected
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class DashboardStatsViewModel @AssistedInject constructor(
trackLocalTimezoneDifferenceFromStore()
}

fun onTabSelected(selectionType: SelectionType) {
fun onRangeChanged(selectionType: SelectionType) {
parentViewModel.trackCardInteracted(DashboardWidget.Type.STATS.trackingIdentifier)
usageTracksEventEmitter.interacted()
if (selectionType != SelectionType.CUSTOM) {
Expand All @@ -134,7 +134,7 @@ class DashboardStatsViewModel @AssistedInject constructor(
} else {
appPrefsWrapper.setActiveStatsTab(SelectionType.CUSTOM.name)
analyticsTrackerWrapper.track(
AnalyticsEvent.DASHBOARD_STATS_CUSTOM_RANGE_TAB_SELECTED
AnalyticsEvent.DASHBOARD_STATS_CUSTOM_RANGE_ADD_BUTTON_TAPPED
)
}
}
Expand All @@ -151,7 +151,7 @@ class DashboardStatsViewModel @AssistedInject constructor(
viewModelScope.launch {
customDateRangeDataStore.updateDateRange(range)
if (dateRangeState.value?.rangeSelection?.selectionType != SelectionType.CUSTOM) {
onTabSelected(SelectionType.CUSTOM)
onRangeChanged(SelectionType.CUSTOM)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class DashboardTopPerformersViewModel @AssistedInject constructor(
}
}

fun onTabSelected(selectionType: SelectionType) {
fun onRangeChanged(selectionType: SelectionType) {
parentViewModel.trackCardInteracted(DashboardWidget.Type.POPULAR_PRODUCTS.trackingIdentifier)
usageTracksEventEmitter.interacted()
if (selectionType != SelectionType.CUSTOM) {
Expand All @@ -150,7 +150,7 @@ class DashboardTopPerformersViewModel @AssistedInject constructor(
onEditCustomRangeTapped()
} else {
appPrefsWrapper.setActiveTopPerformersTab(SelectionType.CUSTOM.name)
analyticsTrackerWrapper.track(AnalyticsEvent.DASHBOARD_STATS_CUSTOM_RANGE_TAB_SELECTED)
analyticsTrackerWrapper.track(AnalyticsEvent.DASHBOARD_STATS_CUSTOM_RANGE_ADD_BUTTON_TAPPED)
}
}
}
Expand Down Expand Up @@ -287,7 +287,7 @@ class DashboardTopPerformersViewModel @AssistedInject constructor(
viewModelScope.launch {
customDateRangeDataStore.updateDateRange(statsTimeRange)
if (selectedDateRange.value?.rangeSelection?.selectionType != SelectionType.CUSTOM) {
onTabSelected(SelectionType.CUSTOM)
onRangeChanged(SelectionType.CUSTOM)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ fun DashboardTopPerformersWidgetCard(
topPerformersState = topPerformersState,
selectedDateRange = selectedDateRange,
lastUpdateState = lastUpdateState,
onTabSelected = topPerformersViewModel::onTabSelected,
onTabSelected = topPerformersViewModel::onRangeChanged,
onEditCustomRangeTapped = topPerformersViewModel::onEditCustomRangeTapped
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class DashboardStatsViewModelTest : BaseUnitTest() {
whenever(networkStatus.isConnected()).thenReturn(false)
}

viewModel.onTabSelected(ANY_SELECTION_TYPE)
viewModel.onRangeChanged(ANY_SELECTION_TYPE)

verify(getStats, never()).invoke(any(), any())
}
Expand All @@ -155,7 +155,7 @@ class DashboardStatsViewModelTest : BaseUnitTest() {
.thenReturn(ANY_SELECTION_TYPE.name)
}

viewModel.onTabSelected(ANY_SELECTION_TYPE)
viewModel.onRangeChanged(ANY_SELECTION_TYPE)

verify(getStats, times(2)).invoke(
refresh = ArgumentMatchers.eq(false),
Expand Down Expand Up @@ -196,7 +196,7 @@ class DashboardStatsViewModelTest : BaseUnitTest() {
.thenReturn(ANY_SELECTION_TYPE.name)
}

viewModel.onTabSelected(ANY_SELECTION_TYPE)
viewModel.onRangeChanged(ANY_SELECTION_TYPE)

Assertions.assertThat(viewModel.revenueStatsState.value)
.isInstanceOf(DashboardStatsViewModel.RevenueStatsViewState.Content::class.java)
Expand All @@ -209,7 +209,7 @@ class DashboardStatsViewModelTest : BaseUnitTest() {
testBlocking {
setup()

viewModel.onTabSelected(ANY_SELECTION_TYPE)
viewModel.onRangeChanged(ANY_SELECTION_TYPE)

verify(appPrefsWrapper).setActiveStatsTab(ANY_SELECTION_TYPE.name)
}
Expand Down Expand Up @@ -286,7 +286,7 @@ class DashboardStatsViewModelTest : BaseUnitTest() {

val state = viewModel.dateRangeState.runAndCaptureValues {
viewModel.onChartDateSelected("11")
viewModel.onTabSelected(ANY_SELECTION_TYPE)
viewModel.onRangeChanged(ANY_SELECTION_TYPE)
}.last()

verify(dateRangeFormatter, never())
Expand Down

0 comments on commit 94898b9

Please sign in to comment.