From fccfbdf303ab0abc1f67b82d94900f0d7fc6d330 Mon Sep 17 00:00:00 2001 From: Roger Yang Date: Fri, 11 Feb 2022 12:19:13 -0500 Subject: [PATCH] Close #23694: Add telemetry for history search --- app/metrics.yaml | 26 +++++++++++++++++++ .../mozilla/fenix/components/metrics/Event.kt | 2 ++ .../components/metrics/GleanMetricsService.kt | 6 +++++ .../fenix/library/history/HistoryFragment.kt | 1 + .../history/HistorySearchController.kt | 4 +++ .../history/HistorySearchDialogFragment.kt | 2 ++ .../metrics/GleanMetricsServiceTest.kt | 8 ++++++ .../metrics/MetricControllerTest.kt | 6 +++++ .../history/HistorySearchControllerTest.kt | 5 ++++ 9 files changed, 60 insertions(+) diff --git a/app/metrics.yaml b/app/metrics.yaml index 9b5b7a8d6ded..cf8de907e594 100644 --- a/app/metrics.yaml +++ b/app/metrics.yaml @@ -3124,6 +3124,32 @@ history: notification_emails: - android-probes@mozilla.com expires: "2022-11-01" + search_icon_tapped: + type: event + description: | + A user tapped on the search icon in history. + bugs: + - TBD + data_reviews: + - TBD + data_sensitivity: + - interaction + notification_emails: + - android-probes@mozilla.com + expires: "2023-01-31" + search_result_tapped: + type: event + description: | + A user tapped on the search result in history. + bugs: + - TBD + data_reviews: + - TBD + data_sensitivity: + - interaction + notification_emails: + - android-probes@mozilla.com + expires: "2023-01-31" recently_closed_tabs: opened: 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 a3e86d1910df..bdc6524e9802 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 @@ -90,6 +90,8 @@ sealed class Event { object HistorySearchTermGroupOpenTab : Event() object HistorySearchTermGroupRemoveTab : Event() object HistorySearchTermGroupRemoveAll : Event() + object HistorySearchIconTapped : Event() + object HistorySearchResultTapped : Event() object RecentlyClosedTabsOpened : Event() object RecentlyClosedTabsClosed : Event() object RecentlyClosedTabsShowFullHistory : 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 1551d2a132eb..395b87ef3531 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 @@ -326,6 +326,12 @@ private val Event.wrapper: EventWrapper<*>? is Event.HistorySearchTermGroupRemoveAll -> EventWrapper( { History.searchTermGroupRemoveAll.record(it) } ) + is Event.HistorySearchIconTapped -> EventWrapper( + { History.searchIconTapped.record(it) } + ) + is Event.HistorySearchResultTapped -> EventWrapper( + { History.searchResultTapped.record(it) } + ) is Event.RecentlyClosedTabsOpened -> EventWrapper( { RecentlyClosedTabs.opened.record(it) } ) diff --git a/app/src/main/java/org/mozilla/fenix/library/history/HistoryFragment.kt b/app/src/main/java/org/mozilla/fenix/library/history/HistoryFragment.kt index 39862bc6323a..1c43bc5a4d07 100644 --- a/app/src/main/java/org/mozilla/fenix/library/history/HistoryFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/library/history/HistoryFragment.kt @@ -244,6 +244,7 @@ class HistoryFragment : LibraryPageFragment(), UserInteractionHandler { true } R.id.history_search -> { + requireComponents.analytics.metrics.track(Event.HistorySearchIconTapped) historyInteractor.onSearch() true } diff --git a/app/src/main/java/org/mozilla/fenix/library/history/HistorySearchController.kt b/app/src/main/java/org/mozilla/fenix/library/history/HistorySearchController.kt index 9f423a297625..e4d77760995a 100644 --- a/app/src/main/java/org/mozilla/fenix/library/history/HistorySearchController.kt +++ b/app/src/main/java/org/mozilla/fenix/library/history/HistorySearchController.kt @@ -7,6 +7,8 @@ package org.mozilla.fenix.library.history import mozilla.components.concept.engine.EngineSession.LoadUrlFlags import org.mozilla.fenix.BrowserDirection import org.mozilla.fenix.HomeActivity +import org.mozilla.fenix.components.metrics.Event +import org.mozilla.fenix.components.metrics.MetricController /** * An interface that handles the view manipulation of the History Search, triggered by the Interactor @@ -19,6 +21,7 @@ interface HistorySearchController { class HistorySearchDialogController( private val activity: HomeActivity, + private val metrics: MetricController? = null, private val fragmentStore: HistorySearchFragmentStore, private val clearToolbarFocus: () -> Unit, ) : HistorySearchController { @@ -32,6 +35,7 @@ class HistorySearchDialogController( } override fun handleUrlTapped(url: String, flags: LoadUrlFlags) { + metrics?.track(Event.HistorySearchResultTapped) clearToolbarFocus() activity.openToBrowserAndLoad( diff --git a/app/src/main/java/org/mozilla/fenix/library/history/HistorySearchDialogFragment.kt b/app/src/main/java/org/mozilla/fenix/library/history/HistorySearchDialogFragment.kt index 1e31005d8769..feadca8991f0 100644 --- a/app/src/main/java/org/mozilla/fenix/library/history/HistorySearchDialogFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/library/history/HistorySearchDialogFragment.kt @@ -37,6 +37,7 @@ import org.mozilla.fenix.R import org.mozilla.fenix.components.toolbar.ToolbarPosition import org.mozilla.fenix.databinding.FragmentHistorySearchDialogBinding import org.mozilla.fenix.databinding.SearchSuggestionsHintBinding +import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.settings import org.mozilla.fenix.library.history.awesomebar.AwesomeBarView import org.mozilla.fenix.library.history.toolbar.ToolbarView @@ -82,6 +83,7 @@ class HistorySearchDialogFragment : AppCompatDialogFragment(), UserInteractionHa interactor = HistorySearchDialogInteractor( HistorySearchDialogController( activity = activity, + metrics = activity.components.analytics.metrics, fragmentStore = store, clearToolbarFocus = { dialogHandledAction = true 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 fc8526d3c9c5..57535d146ce4 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 @@ -189,6 +189,14 @@ class GleanMetricsServiceTest { assertFalse(History.searchTermGroupRemoveAll.testHasValue()) gleanService.track(Event.HistorySearchTermGroupRemoveAll) assertTrue(History.searchTermGroupRemoveAll.testHasValue()) + + assertFalse(History.searchIconTapped.testHasValue()) + gleanService.track(Event.HistorySearchIconTapped) + assertTrue(History.searchIconTapped.testHasValue()) + + assertFalse(History.searchResultTapped.testHasValue()) + gleanService.track(Event.HistorySearchResultTapped) + assertTrue(History.searchResultTapped.testHasValue()) } @Test diff --git a/app/src/test/java/org/mozilla/fenix/components/metrics/MetricControllerTest.kt b/app/src/test/java/org/mozilla/fenix/components/metrics/MetricControllerTest.kt index 9040191593d7..d113faf4f856 100644 --- a/app/src/test/java/org/mozilla/fenix/components/metrics/MetricControllerTest.kt +++ b/app/src/test/java/org/mozilla/fenix/components/metrics/MetricControllerTest.kt @@ -340,6 +340,8 @@ class MetricControllerTest { every { marketingService1.shouldTrack(Event.HistorySearchTermGroupOpenTab) } returns true every { marketingService1.shouldTrack(Event.HistorySearchTermGroupRemoveTab) } returns true every { marketingService1.shouldTrack(Event.HistorySearchTermGroupRemoveAll) } returns true + every { marketingService1.shouldTrack(Event.HistorySearchIconTapped) } returns true + every { marketingService1.shouldTrack(Event.HistorySearchResultTapped) } returns true controller.start(MetricServiceType.Marketing) @@ -354,6 +356,8 @@ class MetricControllerTest { controller.track(Event.HistorySearchTermGroupOpenTab) controller.track(Event.HistorySearchTermGroupRemoveTab) controller.track(Event.HistorySearchTermGroupRemoveAll) + controller.track(Event.HistorySearchIconTapped) + controller.track(Event.HistorySearchResultTapped) verify { marketingService1.track(Event.HistoryOpenedInNewTab) } verify { marketingService1.track(Event.HistoryOpenedInNewTabs) } @@ -366,6 +370,8 @@ class MetricControllerTest { verify { marketingService1.track(Event.HistorySearchTermGroupOpenTab) } verify { marketingService1.track(Event.HistorySearchTermGroupRemoveTab) } verify { marketingService1.track(Event.HistorySearchTermGroupRemoveAll) } + verify { marketingService1.track(Event.HistorySearchIconTapped) } + verify { marketingService1.track(Event.HistorySearchResultTapped) } } @Test diff --git a/app/src/test/java/org/mozilla/fenix/library/history/HistorySearchControllerTest.kt b/app/src/test/java/org/mozilla/fenix/library/history/HistorySearchControllerTest.kt index b8089b38aa5a..859f6ab3d50c 100644 --- a/app/src/test/java/org/mozilla/fenix/library/history/HistorySearchControllerTest.kt +++ b/app/src/test/java/org/mozilla/fenix/library/history/HistorySearchControllerTest.kt @@ -14,11 +14,14 @@ import org.junit.Before import org.junit.Test import org.mozilla.fenix.BrowserDirection import org.mozilla.fenix.HomeActivity +import org.mozilla.fenix.components.metrics.Event +import org.mozilla.fenix.components.metrics.MetricController class HistorySearchControllerTest { @MockK(relaxed = true) private lateinit var activity: HomeActivity @MockK(relaxed = true) private lateinit var store: HistorySearchFragmentStore + @MockK(relaxed = true) private lateinit var metrics: MetricController @Before fun setUp() { @@ -64,6 +67,7 @@ class HistorySearchControllerTest { createController().handleUrlTapped(url) verify { + metrics.track(Event.HistorySearchResultTapped) activity.openToBrowserAndLoad( searchTermOrURL = url, newTab = true, @@ -78,6 +82,7 @@ class HistorySearchControllerTest { ): HistorySearchDialogController { return HistorySearchDialogController( activity = activity, + metrics = metrics, fragmentStore = store, clearToolbarFocus = clearToolbarFocus, )