From 41825022e76485a00330bbb67b84177922b0e440 Mon Sep 17 00:00:00 2001 From: Elise Richards Date: Tue, 24 Aug 2021 12:30:13 -0700 Subject: [PATCH] For #19931: Add telemetry probes for recent bookmarks on home screen (#20316) * Add telemetry probes for recent bookmarks on home screen. Tests for controller. * Make the events into counters in the metrics ping Update tests to reflect new metrics Add data review link for new metrics Mock new settings for startup metrics tests Update metrics Add test for recent bookmark glean events * Recent bookmarks controller tests --- app/metrics.yaml | 38 +++++++++++++++++++ .../mozilla/fenix/components/metrics/Event.kt | 4 ++ .../components/metrics/GleanMetricsService.kt | 9 +++++ .../controller/RecentBookmarksController.kt | 4 ++ .../metrics/GleanMetricsServiceTest.kt | 12 ++++++ .../DefaultRecentBookmarksControllerTest.kt | 17 ++++++++- 6 files changed, 82 insertions(+), 2 deletions(-) diff --git a/app/metrics.yaml b/app/metrics.yaml index 003f505232dd..71f06b483d7d 100644 --- a/app/metrics.yaml +++ b/app/metrics.yaml @@ -5750,3 +5750,41 @@ recent_tabs: notification_emails: - android-probes@mozilla.com expires: "2022-06-23" + +recent_bookmarks: + bookmark_clicked: + type: counter + lifetime: application + description: | + A counter that indicates the number of times that a user + has clicked on a recently saved bookmark from the home + screen. + send_in_pings: + - metrics + bugs: + - https://github.com/mozilla-mobile/fenix/issues/19931 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/20316#issuecomment-888291843 + data_sensitivity: + - interaction + notification_emails: + - android-probes@mozilla.com + expires: "2022-02-01" + show_all_bookmarks: + type: counter + lifetime: application + description: | + A counter that indicates the number of times that a user + has clicked the show all button for recently saved bookmarks + on the home screen. + send_in_pings: + - metrics + bugs: + - https://github.com/mozilla-mobile/fenix/issues/19931 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/20316#issuecomment-888291843 + data_sensitivity: + - interaction + notification_emails: + - android-probes@mozilla.com + expires: "2022-02-01" diff --git a/app/src/main/java/org/mozilla/fenix/components/metrics/Event.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/Event.kt index bb50f927b5a7..95968bd52bba 100644 --- a/app/src/main/java/org/mozilla/fenix/components/metrics/Event.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/Event.kt @@ -251,6 +251,10 @@ sealed class Event { object OpenRecentTab : Event() object OpenInProgressMediaTab : Event() + // Recent bookmarks + object BookmarkClicked : Event() + object ShowAllBookmarks : Event() + // Android Autofill object AndroidAutofillUnlockSuccessful : Event() object AndroidAutofillUnlockCanceled : Event() diff --git a/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt index 7472e4f0ecea..6fe49d5658e9 100644 --- a/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt @@ -46,6 +46,7 @@ import org.mozilla.fenix.GleanMetrics.PrivateBrowsingMode import org.mozilla.fenix.GleanMetrics.PrivateBrowsingShortcut import org.mozilla.fenix.GleanMetrics.ProgressiveWebApp import org.mozilla.fenix.GleanMetrics.ReaderMode +import org.mozilla.fenix.GleanMetrics.RecentBookmarks import org.mozilla.fenix.GleanMetrics.RecentTabs import org.mozilla.fenix.GleanMetrics.SearchShortcuts import org.mozilla.fenix.GleanMetrics.SearchSuggestions @@ -853,6 +854,14 @@ private val Event.wrapper: EventWrapper<*>? { RecentTabs.showAllClicked.record(it) } ) + is Event.BookmarkClicked -> EventWrapper( + { RecentBookmarks.bookmarkClicked.add() } + ) + + is Event.ShowAllBookmarks -> EventWrapper( + { RecentBookmarks.showAllBookmarks.add() } + ) + is Event.AndroidAutofillRequestWithLogins -> EventWrapper( { AndroidAutofill.requestMatchingLogins.record(it) } ) diff --git a/app/src/main/java/org/mozilla/fenix/home/recentbookmarks/controller/RecentBookmarksController.kt b/app/src/main/java/org/mozilla/fenix/home/recentbookmarks/controller/RecentBookmarksController.kt index 66eaf473fdaa..456c1dc55ec0 100644 --- a/app/src/main/java/org/mozilla/fenix/home/recentbookmarks/controller/RecentBookmarksController.kt +++ b/app/src/main/java/org/mozilla/fenix/home/recentbookmarks/controller/RecentBookmarksController.kt @@ -12,6 +12,8 @@ import mozilla.components.concept.storage.BookmarkNode import org.mozilla.fenix.BrowserDirection import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.R +import org.mozilla.fenix.components.metrics.Event +import org.mozilla.fenix.ext.components import org.mozilla.fenix.home.HomeFragmentDirections import org.mozilla.fenix.home.recentbookmarks.interactor.RecentBookmarksInteractor @@ -47,9 +49,11 @@ class DefaultRecentBookmarksController( newTab = true, from = BrowserDirection.FromHome ) + activity.components.core.metrics.track(Event.BookmarkClicked) } override fun handleShowAllBookmarksClicked() { + activity.components.core.metrics.track(Event.ShowAllBookmarks) dismissSearchDialogIfDisplayed() navController.navigate( HomeFragmentDirections.actionGlobalBookmarkFragment(BookmarkRoot.Mobile.id) diff --git a/app/src/test/java/org/mozilla/fenix/components/metrics/GleanMetricsServiceTest.kt b/app/src/test/java/org/mozilla/fenix/components/metrics/GleanMetricsServiceTest.kt index 12e6170fb9b8..2816e340f16a 100644 --- a/app/src/test/java/org/mozilla/fenix/components/metrics/GleanMetricsServiceTest.kt +++ b/app/src/test/java/org/mozilla/fenix/components/metrics/GleanMetricsServiceTest.kt @@ -19,6 +19,7 @@ import org.mozilla.fenix.GleanMetrics.Awesomebar import org.mozilla.fenix.GleanMetrics.BookmarksManagement import org.mozilla.fenix.GleanMetrics.Events import org.mozilla.fenix.GleanMetrics.History +import org.mozilla.fenix.GleanMetrics.RecentBookmarks import org.mozilla.fenix.GleanMetrics.SyncedTabs import org.mozilla.fenix.GleanMetrics.TabsTray import org.mozilla.fenix.helpers.FenixRobolectricTestRunner @@ -277,4 +278,15 @@ class GleanMetricsServiceTest { gleanService.track(Event.DefaultBrowserNotifTapped) assertTrue(Events.defaultBrowserNotifTapped.testHasValue()) } + + @Test + fun `Home screen recent bookmarks events are correctly recorded`() { + assertFalse(RecentBookmarks.bookmarkClicked.testHasValue()) + gleanService.track(Event.BookmarkClicked) + assertTrue(RecentBookmarks.bookmarkClicked.testHasValue()) + + assertFalse(RecentBookmarks.showAllBookmarks.testHasValue()) + gleanService.track(Event.ShowAllBookmarks) + assertTrue(RecentBookmarks.showAllBookmarks.testHasValue()) + } } diff --git a/app/src/test/java/org/mozilla/fenix/home/recentbookmarks/DefaultRecentBookmarksControllerTest.kt b/app/src/test/java/org/mozilla/fenix/home/recentbookmarks/DefaultRecentBookmarksControllerTest.kt index 5efba0017a12..8a0a64eded73 100644 --- a/app/src/test/java/org/mozilla/fenix/home/recentbookmarks/DefaultRecentBookmarksControllerTest.kt +++ b/app/src/test/java/org/mozilla/fenix/home/recentbookmarks/DefaultRecentBookmarksControllerTest.kt @@ -13,6 +13,7 @@ import io.mockk.spyk import io.mockk.verify import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.TestCoroutineDispatcher +import kotlinx.coroutines.test.runBlockingTest import mozilla.appservices.places.BookmarkRoot import mozilla.components.concept.storage.BookmarkNode import mozilla.components.concept.storage.BookmarkNodeType @@ -24,6 +25,9 @@ import org.junit.Test import org.mozilla.fenix.BrowserDirection import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.R +import org.mozilla.fenix.components.metrics.Event +import org.mozilla.fenix.components.metrics.MetricController +import org.mozilla.fenix.ext.components import org.mozilla.fenix.home.HomeFragmentDirections import org.mozilla.fenix.home.recentbookmarks.controller.DefaultRecentBookmarksController @@ -37,12 +41,18 @@ class DefaultRecentBookmarksControllerTest { private val activity: HomeActivity = mockk(relaxed = true) private val navController: NavController = mockk(relaxUnitFun = true) + private val metrics: MetricController = mockk(relaxed = true) private lateinit var controller: DefaultRecentBookmarksController @Before fun setup() { every { activity.openToBrowserAndLoad(any(), any(), any()) } just Runs + every { activity.components.core.metrics } returns metrics + + every { navController.currentDestination } returns mockk { + every { id } returns R.id.homeFragment + } every { navController.navigateUp() } returns true controller = spyk( @@ -85,13 +95,14 @@ class DefaultRecentBookmarksControllerTest { from = BrowserDirection.FromHome ) } + verify { metrics.track(Event.BookmarkClicked) } verify(exactly = 0) { navController.navigateUp() } } @Test - fun `WHEN show all recently saved bookmark is clicked THEN the bookmarks root is opened`() { + fun `WHEN show all recently saved bookmark is clicked THEN the bookmarks root is opened`() = runBlockingTest { every { navController.currentDestination } returns mockk { every { id } returns R.id.homeFragment } @@ -100,8 +111,8 @@ class DefaultRecentBookmarksControllerTest { val directions = HomeFragmentDirections.actionGlobalBookmarkFragment(BookmarkRoot.Mobile.id) verify { - controller.dismissSearchDialogIfDisplayed() navController.navigate(directions) + metrics.track(Event.ShowAllBookmarks) } verify(exactly = 0) { navController.navigateUp() @@ -117,10 +128,12 @@ class DefaultRecentBookmarksControllerTest { controller.handleShowAllBookmarksClicked() val directions = HomeFragmentDirections.actionGlobalBookmarkFragment(BookmarkRoot.Mobile.id) + verify { controller.dismissSearchDialogIfDisplayed() navController.navigateUp() navController.navigate(directions) + metrics.track(Event.ShowAllBookmarks) } } }