diff --git a/WordPress/build.gradle b/WordPress/build.gradle index 730eb02998b2..54ab94ce0c0e 100644 --- a/WordPress/build.gradle +++ b/WordPress/build.gradle @@ -111,7 +111,7 @@ android { buildConfigField "boolean", "RECOMMEND_THE_APP", "false" buildConfigField "boolean", "UNIFIED_COMMENTS_COMMENT_EDIT", "false" buildConfigField "boolean", "MY_SITE_DASHBOARD_PHASE_2", "false" - buildConfigField "boolean", "MY_SITE_DASHBOARD_STATS_CARD", "false" + buildConfigField "boolean", "MY_SITE_DASHBOARD_TODAYS_STATS_CARD", "false" buildConfigField "boolean", "UNIFIED_COMMENTS_DETAILS", "false" buildConfigField "boolean", "UNIFIED_ABOUT", "false" buildConfigField "boolean", "COMMENTS_SNIPPET", "false" diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java index 8b6b52a711c9..75d095f2c429 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java @@ -132,6 +132,7 @@ import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper; import org.wordpress.android.util.analytics.AnalyticsUtils; import org.wordpress.android.util.analytics.service.InstallationReferrerServiceStarter; +import org.wordpress.android.util.config.MySiteDashboardTodaysStatsCardFeatureConfig; import org.wordpress.android.viewmodel.main.WPMainActivityViewModel; import org.wordpress.android.viewmodel.main.WPMainActivityViewModel.FocusPointInfo; import org.wordpress.android.viewmodel.mlp.ModalLayoutPickerViewModel; @@ -225,6 +226,7 @@ public class WPMainActivity extends LocaleAwareActivity implements @Inject AnalyticsTrackerWrapper mAnalyticsTrackerWrapper; @Inject CreateSiteNotificationScheduler mCreateSiteNotificationScheduler; @Inject WeeklyRoundupScheduler mWeeklyRoundupScheduler; + @Inject MySiteDashboardTodaysStatsCardFeatureConfig mTodaysStatsCardFeatureConfig; @Inject BuildConfigWrapper mBuildConfigWrapper; @@ -975,7 +977,12 @@ private void trackLastVisiblePage(PageType pageType, boolean trackAnalytics) { case MY_SITE: ActivityId.trackLastActivity(ActivityId.MY_SITE); if (trackAnalytics) { - mAnalyticsTrackerWrapper.track(AnalyticsTracker.Stat.MY_SITE_ACCESSED, getSelectedSite()); + // Added today's stats feature config to check if my site tab is accessed more often in AB testing + mAnalyticsTrackerWrapper.track( + AnalyticsTracker.Stat.MY_SITE_ACCESSED, + getSelectedSite(), + mTodaysStatsCardFeatureConfig + ); } break; case READER: diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteViewModel.kt index 133d676b325e..3771cbff5500 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteViewModel.kt @@ -17,9 +17,9 @@ import org.wordpress.android.analytics.AnalyticsTracker.Stat.MY_SITE_PULL_TO_REF import org.wordpress.android.fluxc.model.DynamicCardType import org.wordpress.android.fluxc.model.MediaModel import org.wordpress.android.fluxc.model.SiteModel -import org.wordpress.android.fluxc.model.experiments.Variation.Control import org.wordpress.android.fluxc.model.dashboard.CardModel.PostsCardModel import org.wordpress.android.fluxc.model.dashboard.CardModel.TodaysStatsCardModel +import org.wordpress.android.fluxc.model.experiments.Variation.Control import org.wordpress.android.fluxc.store.AccountStore import org.wordpress.android.fluxc.store.QuickStartStore.QuickStartTask import org.wordpress.android.fluxc.store.QuickStartStore.QuickStartTaskType @@ -328,9 +328,15 @@ class MySiteViewModel @Inject constructor( return orderForDisplay(infoItem, cardsResult, dynamicCards, siteItems) } - private fun onTodaysStatsCardFooterLinkClick() = navigateToTodaysStats() + private fun onTodaysStatsCardFooterLinkClick() { + cardsTracker.trackTodaysStatsCardFooterLinkClicked() + navigateToTodaysStats() + } - private fun onTodaysStatsCardClick() = navigateToTodaysStats() + private fun onTodaysStatsCardClick() { + cardsTracker.trackTodaysStatsCardClicked() + navigateToTodaysStats() + } private fun navigateToTodaysStats() { val selectedSite = requireNotNull(selectedSiteRepository.getSelectedSite()) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/dashboard/CardsShownTracker.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/dashboard/CardsShownTracker.kt index 68a687d2b004..20952117f3ff 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/dashboard/CardsShownTracker.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/dashboard/CardsShownTracker.kt @@ -9,6 +9,7 @@ import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.DashboardCards.Das import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.DashboardCards.DashboardCard.PostCard.PostCardWithoutPostItems import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.DashboardCards.DashboardCard.TodaysStatsCard import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.DashboardCards.DashboardCard.TodaysStatsCard.TodaysStatsCardWithData +import org.wordpress.android.ui.mysite.cards.dashboard.CardsTracker.StatsSubtype import org.wordpress.android.ui.mysite.cards.dashboard.CardsTracker.Type import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper import javax.inject.Inject @@ -38,13 +39,13 @@ class CardsShownTracker @Inject constructor( is TodaysStatsCard.Error -> trackCardShown( Pair( card.dashboardCardType.toTypeValue().label, - Type.TODAYS_STATS.label + StatsSubtype.TODAYS_STATS.label ) ) is TodaysStatsCardWithData -> trackCardShown( Pair( card.dashboardCardType.toTypeValue().label, - Type.TODAYS_STATS.label + StatsSubtype.TODAYS_STATS.label ) ) is PostCard.Error -> trackCardShown( diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/dashboard/CardsSource.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/dashboard/CardsSource.kt index 38a17dc29b32..acf321038a94 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/dashboard/CardsSource.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/dashboard/CardsSource.kt @@ -15,7 +15,7 @@ import org.wordpress.android.modules.BG_THREAD import org.wordpress.android.ui.mysite.MySiteSource.MySiteRefreshSource import org.wordpress.android.ui.mysite.MySiteUiState.PartialState.CardsUpdate import org.wordpress.android.ui.mysite.SelectedSiteRepository -import org.wordpress.android.util.config.MySiteDashboardStatsCardFeatureConfig +import org.wordpress.android.util.config.MySiteDashboardTodaysStatsCardFeatureConfig import javax.inject.Inject import javax.inject.Named @@ -24,7 +24,7 @@ const val REFRESH_DELAY = 500L class CardsSource @Inject constructor( private val selectedSiteRepository: SelectedSiteRepository, private val cardsStore: CardsStore, - private val statsCardFeatureConfig: MySiteDashboardStatsCardFeatureConfig, + private val todaysStatsCardFeatureConfig: MySiteDashboardTodaysStatsCardFeatureConfig, @param:Named(BG_THREAD) private val bgDispatcher: CoroutineDispatcher ) : MySiteRefreshSource { override val refresh = MutableLiveData(false) @@ -94,7 +94,7 @@ class CardsSource @Inject constructor( } private fun getCardTypes() = mutableListOf().apply { - if (statsCardFeatureConfig.isEnabled()) add(Type.TODAYS_STATS) + if (todaysStatsCardFeatureConfig.isEnabled()) add(Type.TODAYS_STATS) add(Type.POSTS) }.toList() diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/dashboard/CardsTracker.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/dashboard/CardsTracker.kt index ba3941736373..82211407dfa3 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/dashboard/CardsTracker.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/dashboard/CardsTracker.kt @@ -15,10 +15,14 @@ class CardsTracker @Inject constructor( ) { enum class Type(val label: String) { ERROR("error"), - TODAYS_STATS("todays_stats"), + STATS("stats"), POST("post") } + enum class StatsSubtype(val label: String) { + TODAYS_STATS("todays_stats") + } + enum class PostSubtype(val label: String) { CREATE_FIRST("create_first"), CREATE_NEXT("create_next"), @@ -26,12 +30,20 @@ class CardsTracker @Inject constructor( SCHEDULED("scheduled") } + fun trackTodaysStatsCardFooterLinkClicked() { + trackCardFooterLinkClicked(Type.STATS.label, StatsSubtype.TODAYS_STATS.label) + } + + fun trackTodaysStatsCardClicked() { + trackCardItemClicked(Type.STATS.label, StatsSubtype.TODAYS_STATS.label) + } + fun trackPostCardFooterLinkClicked(postCardType: PostCardType) { trackCardFooterLinkClicked(Type.POST.label, postCardType.toSubtypeValue().label) } fun trackPostItemClicked(postCardType: PostCardType) { - trackCardPostItemClicked(Type.POST.label, postCardType.toSubtypeValue().label) + trackCardItemClicked(Type.POST.label, postCardType.toSubtypeValue().label) } private fun trackCardFooterLinkClicked(type: String, subtype: String) { @@ -44,7 +56,7 @@ class CardsTracker @Inject constructor( ) } - private fun trackCardPostItemClicked(type: String, subtype: String) { + private fun trackCardItemClicked(type: String, subtype: String) { analyticsTrackerWrapper.track( Stat.MY_SITE_DASHBOARD_CARD_ITEM_TAPPED, mapOf( @@ -65,6 +77,7 @@ class CardsTracker @Inject constructor( companion object { const val TYPE = "type" const val SUBTYPE = "subtype" + const val STATS = "stats" } } @@ -72,7 +85,7 @@ fun DashboardCardType.toTypeValue(): Type { return when (this) { DashboardCardType.ERROR_CARD -> Type.ERROR DashboardCardType.TODAYS_STATS_CARD_ERROR -> Type.ERROR - DashboardCardType.TODAYS_STATS_CARD -> Type.TODAYS_STATS + DashboardCardType.TODAYS_STATS_CARD -> Type.STATS DashboardCardType.POST_CARD_ERROR -> Type.ERROR DashboardCardType.POST_CARD_WITHOUT_POST_ITEMS -> Type.POST DashboardCardType.POST_CARD_WITH_POST_ITEMS -> Type.POST diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/items/SiteItemsTracker.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/items/SiteItemsTracker.kt index b5fd2715480c..552b676db0d1 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/items/SiteItemsTracker.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/items/SiteItemsTracker.kt @@ -9,7 +9,8 @@ class SiteItemsTracker @Inject constructor( private val analyticsTrackerWrapper: AnalyticsTrackerWrapper ) { enum class Type(val label: String) { - POSTS("posts") + POSTS("posts"), + STATS("stats") } fun trackSiteItemClicked(listItemAction: ListItemAction) = trackSiteItemClicked(listItemAction.toTypeValue()) @@ -23,6 +24,7 @@ class SiteItemsTracker @Inject constructor( private fun ListItemAction.toTypeValue(): Type? { return when (this) { ListItemAction.POSTS -> Type.POSTS + ListItemAction.STATS -> Type.STATS else -> null } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsViewModel.kt index 927984bab648..e79c54781f91 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsViewModel.kt @@ -47,6 +47,7 @@ import org.wordpress.android.ui.stats.refresh.utils.trackGranular import org.wordpress.android.ui.utils.UiString.UiStringRes import org.wordpress.android.util.NetworkUtilsWrapper import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper +import org.wordpress.android.util.config.MySiteDashboardTodaysStatsCardFeatureConfig import org.wordpress.android.util.mapNullable import org.wordpress.android.util.mergeNotNull import org.wordpress.android.viewmodel.Event @@ -66,7 +67,8 @@ class StatsViewModel private val statsSiteProvider: StatsSiteProvider, newsCardHandler: NewsCardHandler, private val statsModuleActivateUseCase: StatsModuleActivateUseCase, - private val notificationsTracker: SystemNotificationsTracker + private val notificationsTracker: SystemNotificationsTracker, + private val todaysStatsCardFeatureConfig: MySiteDashboardTodaysStatsCardFeatureConfig ) : ScopedViewModel(mainDispatcher) { private val _isRefreshing = MutableLiveData() val isRefreshing: LiveData = _isRefreshing @@ -148,7 +150,12 @@ class StatsViewModel selectedDateProvider.setInitialSelectedPeriod(initialGranularity, initialSelectedPeriod) } - analyticsTracker.track(AnalyticsTracker.Stat.STATS_ACCESSED, statsSiteProvider.siteModel) + // Added today's stats feature config to check whether that card is enabled when stats screen is accessed + analyticsTracker.track( + stat = AnalyticsTracker.Stat.STATS_ACCESSED, + site = statsSiteProvider.siteModel, + feature = todaysStatsCardFeatureConfig + ) if (launchedFromWidget) { analyticsTracker.track(AnalyticsTracker.Stat.STATS_WIDGET_TAPPED, statsSiteProvider.siteModel) diff --git a/WordPress/src/main/java/org/wordpress/android/util/analytics/AnalyticsTrackerWrapper.kt b/WordPress/src/main/java/org/wordpress/android/util/analytics/AnalyticsTrackerWrapper.kt index 15eeb8584d25..711a2fecb78a 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/analytics/AnalyticsTrackerWrapper.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/analytics/AnalyticsTrackerWrapper.kt @@ -43,6 +43,10 @@ class AnalyticsTrackerWrapper AnalyticsUtils.trackWithSiteDetails(this, stat, site, properties) } + fun track(stat: Stat, site: SiteModel?, feature: FeatureConfig) { + AnalyticsUtils.trackWithSiteDetails(this, stat, site, feature.toParams().toMutableMap()) + } + /** * A convenience method for logging an error event with some additional meta data. * @param stat The stat to track. diff --git a/WordPress/src/main/java/org/wordpress/android/util/config/MySiteDashboardStatsCardFeatureConfig.kt b/WordPress/src/main/java/org/wordpress/android/util/config/MySiteDashboardTodaysStatsCardFeatureConfig.kt similarity index 74% rename from WordPress/src/main/java/org/wordpress/android/util/config/MySiteDashboardStatsCardFeatureConfig.kt rename to WordPress/src/main/java/org/wordpress/android/util/config/MySiteDashboardTodaysStatsCardFeatureConfig.kt index 7e4d030e488c..2a642f389a19 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/config/MySiteDashboardStatsCardFeatureConfig.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/config/MySiteDashboardTodaysStatsCardFeatureConfig.kt @@ -8,9 +8,9 @@ import javax.inject.Inject * Configuration of the 'My Site Dashboard - Stats Card' that will add Stats Card on the 'My Site' screen. */ @FeatureInDevelopment -class MySiteDashboardStatsCardFeatureConfig @Inject constructor( +class MySiteDashboardTodaysStatsCardFeatureConfig @Inject constructor( appConfig: AppConfig ) : FeatureConfig( appConfig, - BuildConfig.MY_SITE_DASHBOARD_STATS_CARD + BuildConfig.MY_SITE_DASHBOARD_TODAYS_STATS_CARD ) diff --git a/WordPress/src/test/java/org/wordpress/android/ui/mysite/cards/dashboard/CardsSourceTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/mysite/cards/dashboard/CardsSourceTest.kt index 5f5c212aa271..173f8217ab83 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/mysite/cards/dashboard/CardsSourceTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/mysite/cards/dashboard/CardsSourceTest.kt @@ -24,7 +24,7 @@ import org.wordpress.android.test import org.wordpress.android.testScope import org.wordpress.android.ui.mysite.MySiteUiState.PartialState.CardsUpdate import org.wordpress.android.ui.mysite.SelectedSiteRepository -import org.wordpress.android.util.config.MySiteDashboardStatsCardFeatureConfig +import org.wordpress.android.util.config.MySiteDashboardTodaysStatsCardFeatureConfig /* SITE */ @@ -81,7 +81,7 @@ class CardsSourceTest : BaseUnitTest() { @Mock private lateinit var selectedSiteRepository: SelectedSiteRepository @Mock private lateinit var cardsStore: CardsStore @Mock private lateinit var siteModel: SiteModel - @Mock private lateinit var statsCardFeatureConfig: MySiteDashboardStatsCardFeatureConfig + @Mock private lateinit var todaysStatsCardFeatureConfig: MySiteDashboardTodaysStatsCardFeatureConfig private lateinit var cardSource: CardsSource private val data = CardsResult( @@ -98,7 +98,7 @@ class CardsSourceTest : BaseUnitTest() { cardSource = CardsSource( selectedSiteRepository, cardsStore, - statsCardFeatureConfig, + todaysStatsCardFeatureConfig, TEST_DISPATCHER ) } @@ -120,10 +120,10 @@ class CardsSourceTest : BaseUnitTest() { } @Test - fun `given stats feature enabled, when build is invoked, then todays stats from store(database)`() = test { + fun `given today's stats feature enabled, when build is invoked, then todays stats from store(database)`() = test { val result = mutableListOf() whenever(cardsStore.getCards(siteModel, STATS_FEATURED_ENABLED_CARD_TYPES)).thenReturn(flowOf(data)) - whenever(statsCardFeatureConfig.isEnabled()).thenReturn(true) + whenever(todaysStatsCardFeatureConfig.isEnabled()).thenReturn(true) cardSource.build(testScope(), SITE_LOCAL_ID).observeForever { it?.let { result.add(it) } } @@ -168,17 +168,18 @@ class CardsSourceTest : BaseUnitTest() { } @Test - fun `given stats feature enabled, when refresh is invoked, then todays stats are requested from network`() = test { - val result = mutableListOf() - whenever(cardsStore.getCards(siteModel, STATS_FEATURED_ENABLED_CARD_TYPES)).thenReturn(flowOf(data)) - whenever(statsCardFeatureConfig.isEnabled()).thenReturn(true) - whenever(cardsStore.fetchCards(siteModel, STATS_FEATURED_ENABLED_CARD_TYPES)).thenReturn(success) - cardSource.refresh.observeForever { } - - cardSource.build(testScope(), SITE_LOCAL_ID).observeForever { it?.let { result.add(it) } } - - verify(cardsStore).fetchCards(siteModel, STATS_FEATURED_ENABLED_CARD_TYPES) - } + fun `given today's stats feature enabled, when refresh is invoked, then todays stats are requested from network`() = + test { + val result = mutableListOf() + whenever(cardsStore.getCards(siteModel, STATS_FEATURED_ENABLED_CARD_TYPES)).thenReturn(flowOf(data)) + whenever(todaysStatsCardFeatureConfig.isEnabled()).thenReturn(true) + whenever(cardsStore.fetchCards(siteModel, STATS_FEATURED_ENABLED_CARD_TYPES)).thenReturn(success) + cardSource.refresh.observeForever { } + + cardSource.build(testScope(), SITE_LOCAL_ID).observeForever { it?.let { result.add(it) } } + + verify(cardsStore).fetchCards(siteModel, STATS_FEATURED_ENABLED_CARD_TYPES) + } @Test fun `given error, when build is invoked, then error snackbar with stale message is also shown (network)`() = test { diff --git a/WordPress/src/test/java/org/wordpress/android/ui/mysite/cards/dashboard/CardsTrackerTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/mysite/cards/dashboard/CardsTrackerTest.kt index b5236fbcff51..77aac5f07a81 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/mysite/cards/dashboard/CardsTrackerTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/mysite/cards/dashboard/CardsTrackerTest.kt @@ -8,6 +8,7 @@ import org.mockito.Mock import org.mockito.junit.MockitoJUnitRunner import org.wordpress.android.analytics.AnalyticsTracker.Stat import org.wordpress.android.ui.mysite.cards.dashboard.CardsTracker.PostSubtype +import org.wordpress.android.ui.mysite.cards.dashboard.CardsTracker.StatsSubtype import org.wordpress.android.ui.mysite.cards.dashboard.CardsTracker.Type import org.wordpress.android.ui.mysite.cards.dashboard.posts.PostCardType import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper @@ -26,65 +27,79 @@ class CardsTrackerTest { cardsTracker = CardsTracker(cardsShownTracker, analyticsTracker) } + @Test + fun `when today's stats card footer link is clicked, then today's stats card footer click event is tracked`() { + cardsTracker.trackTodaysStatsCardFooterLinkClicked() + + verifyFooterLinkClickedTracked(Type.STATS, StatsSubtype.TODAYS_STATS.label) + } + + @Test + fun `when today's stats card is clicked, then today's stats card item click event is tracked`() { + cardsTracker.trackTodaysStatsCardClicked() + + verifyCardItemClickedTracked(Type.STATS, StatsSubtype.TODAYS_STATS.label) + } + @Test fun `when post create first footer link is clicked, then post create first event is tracked`() { cardsTracker.trackPostCardFooterLinkClicked(PostCardType.CREATE_FIRST) - verifyFooterLinkClickedTracked(Type.POST, PostSubtype.CREATE_FIRST) + verifyFooterLinkClickedTracked(Type.POST, PostSubtype.CREATE_FIRST.label) } @Test fun `when post create next footer link is clicked, then post create next event is tracked`() { cardsTracker.trackPostCardFooterLinkClicked(PostCardType.CREATE_NEXT) - verifyFooterLinkClickedTracked(Type.POST, PostSubtype.CREATE_NEXT) + verifyFooterLinkClickedTracked(Type.POST, PostSubtype.CREATE_NEXT.label) } @Test fun `when post draft footer link is clicked, then post draft event is tracked`() { cardsTracker.trackPostCardFooterLinkClicked(PostCardType.DRAFT) - verifyFooterLinkClickedTracked(Type.POST, PostSubtype.DRAFT) + verifyFooterLinkClickedTracked(Type.POST, PostSubtype.DRAFT.label) } @Test fun `when post scheduled footer link is clicked, then post scheduled event is tracked`() { cardsTracker.trackPostCardFooterLinkClicked(PostCardType.SCHEDULED) - verifyFooterLinkClickedTracked(Type.POST, PostSubtype.SCHEDULED) + verifyFooterLinkClickedTracked(Type.POST, PostSubtype.SCHEDULED.label) } @Test fun `when post draft item is clicked, then post item event is tracked`() { cardsTracker.trackPostItemClicked(PostCardType.DRAFT) - verifyPostItemClickedTracked(Type.POST, PostSubtype.DRAFT) + verifyCardItemClickedTracked(Type.POST, PostSubtype.DRAFT.label) } @Test fun `when post scheduled item is clicked, then post item event is tracked`() { cardsTracker.trackPostItemClicked(PostCardType.SCHEDULED) - verifyPostItemClickedTracked(Type.POST, PostSubtype.SCHEDULED) + verifyCardItemClickedTracked(Type.POST, PostSubtype.SCHEDULED.label) } private fun verifyFooterLinkClickedTracked( typeValue: Type, - subtypeValue: PostSubtype + subtypeValue: String ) { verify(analyticsTracker).track( Stat.MY_SITE_DASHBOARD_CARD_FOOTER_ACTION_TAPPED, - mapOf(TYPE to typeValue.label, SUBTYPE to subtypeValue.label) + mapOf(TYPE to typeValue.label, SUBTYPE to subtypeValue) ) } - private fun verifyPostItemClickedTracked( + private fun verifyCardItemClickedTracked( typeValue: Type, - subtypeValue: PostSubtype + subtypeValue: String ) { verify(analyticsTracker).track( Stat.MY_SITE_DASHBOARD_CARD_ITEM_TAPPED, - mapOf(TYPE to typeValue.label, SUBTYPE to subtypeValue.label) + mapOf(TYPE to typeValue.label, SUBTYPE to subtypeValue) ) } } diff --git a/WordPress/src/test/java/org/wordpress/android/ui/mysite/items/SiteItemsTrackerTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/mysite/items/SiteItemsTrackerTest.kt index 41184b3e97ba..28f45679740b 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/mysite/items/SiteItemsTrackerTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/mysite/items/SiteItemsTrackerTest.kt @@ -32,6 +32,13 @@ class SiteItemsTrackerTest { verifySiteItemClickedTracked(Type.POSTS) } + @Test + fun `when site item stats is clicked, then menu item tapped stats is tracked`() { + siteItemsTracker.trackSiteItemClicked(ListItemAction.STATS) + + verifySiteItemClickedTracked(Type.STATS) + } + @Test fun `given not tracking site item, when site item is clicked, then click is not tracked`() { siteItemsTracker.trackSiteItemClicked(ListItemAction.VIEW_SITE) diff --git a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/StatsViewModelTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/StatsViewModelTest.kt index 37686b72571f..65d3f9f5d4d9 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/StatsViewModelTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/stats/refresh/StatsViewModelTest.kt @@ -39,6 +39,7 @@ import org.wordpress.android.ui.stats.refresh.utils.trackGranular import org.wordpress.android.ui.utils.UiString.UiStringRes import org.wordpress.android.util.NetworkUtilsWrapper import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper +import org.wordpress.android.util.config.MySiteDashboardTodaysStatsCardFeatureConfig import org.wordpress.android.viewmodel.ResourceProvider class StatsViewModelTest : BaseUnitTest() { @@ -53,6 +54,7 @@ class StatsViewModelTest : BaseUnitTest() { @Mock lateinit var site: SiteModel @Mock lateinit var statsModuleActivateUseCase: StatsModuleActivateUseCase @Mock lateinit var notificationsTracker: SystemNotificationsTracker + @Mock lateinit var todaysStatsCardFeatureConfig: MySiteDashboardTodaysStatsCardFeatureConfig private lateinit var viewModel: StatsViewModel private val _liveSelectedSection = MutableLiveData() private val liveSelectedSection: LiveData = _liveSelectedSection @@ -71,7 +73,8 @@ class StatsViewModelTest : BaseUnitTest() { statsSiteProvider, newsCardHandler, statsModuleActivateUseCase, - notificationsTracker + notificationsTracker, + todaysStatsCardFeatureConfig ) viewModel.start(1, false, null, null, false, null)