diff --git a/app/metrics.yaml b/app/metrics.yaml index 065588a029eb..8a93438ba53b 100644 --- a/app/metrics.yaml +++ b/app/metrics.yaml @@ -5961,3 +5961,31 @@ recent_tabs: notification_emails: - android-probes@mozilla.com expires: "2022-06-23" +recent_bookmarks: + bookmark_clicked: + type: event + description: | + A recently saved bookmark was clicked on the home screen. + bugs: + - https://github.com/mozilla-mobile/fenix/issues/19931 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/TBD... + data_sensitivity: + - interaction + notification_emails: + - android-probes@mozilla.com + expires: "2022-01-31" + show_all_clicked: + type: event + description: | + The show all button was clicked on the recently saved + bookmarks section of the home screen. + bugs: + - https://github.com/mozilla-mobile/fenix/issues/19931 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/TBD... + data_sensitivity: + - interaction + notification_emails: + - android-probes@mozilla.com + expires: "2022-01-31" 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 07091a485cf3..30ebe5b61cb0 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 @@ -249,6 +249,10 @@ sealed class Event { object OpenRecentTab : Event() object OpenInProgressMediaTab : Event() + // Recent bookmarks on Home + object RecentBookmarkClicked : Event() + object RecentBookmarkShowAll : Event() + // Interaction events with extras data class TopSiteSwipeCarousel(val page: Int) : 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 6a5bee9e2491..10e70d9c7fc5 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 @@ -862,6 +863,14 @@ private val Event.wrapper: EventWrapper<*>? { RecentTabs.showAllClicked.record(it) } ) + is Event.RecentBookmarkClicked -> EventWrapper( + { RecentBookmarks.bookmarkClicked.record(it) } + ) + + is Event.RecentBookmarkShowAll -> EventWrapper( + { RecentBookmarks.showAllClicked.record(it) } + ) + // Don't record other events in Glean: is Event.AddBookmark -> null is Event.OpenedAppFirstRun -> null 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 ebb788f73bbd..6eaf45b138d3 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 @@ -10,6 +10,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.ext.nav import org.mozilla.fenix.home.HomeFragmentDirections import org.mozilla.fenix.home.recentbookmarks.interactor.RecentBookmarksInteractor @@ -45,9 +47,11 @@ class DefaultRecentBookmarksController( newTab = true, from = BrowserDirection.FromHome ) + activity.components.core.metrics.track(Event.RecentBookmarkClicked) } override fun handleShowAllBookmarksClicked() { + activity.components.core.metrics.track(Event.RecentBookmarkShowAll) val directions = HomeFragmentDirections.actionGlobalBookmarkFragment(BookmarkRoot.Mobile.id) navController.nav(R.id.homeFragment, directions) } 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 f2e391ac3584..10d2af838955 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 @@ -14,6 +14,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 @@ -25,6 +26,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 @@ -38,11 +42,13 @@ 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 } @@ -79,14 +85,19 @@ class DefaultRecentBookmarksControllerTest { newTab = true, from = BrowserDirection.FromHome ) + metrics.track(Event.RecentBookmarkClicked) } } @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 { controller.handleShowAllBookmarksClicked() val directions = HomeFragmentDirections.actionGlobalBookmarkFragment(BookmarkRoot.Mobile.id) - verify { navController.navigate(directions, any()) } + + verify { + metrics.track(Event.RecentBookmarkShowAll) + navController.navigate(directions, any()) + } } }