From e5e5deed271915b4f7dd8f28ec27e5b28ee96805 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Wed, 14 Feb 2024 20:43:04 +0300 Subject: [PATCH 01/17] Fix stats_insights_accessed event stats_insights_accessed was being tracked for always even when the insights tab was not selected. This fixes it and track the correct event. --- .../org/wordpress/android/ui/stats/refresh/StatsViewModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 af3c5669e5f7..2373b2dd749d 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 @@ -164,7 +164,7 @@ class StatsViewModel analyticsTracker.track(stat = AnalyticsTracker.Stat.STATS_ACCESSED, site = statsSiteProvider.siteModel) initialSection?.let { statsSectionManager.setSelectedSection(it) } - trackSectionSelected(initialSection ?: StatsSection.INSIGHTS) + trackSectionSelected(statsSectionManager.getSelectedSection()) val initialGranularity = initialSection?.toStatsGranularity() if (initialGranularity != null && initialSelectedPeriod != null) { From a1a77d84adac78336b6ff65b8fd003fadc394e48 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Wed, 14 Feb 2024 22:08:44 +0300 Subject: [PATCH 02/17] Fix StatsViewModelTest --- .../android/ui/stats/refresh/StatsViewModelTest.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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 8e7480cd034e..c94de84aab83 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 @@ -10,7 +10,6 @@ import org.junit.Test import org.mockito.Mock import org.mockito.kotlin.any import org.mockito.kotlin.anyOrNull -import org.mockito.kotlin.times import org.mockito.kotlin.verify import org.mockito.kotlin.whenever import org.wordpress.android.BaseUnitTest @@ -33,11 +32,13 @@ import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSect import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection.DAYS import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection.INSIGHTS import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection.MONTHS +import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection.TRAFFIC import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection.WEEKS import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection.YEARS import org.wordpress.android.ui.stats.refresh.lists.sections.granular.SelectedDateProvider import org.wordpress.android.ui.stats.refresh.utils.NewsCardHandler import org.wordpress.android.ui.stats.refresh.utils.SelectedSectionManager +import org.wordpress.android.ui.stats.refresh.utils.SelectedTrafficGranularityManager import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider import org.wordpress.android.ui.stats.refresh.utils.trackGranular import org.wordpress.android.ui.utils.UiString.UiStringRes @@ -58,6 +59,9 @@ class StatsViewModelTest : BaseUnitTest() { @Mock lateinit var statsSectionManager: SelectedSectionManager + @Mock + lateinit var selectedTrafficGranularityManager: SelectedTrafficGranularityManager + @Mock lateinit var analyticsTracker: AnalyticsTrackerWrapper @@ -97,6 +101,8 @@ class StatsViewModelTest : BaseUnitTest() { @Before fun setUp() { whenever(baseListUseCase.snackbarMessage).thenReturn(MutableLiveData()) + whenever(statsSectionManager.getSelectedSection()).thenReturn(TRAFFIC) + whenever(selectedTrafficGranularityManager.getSelectedTrafficGranularity()).thenReturn(StatsGranularity.DAYS) whenever(statsSectionManager.liveSelectedSection).thenReturn(liveSelectedSection) whenever(statsSiteProvider.siteModel).thenReturn(site) viewModel = StatsViewModel( @@ -105,6 +111,7 @@ class StatsViewModelTest : BaseUnitTest() { testDispatcher(), selectedDateProvider, statsSectionManager, + selectedTrafficGranularityManager, analyticsTracker, networkUtilsWrapper, statsSiteProvider, @@ -126,9 +133,7 @@ class StatsViewModelTest : BaseUnitTest() { viewModel.onSectionSelected(INSIGHTS) verify(statsSectionManager).setSelectedSection(INSIGHTS) - /* First one is default insights section selection which is set when no value is passed to vm for - initial section */ - verify(analyticsTracker, times(2)).track(STATS_INSIGHTS_ACCESSED) + verify(analyticsTracker).track(STATS_INSIGHTS_ACCESSED) } @Test From 1b3583ee745b0c9bab5c496b2e1aa60ba7f28ced Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Thu, 15 Feb 2024 16:25:00 +0300 Subject: [PATCH 03/17] Add more types to `StatsLaunchedFrom` --- .../android/ui/stats/refresh/StatsActivity.kt | 13 ++++++++++--- .../android/ui/stats/refresh/StatsViewModel.kt | 2 +- .../refresh/lists/widget/WidgetBlockListProvider.kt | 2 +- .../widget/alltime/AllTimeWidgetListProvider.kt | 2 +- .../lists/widget/today/TodayWidgetListProvider.kt | 2 +- .../stats/refresh/lists/widget/utils/WidgetUtils.kt | 2 +- .../lists/widget/views/ViewsWidgetListProvider.kt | 2 +- .../widget/weeks/WeekViewsWidgetListProvider.kt | 2 +- 8 files changed, 17 insertions(+), 10 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsActivity.kt index 2aaa415a22e9..42369a071d82 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsActivity.kt @@ -88,8 +88,15 @@ class StatsActivity : LocaleAwareActivity() { } } - enum class StatsLaunchedFrom { - STATS_WIDGET, - NOTIFICATIONS + enum class StatsLaunchedFrom(val value: String) { + QUICK_ACTIONS("quick_actions"), + TODAY_STATS_CARD("today_stats_card"), + ROW("row"), + WIDGET("widget"), + NOTIFICATION("notification"), + LINK("link"), + SHORTCUT("shortcut"), + ACTIVITY_LOG("activity_log"), + JETPACK_CONNECTION("jetpack_connection") } } 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 2373b2dd749d..923e8b7ede39 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 @@ -171,7 +171,7 @@ class StatsViewModel selectedDateProvider.setInitialSelectedPeriod(initialGranularity, initialSelectedPeriod) } - if (launchedFrom == StatsLaunchedFrom.STATS_WIDGET) { + if (launchedFrom == StatsLaunchedFrom.WIDGET) { analyticsTracker.track(AnalyticsTracker.Stat.STATS_WIDGET_TAPPED, statsSiteProvider.siteModel) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/WidgetBlockListProvider.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/WidgetBlockListProvider.kt index 8b66c964e528..51437fe4dba2 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/WidgetBlockListProvider.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/WidgetBlockListProvider.kt @@ -57,7 +57,7 @@ class WidgetBlockListProvider(val context: Context, val viewModel: WidgetBlockLi intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) intent.putExtra(WordPress.LOCAL_SITE_ID, uiModel.localSiteId) intent.putExtra(StatsActivity.ARG_DESIRED_TIMEFRAME, uiModel.targetTimeframe) - intent.putExtra(StatsActivity.ARG_LAUNCHED_FROM, StatsLaunchedFrom.STATS_WIDGET) + intent.putExtra(StatsActivity.ARG_LAUNCHED_FROM, StatsLaunchedFrom.WIDGET) rv.setOnClickFillInIntent(R.id.container, intent) return rv } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/alltime/AllTimeWidgetListProvider.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/alltime/AllTimeWidgetListProvider.kt index fc183ed71068..3c47027e270b 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/alltime/AllTimeWidgetListProvider.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/alltime/AllTimeWidgetListProvider.kt @@ -70,7 +70,7 @@ class AllTimeWidgetListProvider(val context: Context, intent: Intent) : RemoteVi intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) intent.putExtra(WordPress.LOCAL_SITE_ID, uiModel.localSiteId) intent.putExtra(StatsActivity.ARG_DESIRED_TIMEFRAME, StatsTimeframe.INSIGHTS) - intent.putExtra(StatsActivity.ARG_LAUNCHED_FROM, StatsLaunchedFrom.STATS_WIDGET) + intent.putExtra(StatsActivity.ARG_LAUNCHED_FROM, StatsLaunchedFrom.WIDGET) rv.setOnClickFillInIntent(R.id.container, intent) return rv } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/today/TodayWidgetListProvider.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/today/TodayWidgetListProvider.kt index 13d3132151f8..e0e3918d8bd4 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/today/TodayWidgetListProvider.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/today/TodayWidgetListProvider.kt @@ -68,7 +68,7 @@ class TodayWidgetListProvider(val context: Context, intent: Intent) : RemoteView intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) intent.putExtra(WordPress.LOCAL_SITE_ID, uiModel.localSiteId) intent.putExtra(StatsActivity.ARG_DESIRED_TIMEFRAME, StatsTimeframe.INSIGHTS) - intent.putExtra(StatsActivity.ARG_LAUNCHED_FROM, StatsLaunchedFrom.STATS_WIDGET) + intent.putExtra(StatsActivity.ARG_LAUNCHED_FROM, StatsLaunchedFrom.WIDGET) rv.setOnClickFillInIntent(R.id.container, intent) return rv } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/utils/WidgetUtils.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/utils/WidgetUtils.kt index 686955a3e261..6693aa25c36f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/utils/WidgetUtils.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/utils/WidgetUtils.kt @@ -180,7 +180,7 @@ class WidgetUtils intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) intent.putExtra(WordPress.LOCAL_SITE_ID, localSiteId) intent.putExtra(StatsActivity.ARG_DESIRED_TIMEFRAME, statsTimeframe) - intent.putExtra(StatsActivity.ARG_LAUNCHED_FROM, StatsLaunchedFrom.STATS_WIDGET) + intent.putExtra(StatsActivity.ARG_LAUNCHED_FROM, StatsLaunchedFrom.WIDGET) return PendingIntent.getActivity( context, getRandomId(), diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/views/ViewsWidgetListProvider.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/views/ViewsWidgetListProvider.kt index ee5a67c6b132..0f7c58c6d537 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/views/ViewsWidgetListProvider.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/views/ViewsWidgetListProvider.kt @@ -90,7 +90,7 @@ class ViewsWidgetListProvider(val context: Context, intent: Intent) : RemoteView intent.putExtra(INITIAL_SELECTED_PERIOD_KEY, uiModel.period) intent.putExtra(WordPress.LOCAL_SITE_ID, uiModel.localSiteId) intent.putExtra(StatsActivity.ARG_DESIRED_TIMEFRAME, StatsTimeframe.DAY) - intent.putExtra(StatsActivity.ARG_LAUNCHED_FROM, StatsLaunchedFrom.STATS_WIDGET) + intent.putExtra(StatsActivity.ARG_LAUNCHED_FROM, StatsLaunchedFrom.WIDGET) rv.setOnClickFillInIntent(R.id.container, intent) return rv } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/weeks/WeekViewsWidgetListProvider.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/weeks/WeekViewsWidgetListProvider.kt index 69ccc38ed121..9ea2cf71fd5c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/weeks/WeekViewsWidgetListProvider.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/weeks/WeekViewsWidgetListProvider.kt @@ -69,7 +69,7 @@ class WeekViewsWidgetListProvider(val context: Context, intent: Intent) : Remote intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) intent.putExtra(WordPress.LOCAL_SITE_ID, uiModel.localSiteId) intent.putExtra(StatsActivity.ARG_DESIRED_TIMEFRAME, StatsTimeframe.INSIGHTS) - intent.putExtra(StatsActivity.ARG_LAUNCHED_FROM, StatsLaunchedFrom.STATS_WIDGET) + intent.putExtra(StatsActivity.ARG_LAUNCHED_FROM, StatsLaunchedFrom.WIDGET) rv.setOnClickFillInIntent(R.id.container, intent) return rv } From 0af95e4214d4f1614a964256862af639d03686da Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Thu, 15 Feb 2024 21:37:39 +0300 Subject: [PATCH 04/17] Add launchedFrom param to start stats from ActivityLauncher --- .../android/ui/ActivityLauncher.java | 39 +++++++++++-------- .../android/ui/stats/refresh/StatsActivity.kt | 7 +++- .../ui/stats/refresh/StatsViewModel.kt | 4 +- .../ui/stats/refresh/StatsViewModelTest.kt | 4 +- 4 files changed, 32 insertions(+), 22 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/ActivityLauncher.java b/WordPress/src/main/java/org/wordpress/android/ui/ActivityLauncher.java index ab51fe1aad2e..e3827621c198 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/ActivityLauncher.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/ActivityLauncher.java @@ -116,6 +116,7 @@ import org.wordpress.android.ui.stats.StatsTimeframe; import org.wordpress.android.ui.stats.StatsViewType; import org.wordpress.android.ui.stats.refresh.StatsActivity; +import org.wordpress.android.ui.stats.refresh.StatsActivity.StatsLaunchedFrom; import org.wordpress.android.ui.stats.refresh.StatsViewAllActivity; import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection; import org.wordpress.android.ui.stats.refresh.lists.detail.StatsDetailActivity; @@ -501,21 +502,23 @@ public static void openEditorForReblog( addNewPostForResult(editorIntent, activity, site, false, reblogSource, -1, null); } - public static void viewStatsInNewStack(Context context, SiteModel site) { - viewStatsInNewStack(context, site, null); + public static void viewStatsInNewStack(Context context, SiteModel site, @NonNull StatsLaunchedFrom launchedFrom) { + viewStatsInNewStack(context, site, null, launchedFrom); } - public static void viewStatsInNewStack(Context context, SiteModel site, @Nullable StatsTimeframe statsTimeframe) { - viewStatsInNewStack(context, site, statsTimeframe, null); + public static void viewStatsInNewStack(Context context, SiteModel site, @Nullable StatsTimeframe statsTimeframe, + @NonNull StatsLaunchedFrom launchedFrom) { + viewStatsInNewStack(context, site, statsTimeframe, null, launchedFrom); } public static void viewStatsInNewStack(Context context, SiteModel site, @Nullable StatsTimeframe statsTimeframe, - @Nullable String period) { + @Nullable String period, @NonNull StatsLaunchedFrom launchedFrom) { if (site == null) { handleMissingSite(context); return; } - runIntentOverMainActivityInNewStack(context, StatsActivity.buildIntent(context, site, statsTimeframe, period)); + runIntentOverMainActivityInNewStack(context, + StatsActivity.buildIntent(context, site, statsTimeframe, period, launchedFrom)); } private static void handleMissingSite(Context context) { @@ -537,9 +540,11 @@ public static PendingIntent buildStatsPendingIntentOverMainActivityInNewStack(Co @Nullable StatsTimeframe timeframe, @Nullable String period, @Nullable NotificationType type, + @NonNull + StatsLaunchedFrom launchedFrom, int requestCode, int flags) { return buildPendingIntentOverMainActivityInNewStack(context, - StatsActivity.buildIntent(context, site, timeframe, period, type), requestCode, flags); + StatsActivity.buildIntent(context, site, timeframe, period, launchedFrom, type), requestCode, flags); } private static PendingIntent buildPendingIntentOverMainActivityInNewStack(Context context, Intent intent, @@ -586,7 +591,7 @@ public static void viewSavedPostsListInReader(Context context) { context.startActivity(intent); } - public static void viewBlogStats(Context context, SiteModel site) { + public static void viewBlogStats(Context context, SiteModel site, @NonNull StatsLaunchedFrom from) { if (site == null) { AppLog.e(T.STATS, "SiteModel is null when opening the stats."); AnalyticsTracker.track( @@ -594,14 +599,15 @@ public static void viewBlogStats(Context context, SiteModel site) { ActivityLauncher.class.getName(), "NullPointerException", "Failed to open Stats because of the null SiteModel" - ); + ); ToastUtils.showToast(context, R.string.stats_cannot_be_started, ToastUtils.Duration.SHORT); } else { - StatsActivity.start(context, site); + StatsActivity.start(context, site, from); } } - public static void viewBlogStatsForTimeframe(Context context, SiteModel site, StatsTimeframe statsTimeframe) { + public static void viewBlogStatsForTimeframe(Context context, SiteModel site, StatsTimeframe statsTimeframe, + @NonNull StatsLaunchedFrom from) { if (site == null) { AppLog.e(T.STATS, "SiteModel is null when opening the stats."); AnalyticsTracker.track( @@ -609,10 +615,10 @@ public static void viewBlogStatsForTimeframe(Context context, SiteModel site, St ActivityLauncher.class.getName(), "NullPointerException", "Failed to open Stats because of the null SiteModel" - ); + ); ToastUtils.showToast(context, R.string.stats_cannot_be_started, ToastUtils.Duration.SHORT); } else { - StatsActivity.start(context, site, statsTimeframe); + StatsActivity.start(context, site, statsTimeframe, from); } } @@ -636,7 +642,8 @@ public static void viewInsightsManagement(Context context, int localSiteId) { context.startActivity(intent); } - public static void viewBlogStatsAfterJetpackSetup(Context context, SiteModel site) { + public static void viewBlogStatsAfterJetpackSetup(Context context, SiteModel site, + @NonNull StatsLaunchedFrom launchedFrom) { if (site == null) { AppLog.e(T.STATS, "SiteModel is null when opening the stats."); AnalyticsTracker.track( @@ -644,11 +651,11 @@ public static void viewBlogStatsAfterJetpackSetup(Context context, SiteModel sit ActivityLauncher.class.getName(), "NullPointerException", "Failed to open Stats because of the null SiteModel" - ); + ); ToastUtils.showToast(context, R.string.stats_cannot_be_started, ToastUtils.Duration.SHORT); return; } - StatsActivity.start(context, site); + StatsActivity.start(context, site, launchedFrom); } public static void viewConnectJetpackForStats(Context context, SiteModel site) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsActivity.kt index 42369a071d82..0366e091f397 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsActivity.kt @@ -69,8 +69,9 @@ class StatsActivity : LocaleAwareActivity() { context: Context, site: SiteModel, statsTimeframe: StatsTimeframe? = null, - period: String? = null - ) = context.startActivity(buildIntent(context, site, statsTimeframe, period)) + period: String? = null, + launchedFrom: StatsLaunchedFrom + ) = context.startActivity(buildIntent(context, site, statsTimeframe, period, launchedFrom)) @JvmStatic @JvmOverloads @@ -79,11 +80,13 @@ class StatsActivity : LocaleAwareActivity() { site: SiteModel, statsTimeframe: StatsTimeframe? = null, period: String? = null, + launchedFrom: StatsLaunchedFrom, notificationType: NotificationType? = null ) = Intent(context, StatsActivity::class.java).apply { putExtra(WordPress.LOCAL_SITE_ID, site.id) statsTimeframe?.let { putExtra(ARG_DESIRED_TIMEFRAME, it) } period?.let { putExtra(INITIAL_SELECTED_PERIOD_KEY, it) } + putExtra(ARG_LAUNCHED_FROM, launchedFrom) notificationType?.let { putExtra(ARG_NOTIFICATION_TYPE, it) } } } 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 923e8b7ede39..9a117b9ef7c4 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 @@ -114,7 +114,7 @@ class StatsViewModel fun start(intent: Intent, restart: Boolean = false) { val localSiteId = intent.getIntExtra(WordPress.LOCAL_SITE_ID, 0) - val launchedFrom = intent.getSerializableExtraCompat(StatsActivity.ARG_LAUNCHED_FROM) + val launchedFrom = intent.getSerializableExtraCompat(StatsActivity.ARG_LAUNCHED_FROM) val initialTimeFrame = getInitialTimeFrame(intent) val initialSelectedPeriod = intent.getStringExtra(StatsActivity.INITIAL_SELECTED_PERIOD_KEY) val notificationType = intent.getSerializableExtraCompat(ARG_NOTIFICATION_TYPE) @@ -148,7 +148,7 @@ class StatsViewModel @Suppress("ComplexMethod", "LongParameterList") fun start( localSiteId: Int, - launchedFrom: Serializable?, + launchedFrom: StatsLaunchedFrom?, initialSection: StatsSection?, initialSelectedPeriod: String?, restart: Boolean, 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 c94de84aab83..9a586d0b4f12 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 @@ -123,7 +123,7 @@ class StatsViewModelTest : BaseUnitTest() { jetpackFeatureRemovalOverlayUtil ) - viewModel.start(1, false, null, null, false, null) + viewModel.start(1, StatsActivity.StatsLaunchedFrom.QUICK_ACTIONS, TRAFFIC, null, false, null) } @Test @@ -337,7 +337,7 @@ class StatsViewModelTest : BaseUnitTest() { private fun startViewModel(statsModuleEnabled: Boolean = true) { whenever(site.isActiveModuleEnabled(any())).thenReturn(statsModuleEnabled) - viewModel.start(1, false, null, null, false, null) + viewModel.start(1, StatsActivity.StatsLaunchedFrom.QUICK_ACTIONS, null, null, false, null) } private val networkUnavailableError = StatsModuleActivateRequestState.Failure.NetworkUnavailable From ada365255635ec3b4ab2cb5ae96992e066b091d4 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Thu, 15 Feb 2024 21:55:21 +0300 Subject: [PATCH 05/17] Add tap_source property to the stats_accessed event --- .../wordpress/android/ui/stats/refresh/StatsViewModel.kt | 6 +++++- .../android/ui/stats/refresh/utils/StatsAnalyticsUtils.kt | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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 9a117b9ef7c4..df7aaf44e7e7 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 @@ -49,6 +49,7 @@ import org.wordpress.android.ui.stats.refresh.utils.SelectedSectionManager import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider import org.wordpress.android.ui.stats.refresh.utils.toStatsGranularity import org.wordpress.android.ui.stats.refresh.utils.trackGranular +import org.wordpress.android.ui.stats.refresh.utils.trackStatsAccessed import org.wordpress.android.ui.utils.UiString.UiStringRes import org.wordpress.android.util.JetpackBrandingUtils import org.wordpress.android.util.NetworkUtilsWrapper @@ -161,7 +162,10 @@ class StatsViewModel if (!isInitialized || restart) { isInitialized = true - analyticsTracker.track(stat = AnalyticsTracker.Stat.STATS_ACCESSED, site = statsSiteProvider.siteModel) + analyticsTracker.trackStatsAccessed( + site = statsSiteProvider.siteModel, + tapSource = launchedFrom?.value ?: "" + ) initialSection?.let { statsSectionManager.setSelectedSection(it) } trackSectionSelected(statsSectionManager.getSelectedSection()) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/StatsAnalyticsUtils.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/StatsAnalyticsUtils.kt index 8113a9b097e7..664ef1a9a6ed 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/StatsAnalyticsUtils.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/StatsAnalyticsUtils.kt @@ -2,6 +2,7 @@ package org.wordpress.android.ui.stats.refresh.utils import org.wordpress.android.analytics.AnalyticsTracker.Stat import org.wordpress.android.analytics.AnalyticsTracker.Stat.STATS_INSIGHTS_VIEWS_VISITORS_TOGGLED +import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.network.utils.StatsGranularity import org.wordpress.android.fluxc.store.StatsStore.InsightType import org.wordpress.android.ui.stats.refresh.lists.widget.configuration.StatsWidgetConfigureFragment.WidgetType @@ -11,6 +12,7 @@ import org.wordpress.android.ui.stats.refresh.lists.widget.configuration.StatsWi import org.wordpress.android.ui.stats.refresh.lists.widget.configuration.StatsWidgetConfigureFragment.WidgetType.WEEK_VIEWS import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper +private const val TAP_SOURCE_PROPERTY = "tap_source" private const val GRANULARITY_PROPERTY = "granularity" private const val DAYS_PROPERTY = "days" private const val WEEKS_PROPERTY = "weeks" @@ -27,6 +29,9 @@ private const val MINIFIED_WIDGET_PROPERTY = "minified" private const val CHIP_VIEWS_PROPERTY = "views" private const val CHIP_VISITORS__PROPERTY = "visitors" +fun AnalyticsTrackerWrapper.trackStatsAccessed(site: SiteModel, tapSource: String) = + track(stat = Stat.STATS_ACCESSED, site = site, properties = mutableMapOf(TAP_SOURCE_PROPERTY to tapSource)) + fun AnalyticsTrackerWrapper.trackGranular(stat: Stat, granularity: StatsGranularity) { val property = when (granularity) { StatsGranularity.DAYS -> DAYS_PROPERTY From ceba38148422cd58b4bf13f651afcac3c8d12c67 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Thu, 15 Feb 2024 21:58:42 +0300 Subject: [PATCH 06/17] Send quick_actions as tap_source when opening the stats from My Site --- .../org/wordpress/android/ui/mysite/MySiteFragment.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteFragment.kt index 6034341af6b4..5879e3b7cbfc 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteFragment.kt @@ -59,6 +59,7 @@ import org.wordpress.android.ui.quickstart.QuickStartTracker import org.wordpress.android.ui.reader.ReaderActivityLauncher import org.wordpress.android.ui.reader.tracker.ReaderTracker import org.wordpress.android.ui.stats.StatsTimeframe +import org.wordpress.android.ui.stats.refresh.StatsActivity import org.wordpress.android.ui.uploads.UploadService import org.wordpress.android.ui.uploads.UploadUtilsWrapper import org.wordpress.android.ui.utils.TitleSubtitleSnackbarSpannable @@ -607,7 +608,12 @@ class MySiteFragment : Fragment(R.layout.my_site_fragment), action.quickStartEvent ) is SiteNavigationAction.OpenUnifiedComments -> ActivityLauncher.viewUnifiedComments(activity, action.site) - is SiteNavigationAction.OpenStats -> ActivityLauncher.viewBlogStats(activity, action.site) + is SiteNavigationAction.OpenStats -> ActivityLauncher.viewBlogStats( + activity, + action.site, + StatsActivity.StatsLaunchedFrom.QUICK_ACTIONS + ) + is SiteNavigationAction.ConnectJetpackForStats -> ActivityLauncher.viewConnectJetpackForStats(activity, action.site) is SiteNavigationAction.StartWPComLoginForJetpackStats -> From 87d89cf8bee8015f0a354ece2862c4ee332552bd Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Thu, 15 Feb 2024 22:02:50 +0300 Subject: [PATCH 07/17] Send row as tap_source when opening the stats from My More screen --- .../org/wordpress/android/ui/mysite/menu/MenuActivity.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/menu/MenuActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/menu/MenuActivity.kt index b80d28a42095..33f583b28840 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/menu/MenuActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/menu/MenuActivity.kt @@ -64,6 +64,7 @@ import org.wordpress.android.ui.mysite.items.listitem.ListItemAction import org.wordpress.android.ui.pages.SnackbarMessageHolder import org.wordpress.android.ui.prefs.SiteSettingsFragment import org.wordpress.android.ui.quickstart.QuickStartMySitePrompts +import org.wordpress.android.ui.stats.refresh.StatsActivity import org.wordpress.android.ui.utils.ListItemInteraction import org.wordpress.android.ui.utils.UiString import org.wordpress.android.util.LocaleManager @@ -143,7 +144,12 @@ class MenuActivity : AppCompatActivity() { is SiteNavigationAction.OpenMedia -> ActivityLauncher.viewCurrentBlogMedia(this, action.site) is SiteNavigationAction.OpenMeScreen -> ActivityLauncher.viewMeActivityForResult(this) is SiteNavigationAction.OpenUnifiedComments -> ActivityLauncher.viewUnifiedComments(this, action.site) - is SiteNavigationAction.OpenStats -> ActivityLauncher.viewBlogStats(this, action.site) + is SiteNavigationAction.OpenStats -> ActivityLauncher.viewBlogStats( + this, + action.site, + StatsActivity.StatsLaunchedFrom.ROW + ) + is SiteNavigationAction.OpenDomains -> ActivityLauncher.viewDomainsDashboardActivity( this, action.site From 034f91bf92b1840467de1cdcbb626178a733baea Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Thu, 15 Feb 2024 22:09:16 +0300 Subject: [PATCH 08/17] Send today_stats_card as tap_source when opening the stats from card --- .../org/wordpress/android/ui/mysite/MySiteFragment.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteFragment.kt index 5879e3b7cbfc..fecc440b3294 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteFragment.kt @@ -673,8 +673,14 @@ class MySiteFragment : Fragment(R.layout.my_site_fragment), ActivityLauncher.viewCurrentBlogPostsOfType(requireActivity(), action.site, PostListType.DRAFTS) is SiteNavigationAction.EditScheduledPost -> ActivityLauncher.viewCurrentBlogPostsOfType(requireActivity(), action.site, PostListType.SCHEDULED) - is SiteNavigationAction.OpenStatsInsights -> - ActivityLauncher.viewBlogStatsForTimeframe(requireActivity(), action.site, StatsTimeframe.INSIGHTS) + + is SiteNavigationAction.OpenStatsInsights -> ActivityLauncher.viewBlogStatsForTimeframe( + requireActivity(), + action.site, + StatsTimeframe.INSIGHTS, + StatsActivity.StatsLaunchedFrom.TODAY_STATS_CARD + ) + is SiteNavigationAction.OpenExternalUrl -> ActivityLauncher.openUrlExternal(requireActivity(), action.url) is SiteNavigationAction.OpenUrlInWebView -> From c2864757192ac244ff0cec68e8145c1c0d795994 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Thu, 15 Feb 2024 23:00:59 +0300 Subject: [PATCH 09/17] Send notification as tap_source when opening stats from weekly notif --- .../android/ui/notifications/NotificationsDetailActivity.java | 3 ++- .../android/workers/weeklyroundup/WeeklyRoundupNotifier.kt | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailActivity.java index 0dc9e1d6f0da..4dc25520a642 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailActivity.java @@ -54,6 +54,7 @@ import org.wordpress.android.ui.reader.comments.ThreadedCommentsActionSource; import org.wordpress.android.ui.reader.tracker.ReaderTracker; import org.wordpress.android.ui.stats.StatsViewType; +import org.wordpress.android.ui.stats.refresh.StatsActivity.StatsLaunchedFrom; import org.wordpress.android.util.AppLog; import org.wordpress.android.util.StringUtils; import org.wordpress.android.util.ToastUtils; @@ -504,7 +505,7 @@ private void showStatsActivityForSite(@NonNull SiteModel site, FormattableRangeT ActivityLauncher.viewAllTabbedInsightsStats(this, StatsViewType.FOLLOWERS, 0, site.getId()); } else { - ActivityLauncher.viewBlogStats(this, site); + ActivityLauncher.viewBlogStats(this, site, StatsLaunchedFrom.NOTIFICATION); } } diff --git a/WordPress/src/main/java/org/wordpress/android/workers/weeklyroundup/WeeklyRoundupNotifier.kt b/WordPress/src/main/java/org/wordpress/android/workers/weeklyroundup/WeeklyRoundupNotifier.kt index 5c59c604c7b1..0924049102aa 100644 --- a/WordPress/src/main/java/org/wordpress/android/workers/weeklyroundup/WeeklyRoundupNotifier.kt +++ b/WordPress/src/main/java/org/wordpress/android/workers/weeklyroundup/WeeklyRoundupNotifier.kt @@ -16,6 +16,7 @@ import org.wordpress.android.ui.jetpackoverlay.JetpackFeatureRemovalPhaseHelper import org.wordpress.android.ui.notifications.SystemNotificationsTracker import org.wordpress.android.ui.prefs.AppPrefsWrapper import org.wordpress.android.ui.stats.StatsTimeframe.WEEK +import org.wordpress.android.ui.stats.refresh.StatsActivity import org.wordpress.android.ui.stats.refresh.utils.StatsUtils import org.wordpress.android.util.SiteUtilsWrapper import org.wordpress.android.viewmodel.ContextProvider @@ -75,6 +76,7 @@ class WeeklyRoundupNotifier @Inject constructor( WEEK, data.period, WEEKLY_ROUNDUP, + StatsActivity.StatsLaunchedFrom.NOTIFICATION, notificationId, FLAG_CANCEL_CURRENT or FLAG_IMMUTABLE ) From 388d1bedefc3cb15cda2e5f48f8058085c420e2e Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Thu, 15 Feb 2024 23:27:15 +0300 Subject: [PATCH 10/17] Send link as tap_source when opening the stats from deeplinks --- .../android/ui/deeplinks/DeepLinkNavigator.kt | 13 +++++++++++-- .../wordpress/android/ui/main/WPMainActivity.java | 6 ++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/deeplinks/DeepLinkNavigator.kt b/WordPress/src/main/java/org/wordpress/android/ui/deeplinks/DeepLinkNavigator.kt index cee3bc824c2d..748e26a9baec 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/deeplinks/DeepLinkNavigator.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/deeplinks/DeepLinkNavigator.kt @@ -29,6 +29,7 @@ import org.wordpress.android.ui.deeplinks.DeepLinkNavigator.NavigateAction.ViewP import org.wordpress.android.ui.sitecreation.misc.SiteCreationSource.DEEP_LINK import org.wordpress.android.ui.sitemonitor.SiteMonitorType import org.wordpress.android.ui.stats.StatsTimeframe +import org.wordpress.android.ui.stats.refresh.StatsActivity import org.wordpress.android.util.UriWrapper import javax.inject.Inject @@ -61,12 +62,20 @@ class DeepLinkNavigator activity, navigateAction.statsTimeframe ) - is OpenStatsForSite -> ActivityLauncher.viewStatsInNewStack(activity, navigateAction.site) + + is OpenStatsForSite -> ActivityLauncher.viewStatsInNewStack( + activity, + navigateAction.site, + StatsActivity.StatsLaunchedFrom.LINK + ) + is OpenStatsForSiteAndTimeframe -> ActivityLauncher.viewStatsInNewStack( activity, navigateAction.site, - navigateAction.statsTimeframe + navigateAction.statsTimeframe, + StatsActivity.StatsLaunchedFrom.LINK ) + OpenReader -> ActivityLauncher.viewReaderInNewStack(activity) is OpenInReader -> ActivityLauncher.viewPostDeeplinkInNewStack(activity, navigateAction.uri.uri) is ViewPostInReader -> ActivityLauncher.viewReaderPostDetailInNewStack( 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 6d67608adebb..27cc8feae2a3 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 @@ -134,6 +134,7 @@ import org.wordpress.android.ui.review.ReviewViewModel; import org.wordpress.android.ui.sitecreation.misc.SiteCreationSource; import org.wordpress.android.ui.stats.StatsTimeframe; +import org.wordpress.android.ui.stats.refresh.StatsActivity.StatsLaunchedFrom; import org.wordpress.android.ui.stories.intro.StoriesIntroDialogFragment; import org.wordpress.android.ui.uploads.UploadActionUseCase; import org.wordpress.android.ui.uploads.UploadUtils; @@ -944,9 +945,10 @@ private void handleOpenPageIntent(@NonNull Intent intent) { } if (intent.hasExtra(ARG_STATS_TIMEFRAME)) { ActivityLauncher.viewBlogStatsForTimeframe(this, getSelectedSite(), - (StatsTimeframe) intent.getSerializableExtra(ARG_STATS_TIMEFRAME)); + (StatsTimeframe) intent.getSerializableExtra(ARG_STATS_TIMEFRAME), + StatsLaunchedFrom.LINK); } else { - ActivityLauncher.viewBlogStats(this, getSelectedSite()); + ActivityLauncher.viewBlogStats(this, getSelectedSite(), StatsLaunchedFrom.LINK); } break; case ARG_PAGES: From 32581159fac4cbd097a3740542cf50a18b067c6a Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Thu, 15 Feb 2024 23:42:15 +0300 Subject: [PATCH 11/17] Send shortcut as tap_source when opening the stats from shortcut --- .../main/java/org/wordpress/android/ui/ShortcutsNavigator.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/ShortcutsNavigator.java b/WordPress/src/main/java/org/wordpress/android/ui/ShortcutsNavigator.java index 2ff58cd2fa96..59f1d5a96a01 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/ShortcutsNavigator.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/ShortcutsNavigator.java @@ -5,6 +5,7 @@ import org.wordpress.android.analytics.AnalyticsTracker; import org.wordpress.android.fluxc.model.SiteModel; import org.wordpress.android.ui.jetpackoverlay.JetpackFeatureRemovalPhaseHelper; +import org.wordpress.android.ui.stats.refresh.StatsActivity.StatsLaunchedFrom; import org.wordpress.android.util.AppLog; import javax.inject.Inject; @@ -35,7 +36,7 @@ public void showTargetScreen(String action, Activity activity, SiteModel current if (mJetpackFeatureRemovalPhaseHelper.shouldShowStaticPage()) { ActivityLauncher.showJetpackStaticPoster(activity); } else { - ActivityLauncher.viewBlogStats(activity, currentSite); + ActivityLauncher.viewBlogStats(activity, currentSite, StatsLaunchedFrom.SHORTCUT); } } break; From 5740df5977c58a0ee459c12901ec617210d85671 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Thu, 15 Feb 2024 23:58:43 +0300 Subject: [PATCH 12/17] Send activity_log as tap_source when opening stats from activity log --- .../ui/notifications/utils/FormattableContentClickHandler.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/notifications/utils/FormattableContentClickHandler.kt b/WordPress/src/main/java/org/wordpress/android/ui/notifications/utils/FormattableContentClickHandler.kt index 6993078a7999..f42672dc941e 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/notifications/utils/FormattableContentClickHandler.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/notifications/utils/FormattableContentClickHandler.kt @@ -16,6 +16,7 @@ import org.wordpress.android.ui.reader.comments.ThreadedCommentsActionSource.ACT import org.wordpress.android.ui.reader.tracker.ReaderTracker import org.wordpress.android.ui.reader.utils.ReaderUtils import org.wordpress.android.ui.stats.StatsViewType.FOLLOWERS +import org.wordpress.android.ui.stats.refresh.StatsActivity import org.wordpress.android.util.AppLog import org.wordpress.android.util.AppLog.T.API import org.wordpress.android.util.ToastUtils @@ -117,7 +118,7 @@ class FormattableContentClickHandler @Inject constructor( if (rangeType == FormattableRangeType.FOLLOW) { ActivityLauncher.viewAllTabbedInsightsStats(activity, FOLLOWERS, 0, site.id) } else { - ActivityLauncher.viewBlogStats(activity, site) + ActivityLauncher.viewBlogStats(activity, site, StatsActivity.StatsLaunchedFrom.ACTIVITY_LOG) } } From e11ccaeecd64d0ab24e8721d3e4490ac445254fe Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Fri, 16 Feb 2024 00:02:28 +0300 Subject: [PATCH 13/17] Send jetpack_connection as tap_source when opening the stats --- .../wordpress/android/ui/JetpackConnectionResultActivity.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/JetpackConnectionResultActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/JetpackConnectionResultActivity.java index bdac09b520cd..85b6abe0cde0 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/JetpackConnectionResultActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/JetpackConnectionResultActivity.java @@ -20,6 +20,7 @@ import org.wordpress.android.fluxc.store.SiteStore; import org.wordpress.android.login.LoginMode; import org.wordpress.android.ui.accounts.LoginActivity; +import org.wordpress.android.ui.stats.refresh.StatsActivity.StatsLaunchedFrom; import org.wordpress.android.util.AppLog; import org.wordpress.android.util.SiteUtils; import org.wordpress.android.util.ToastUtils; @@ -140,7 +141,7 @@ private void finishAndGoBackToSource() { if (mSource == JetpackConnectionSource.STATS) { SiteModel site = (SiteModel) getIntent().getSerializableExtra(SITE); mDispatcher.dispatch(SiteActionBuilder.newFetchSitesAction(SiteUtils.getFetchSitesPayload())); - ActivityLauncher.viewBlogStatsAfterJetpackSetup(this, site); + ActivityLauncher.viewBlogStatsAfterJetpackSetup(this, site, StatsLaunchedFrom.JETPACK_CONNECTION); } finish(); } From fce1926512af062ef1878aa1ff0aa26edb418334 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Wed, 14 Feb 2024 22:10:14 +0300 Subject: [PATCH 14/17] Track stats_period_accessed event for the TRAFFIC tab --- .../ui/stats/refresh/StatsViewModel.kt | 56 ++++++++++++++++--- .../stats/refresh/lists/StatsListViewModel.kt | 8 ++- .../refresh/utils/StatsAnalyticsUtils.kt | 22 ++++---- .../ui/stats/refresh/StatsViewModelTest.kt | 10 ++++ .../android/analytics/AnalyticsTracker.java | 2 +- .../analytics/AnalyticsTrackerNosara.java | 4 +- 6 files changed, 79 insertions(+), 23 deletions(-) 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 df7aaf44e7e7..cc1ae6094087 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 @@ -14,11 +14,11 @@ import org.wordpress.android.R import org.wordpress.android.WordPress import org.wordpress.android.analytics.AnalyticsTracker import org.wordpress.android.analytics.AnalyticsTracker.Stat.STATS_INSIGHTS_ACCESSED +import org.wordpress.android.analytics.AnalyticsTracker.Stat.STATS_PERIOD_ACCESSED import org.wordpress.android.analytics.AnalyticsTracker.Stat.STATS_PERIOD_DAYS_ACCESSED import org.wordpress.android.analytics.AnalyticsTracker.Stat.STATS_PERIOD_MONTHS_ACCESSED import org.wordpress.android.analytics.AnalyticsTracker.Stat.STATS_PERIOD_WEEKS_ACCESSED import org.wordpress.android.analytics.AnalyticsTracker.Stat.STATS_PERIOD_YEARS_ACCESSED -import org.wordpress.android.analytics.AnalyticsTracker.Stat.STATS_TRAFFIC_ACCESSED import org.wordpress.android.fluxc.network.utils.StatsGranularity import org.wordpress.android.fluxc.store.DEFAULT_INSIGHTS import org.wordpress.android.fluxc.store.JETPACK_DEFAULT_INSIGHTS @@ -46,14 +46,16 @@ import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSect import org.wordpress.android.ui.stats.refresh.lists.sections.granular.SelectedDateProvider import org.wordpress.android.ui.stats.refresh.utils.NewsCardHandler import org.wordpress.android.ui.stats.refresh.utils.SelectedSectionManager +import org.wordpress.android.ui.stats.refresh.utils.SelectedTrafficGranularityManager import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider import org.wordpress.android.ui.stats.refresh.utils.toStatsGranularity -import org.wordpress.android.ui.stats.refresh.utils.trackGranular import org.wordpress.android.ui.stats.refresh.utils.trackStatsAccessed +import org.wordpress.android.ui.stats.refresh.utils.trackWithGranularity import org.wordpress.android.ui.utils.UiString.UiStringRes import org.wordpress.android.util.JetpackBrandingUtils import org.wordpress.android.util.NetworkUtilsWrapper import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper +import org.wordpress.android.util.config.StatsTrafficTabFeatureConfig import org.wordpress.android.util.extensions.getSerializableExtraCompat import org.wordpress.android.util.mapNullable import org.wordpress.android.util.mergeNotNull @@ -71,6 +73,7 @@ class StatsViewModel @Named(BG_THREAD) private val defaultDispatcher: CoroutineDispatcher, private val selectedDateProvider: SelectedDateProvider, private val statsSectionManager: SelectedSectionManager, + private val selectedTrafficGranularityManager: SelectedTrafficGranularityManager, private val analyticsTracker: AnalyticsTrackerWrapper, private val networkUtilsWrapper: NetworkUtilsWrapper, private val statsSiteProvider: StatsSiteProvider, @@ -79,7 +82,8 @@ class StatsViewModel private val statsModuleActivateUseCase: StatsModuleActivateUseCase, private val notificationsTracker: SystemNotificationsTracker, private val jetpackBrandingUtils: JetpackBrandingUtils, - private val jetpackFeatureRemovalOverlayUtil: JetpackFeatureRemovalOverlayUtil + private val jetpackFeatureRemovalOverlayUtil: JetpackFeatureRemovalOverlayUtil, + private val statsTrafficTabFeatureConfig: StatsTrafficTabFeatureConfig ) : ScopedViewModel(mainDispatcher) { private val _isRefreshing = MutableLiveData() val isRefreshing: LiveData = _isRefreshing @@ -168,6 +172,7 @@ class StatsViewModel ) initialSection?.let { statsSectionManager.setSelectedSection(it) } + updateSelectedSectionByTrafficTabFeatureConfig() trackSectionSelected(statsSectionManager.getSelectedSection()) val initialGranularity = initialSection?.toStatsGranularity() @@ -210,6 +215,21 @@ class StatsViewModel showJetpackOverlay() } + private fun updateSelectedSectionByTrafficTabFeatureConfig() { + if (statsTrafficTabFeatureConfig.isEnabled()) { + val selectedSection = statsSectionManager.getSelectedSection() + val isSelectedSectionRemoved = selectedSection == StatsSection.DAYS || + selectedSection == StatsSection.WEEKS || + selectedSection == StatsSection.MONTHS || + selectedSection == StatsSection.YEARS + + if (isSelectedSectionRemoved) { + // statsTrafficTabFeatureConfig has just been enabled. Update the cached selected section. + statsSectionManager.setSelectedSection(StatsSection.TRAFFIC) + } + } + } + private fun showJetpackOverlay() { _showJetpackOverlay.value = Event(true) } @@ -284,12 +304,32 @@ class StatsViewModel private fun trackSectionSelected(statsSection: StatsSection) { when (statsSection) { - StatsSection.TRAFFIC -> analyticsTracker.track(STATS_TRAFFIC_ACCESSED) + StatsSection.TRAFFIC -> analyticsTracker.trackWithGranularity( + STATS_PERIOD_ACCESSED, + selectedTrafficGranularityManager.getSelectedTrafficGranularity() + ) + StatsSection.INSIGHTS -> analyticsTracker.track(STATS_INSIGHTS_ACCESSED) - StatsSection.DAYS -> analyticsTracker.trackGranular(STATS_PERIOD_DAYS_ACCESSED, StatsGranularity.DAYS) - StatsSection.WEEKS -> analyticsTracker.trackGranular(STATS_PERIOD_WEEKS_ACCESSED, StatsGranularity.WEEKS) - StatsSection.MONTHS -> analyticsTracker.trackGranular(STATS_PERIOD_MONTHS_ACCESSED, StatsGranularity.MONTHS) - StatsSection.YEARS -> analyticsTracker.trackGranular(STATS_PERIOD_YEARS_ACCESSED, StatsGranularity.YEARS) + StatsSection.DAYS -> analyticsTracker.trackWithGranularity( + STATS_PERIOD_DAYS_ACCESSED, + StatsGranularity.DAYS + ) + + StatsSection.WEEKS -> analyticsTracker.trackWithGranularity( + STATS_PERIOD_WEEKS_ACCESSED, + StatsGranularity.WEEKS + ) + + StatsSection.MONTHS -> analyticsTracker.trackWithGranularity( + STATS_PERIOD_MONTHS_ACCESSED, + StatsGranularity.MONTHS + ) + + StatsSection.YEARS -> analyticsTracker.trackWithGranularity( + STATS_PERIOD_YEARS_ACCESSED, + StatsGranularity.YEARS + ) + StatsSection.ANNUAL_STATS -> Unit // Do nothing StatsSection.DETAIL -> Unit // Do nothing StatsSection.INSIGHT_DETAIL -> Unit // Do nothing diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt index 366d1f7073f1..565aeb8d5d3b 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt @@ -34,6 +34,7 @@ import org.wordpress.android.ui.stats.refresh.utils.ItemPopupMenuHandler import org.wordpress.android.ui.stats.refresh.utils.NewsCardHandler import org.wordpress.android.ui.stats.refresh.utils.SelectedTrafficGranularityManager import org.wordpress.android.ui.stats.refresh.utils.StatsDateSelector +import org.wordpress.android.ui.stats.refresh.utils.trackWithGranularity import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper import org.wordpress.android.util.mapNullable import org.wordpress.android.util.merge @@ -214,7 +215,7 @@ class InsightsListViewModel class TrafficListViewModel @Inject constructor( @Named(UI_THREAD) mainDispatcher: CoroutineDispatcher, @Named(TRAFFIC_USE_CASE) private val trafficStatsUseCase: BaseListUseCase, - analyticsTracker: AnalyticsTrackerWrapper, + private val analyticsTracker: AnalyticsTrackerWrapper, dateSelectorFactory: StatsDateSelector.Factory, @Named(GRANULAR_USE_CASE_FACTORIES) private val useCasesFactories: List<@JvmSuppressWildcards GranularUseCaseFactory>, @@ -230,6 +231,11 @@ class TrafficListViewModel @Inject constructor( ) { fun onGranularitySelected(statsGranularity: StatsGranularity) { if (dateSelector?.statsGranularity != statsGranularity) { + analyticsTracker.trackWithGranularity( + Stat.STATS_PERIOD_ACCESSED, + selectedTrafficGranularityManager.getSelectedTrafficGranularity() + ) + // Remove observers from the UI before changing the statsUseCase. This prevents removed use cases from // affecting the UI. mutableUiSourceRemoved.call() diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/StatsAnalyticsUtils.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/StatsAnalyticsUtils.kt index 664ef1a9a6ed..cc2f79968e45 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/StatsAnalyticsUtils.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/StatsAnalyticsUtils.kt @@ -14,6 +14,7 @@ import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper private const val TAP_SOURCE_PROPERTY = "tap_source" private const val GRANULARITY_PROPERTY = "granularity" +private const val PERIOD_PROPERTY = "period" private const val DAYS_PROPERTY = "days" private const val WEEKS_PROPERTY = "weeks" private const val MONTHS_PROPERTY = "months" @@ -32,15 +33,8 @@ private const val CHIP_VISITORS__PROPERTY = "visitors" fun AnalyticsTrackerWrapper.trackStatsAccessed(site: SiteModel, tapSource: String) = track(stat = Stat.STATS_ACCESSED, site = site, properties = mutableMapOf(TAP_SOURCE_PROPERTY to tapSource)) -fun AnalyticsTrackerWrapper.trackGranular(stat: Stat, granularity: StatsGranularity) { - val property = when (granularity) { - StatsGranularity.DAYS -> DAYS_PROPERTY - StatsGranularity.WEEKS -> WEEKS_PROPERTY - StatsGranularity.MONTHS -> MONTHS_PROPERTY - StatsGranularity.YEARS -> YEARS_PROPERTY - } - this.track(stat, mapOf(GRANULARITY_PROPERTY to property)) -} +fun AnalyticsTrackerWrapper.trackGranular(stat: Stat, granularity: StatsGranularity) = + track(stat, mapOf(GRANULARITY_PROPERTY to getPropertyByGranularity(granularity))) fun AnalyticsTrackerWrapper.trackViewsVisitorsChips(position: Int) { val property = when (position) { @@ -50,8 +44,14 @@ fun AnalyticsTrackerWrapper.trackViewsVisitorsChips(position: Int) { this.track(STATS_INSIGHTS_VIEWS_VISITORS_TOGGLED, mapOf(TYPE to property)) } -fun AnalyticsTrackerWrapper.trackWithGranularity(stat: Stat, granularity: StatsGranularity) { - this.track(stat, mapOf(GRANULARITY_PROPERTY to granularity)) +fun AnalyticsTrackerWrapper.trackWithGranularity(stat: Stat, granularity: StatsGranularity) = + track(stat, mapOf(PERIOD_PROPERTY to getPropertyByGranularity(granularity))) + +private fun getPropertyByGranularity(granularity: StatsGranularity) = when (granularity) { + StatsGranularity.DAYS -> DAYS_PROPERTY + StatsGranularity.WEEKS -> WEEKS_PROPERTY + StatsGranularity.MONTHS -> MONTHS_PROPERTY + StatsGranularity.YEARS -> YEARS_PROPERTY } fun AnalyticsTrackerWrapper.trackWithType(stat: Stat, insightType: InsightType) { 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 9a586d0b4f12..6243f953c68c 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 @@ -15,6 +15,7 @@ import org.mockito.kotlin.whenever import org.wordpress.android.BaseUnitTest import org.wordpress.android.R import org.wordpress.android.analytics.AnalyticsTracker.Stat.STATS_INSIGHTS_ACCESSED +import org.wordpress.android.analytics.AnalyticsTracker.Stat.STATS_PERIOD_ACCESSED import org.wordpress.android.analytics.AnalyticsTracker.Stat.STATS_PERIOD_DAYS_ACCESSED import org.wordpress.android.analytics.AnalyticsTracker.Stat.STATS_PERIOD_MONTHS_ACCESSED import org.wordpress.android.analytics.AnalyticsTracker.Stat.STATS_PERIOD_WEEKS_ACCESSED @@ -126,6 +127,15 @@ class StatsViewModelTest : BaseUnitTest() { viewModel.start(1, StatsActivity.StatsLaunchedFrom.QUICK_ACTIONS, TRAFFIC, null, false, null) } + @Test + fun `tracks tab traffic selection`() { + startViewModel() + + // The TRAFFIC tab is already the initial tab. + + verify(analyticsTracker).trackGranular(STATS_PERIOD_ACCESSED, StatsGranularity.DAYS) + } + @Test fun `stores and tracks tab insights selection`() { startViewModel() diff --git a/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java b/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java index 5a4e730ef599..f9c8fddccee8 100644 --- a/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java +++ b/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java @@ -82,7 +82,7 @@ public enum Stat { READER_SITE_SHARED, STATS_ACCESSED, STATS_ACCESS_ERROR, - STATS_TRAFFIC_ACCESSED, + STATS_PERIOD_ACCESSED, STATS_INSIGHTS_ACCESSED, STATS_INSIGHTS_MANAGEMENT_HINT_DISMISSED, STATS_INSIGHTS_MANAGEMENT_HINT_CLICKED, diff --git a/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java b/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java index 08a9c022394b..a7cc8bc1018a 100644 --- a/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java +++ b/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java @@ -1073,8 +1073,6 @@ public static String getEventNameForStat(AnalyticsTracker.Stat stat) { return "stats_accessed"; case STATS_ACCESS_ERROR: return "stats_access_error"; - case STATS_TRAFFIC_ACCESSED: - return "stats_traffic_accessed"; case STATS_INSIGHTS_ACCESSED: return "stats_insights_accessed"; case STATS_INSIGHTS_MANAGEMENT_HINT_DISMISSED: @@ -1099,6 +1097,8 @@ public static String getEventNameForStat(AnalyticsTracker.Stat stat) { return "stats_insights_management_type_removed"; case STATS_INSIGHTS_MANAGEMENT_TYPE_REORDERED: return "stats_insights_management_type_reordered"; + case STATS_PERIOD_ACCESSED: + return "stats_period_accessed"; case STATS_PERIOD_DAYS_ACCESSED: return "stats_period_accessed"; case STATS_PERIOD_WEEKS_ACCESSED: From d4231a1c73b7b4b1289556e112cbd0f94845e5f7 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Tue, 13 Feb 2024 20:19:03 +0300 Subject: [PATCH 15/17] Rename stats_previous_date_tapped event to stats_date_tapped_backward --- .../refresh/lists/sections/granular/SelectedDateProvider.kt | 4 ++-- .../org/wordpress/android/analytics/AnalyticsTracker.java | 2 +- .../wordpress/android/analytics/AnalyticsTrackerNosara.java | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/SelectedDateProvider.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/SelectedDateProvider.kt index c4e5c0879c9a..45dcfa1d3414 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/SelectedDateProvider.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/SelectedDateProvider.kt @@ -9,7 +9,7 @@ import androidx.lifecycle.MutableLiveData import kotlinx.parcelize.Parceler import kotlinx.parcelize.Parcelize import org.wordpress.android.analytics.AnalyticsTracker.Stat.STATS_NEXT_DATE_TAPPED -import org.wordpress.android.analytics.AnalyticsTracker.Stat.STATS_PREVIOUS_DATE_TAPPED +import org.wordpress.android.analytics.AnalyticsTracker.Stat.STATS_DATE_TAPPED_BACKWARD import org.wordpress.android.fluxc.network.utils.StatsGranularity import org.wordpress.android.ui.stats.refresh.utils.StatsDateFormatter import org.wordpress.android.ui.stats.refresh.utils.trackWithGranularity @@ -90,7 +90,7 @@ class SelectedDateProvider fun selectPreviousDate(statsGranularity: StatsGranularity) { val selectedDateState = getSelectedDateState(statsGranularity) if (selectedDateState.hasData()) { - analyticsTrackerWrapper.trackWithGranularity(STATS_PREVIOUS_DATE_TAPPED, statsGranularity) + analyticsTrackerWrapper.trackWithGranularity(STATS_DATE_TAPPED_BACKWARD, statsGranularity) updateSelectedDate( selectedDateState.copy(dateValue = selectedDateState.getPreviousDate()), statsGranularity diff --git a/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java b/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java index f9c8fddccee8..e1f2c4ae4b5b 100644 --- a/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java +++ b/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java @@ -100,8 +100,8 @@ public enum Stat { STATS_PERIOD_MONTHS_ACCESSED, STATS_PERIOD_YEARS_ACCESSED, STATS_VIEW_ALL_ACCESSED, - STATS_PREVIOUS_DATE_TAPPED, STATS_NEXT_DATE_TAPPED, + STATS_DATE_TAPPED_BACKWARD, STATS_INSIGHTS_TOTAL_LIKES_GUIDE_TAPPED, STATS_INSIGHTS_ACTION_BLOGGING_REMINDERS_CONFIRMED, STATS_INSIGHTS_ACTION_BLOGGING_REMINDERS_DISMISSED, diff --git a/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java b/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java index a7cc8bc1018a..6261eb2aec4c 100644 --- a/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java +++ b/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java @@ -1109,10 +1109,10 @@ public static String getEventNameForStat(AnalyticsTracker.Stat stat) { return "stats_period_accessed"; case STATS_VIEW_ALL_ACCESSED: return "stats_view_all_accessed"; - case STATS_PREVIOUS_DATE_TAPPED: - return "stats_previous_date_tapped"; case STATS_NEXT_DATE_TAPPED: return "stats_next_date_tapped"; + case STATS_DATE_TAPPED_BACKWARD: + return "stats_date_tapped_backward"; case STATS_INSIGHTS_TOTAL_LIKES_GUIDE_TAPPED: return "stats_insights_total_likes_guide_tapped"; case STATS_INSIGHTS_ACTION_BLOGGING_REMINDERS_CONFIRMED: From fdd2968bd82da003a190fb9be8d22423fff0bce1 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Tue, 13 Feb 2024 20:19:57 +0300 Subject: [PATCH 16/17] Rename stats_next_date_tapped event to stats_date_tapped_forward --- .../refresh/lists/sections/granular/SelectedDateProvider.kt | 4 ++-- .../org/wordpress/android/analytics/AnalyticsTracker.java | 2 +- .../wordpress/android/analytics/AnalyticsTrackerNosara.java | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/SelectedDateProvider.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/SelectedDateProvider.kt index 45dcfa1d3414..e0760a4f395c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/SelectedDateProvider.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/SelectedDateProvider.kt @@ -8,7 +8,7 @@ import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import kotlinx.parcelize.Parceler import kotlinx.parcelize.Parcelize -import org.wordpress.android.analytics.AnalyticsTracker.Stat.STATS_NEXT_DATE_TAPPED +import org.wordpress.android.analytics.AnalyticsTracker.Stat.STATS_DATE_TAPPED_FORWARD import org.wordpress.android.analytics.AnalyticsTracker.Stat.STATS_DATE_TAPPED_BACKWARD import org.wordpress.android.fluxc.network.utils.StatsGranularity import org.wordpress.android.ui.stats.refresh.utils.StatsDateFormatter @@ -101,7 +101,7 @@ class SelectedDateProvider fun selectNextDate(statsGranularity: StatsGranularity) { val selectedDateState = getSelectedDateState(statsGranularity) if (selectedDateState.hasData()) { - analyticsTrackerWrapper.trackWithGranularity(STATS_NEXT_DATE_TAPPED, statsGranularity) + analyticsTrackerWrapper.trackWithGranularity(STATS_DATE_TAPPED_FORWARD, statsGranularity) updateSelectedDate(selectedDateState.copy(dateValue = selectedDateState.getNextDate()), statsGranularity) } } diff --git a/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java b/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java index e1f2c4ae4b5b..0fe9a77f7d2e 100644 --- a/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java +++ b/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java @@ -100,8 +100,8 @@ public enum Stat { STATS_PERIOD_MONTHS_ACCESSED, STATS_PERIOD_YEARS_ACCESSED, STATS_VIEW_ALL_ACCESSED, - STATS_NEXT_DATE_TAPPED, STATS_DATE_TAPPED_BACKWARD, + STATS_DATE_TAPPED_FORWARD, STATS_INSIGHTS_TOTAL_LIKES_GUIDE_TAPPED, STATS_INSIGHTS_ACTION_BLOGGING_REMINDERS_CONFIRMED, STATS_INSIGHTS_ACTION_BLOGGING_REMINDERS_DISMISSED, diff --git a/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java b/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java index 6261eb2aec4c..2f946200e424 100644 --- a/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java +++ b/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java @@ -1109,10 +1109,10 @@ public static String getEventNameForStat(AnalyticsTracker.Stat stat) { return "stats_period_accessed"; case STATS_VIEW_ALL_ACCESSED: return "stats_view_all_accessed"; - case STATS_NEXT_DATE_TAPPED: - return "stats_next_date_tapped"; case STATS_DATE_TAPPED_BACKWARD: return "stats_date_tapped_backward"; + case STATS_DATE_TAPPED_FORWARD: + return "stats_date_tapped_forward"; case STATS_INSIGHTS_TOTAL_LIKES_GUIDE_TAPPED: return "stats_insights_total_likes_guide_tapped"; case STATS_INSIGHTS_ACTION_BLOGGING_REMINDERS_CONFIRMED: From 02869c65983aa46757812766cdd195657c19983c Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Sun, 18 Feb 2024 22:50:05 +0300 Subject: [PATCH 17/17] Fix StatsViewModelTest --- .../ui/stats/refresh/StatsViewModelTest.kt | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) 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 6243f953c68c..8a79b56d866f 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 @@ -41,11 +41,12 @@ import org.wordpress.android.ui.stats.refresh.utils.NewsCardHandler import org.wordpress.android.ui.stats.refresh.utils.SelectedSectionManager import org.wordpress.android.ui.stats.refresh.utils.SelectedTrafficGranularityManager import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider -import org.wordpress.android.ui.stats.refresh.utils.trackGranular +import org.wordpress.android.ui.stats.refresh.utils.trackWithGranularity import org.wordpress.android.ui.utils.UiString.UiStringRes import org.wordpress.android.util.JetpackBrandingUtils import org.wordpress.android.util.NetworkUtilsWrapper import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper +import org.wordpress.android.util.config.StatsTrafficTabFeatureConfig import org.wordpress.android.viewmodel.Event import org.wordpress.android.viewmodel.ResourceProvider @@ -95,6 +96,9 @@ class StatsViewModelTest : BaseUnitTest() { @Mock lateinit var jetpackFeatureRemovalOverlayUtil: JetpackFeatureRemovalOverlayUtil + + @Mock + lateinit var trafficTabFeatureConfig: StatsTrafficTabFeatureConfig private lateinit var viewModel: StatsViewModel private val _liveSelectedSection = MutableLiveData() private val liveSelectedSection: LiveData = _liveSelectedSection @@ -121,7 +125,8 @@ class StatsViewModelTest : BaseUnitTest() { statsModuleActivateUseCase, notificationsTracker, jetpackBrandingUtils, - jetpackFeatureRemovalOverlayUtil + jetpackFeatureRemovalOverlayUtil, + trafficTabFeatureConfig ) viewModel.start(1, StatsActivity.StatsLaunchedFrom.QUICK_ACTIONS, TRAFFIC, null, false, null) @@ -133,7 +138,7 @@ class StatsViewModelTest : BaseUnitTest() { // The TRAFFIC tab is already the initial tab. - verify(analyticsTracker).trackGranular(STATS_PERIOD_ACCESSED, StatsGranularity.DAYS) + verify(analyticsTracker).trackWithGranularity(STATS_PERIOD_ACCESSED, StatsGranularity.DAYS) } @Test @@ -153,7 +158,7 @@ class StatsViewModelTest : BaseUnitTest() { viewModel.onSectionSelected(DAYS) verify(statsSectionManager).setSelectedSection(DAYS) - verify(analyticsTracker).trackGranular(STATS_PERIOD_DAYS_ACCESSED, StatsGranularity.DAYS) + verify(analyticsTracker).trackWithGranularity(STATS_PERIOD_DAYS_ACCESSED, StatsGranularity.DAYS) } @Test @@ -163,7 +168,7 @@ class StatsViewModelTest : BaseUnitTest() { viewModel.onSectionSelected(WEEKS) verify(statsSectionManager).setSelectedSection(WEEKS) - verify(analyticsTracker).trackGranular(STATS_PERIOD_WEEKS_ACCESSED, StatsGranularity.WEEKS) + verify(analyticsTracker).trackWithGranularity(STATS_PERIOD_WEEKS_ACCESSED, StatsGranularity.WEEKS) } @Test @@ -173,7 +178,7 @@ class StatsViewModelTest : BaseUnitTest() { viewModel.onSectionSelected(MONTHS) verify(statsSectionManager).setSelectedSection(MONTHS) - verify(analyticsTracker).trackGranular(STATS_PERIOD_MONTHS_ACCESSED, StatsGranularity.MONTHS) + verify(analyticsTracker).trackWithGranularity(STATS_PERIOD_MONTHS_ACCESSED, StatsGranularity.MONTHS) } @Test @@ -183,7 +188,7 @@ class StatsViewModelTest : BaseUnitTest() { viewModel.onSectionSelected(YEARS) verify(statsSectionManager).setSelectedSection(YEARS) - verify(analyticsTracker).trackGranular(STATS_PERIOD_YEARS_ACCESSED, StatsGranularity.YEARS) + verify(analyticsTracker).trackWithGranularity(STATS_PERIOD_YEARS_ACCESSED, StatsGranularity.YEARS) } @Test