Skip to content

Commit

Permalink
Close mozilla-mobile#23694: Add telemetry for history search
Browse files Browse the repository at this point in the history
  • Loading branch information
rocketsroger committed Feb 15, 2022
1 parent 96cda67 commit 42a862f
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 0 deletions.
26 changes: 26 additions & 0 deletions app/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
- https://github.com/mozilla-mobile/fenix/issues/23694
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/23695
data_sensitivity:
- interaction
notification_emails:
- android-probes@mozilla.com
expires: "2023-03-31"
search_result_tapped:
type: event
description: |
A user tapped on the search result in history.
bugs:
- https://github.com/mozilla-mobile/fenix/issues/23694
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/23695
data_sensitivity:
- interaction
notification_emails:
- android-probes@mozilla.com
expires: "2023-03-31"

recently_closed_tabs:
opened:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,12 @@ private val Event.wrapper: EventWrapper<*>?
is Event.HistorySearchTermGroupRemoveAll -> EventWrapper<NoExtraKeys>(
{ History.searchTermGroupRemoveAll.record(it) }
)
is Event.HistorySearchIconTapped -> EventWrapper<NoExtraKeys>(
{ History.searchIconTapped.record(it) }
)
is Event.HistorySearchResultTapped -> EventWrapper<NoExtraKeys>(
{ History.searchResultTapped.record(it) }
)
is Event.RecentlyClosedTabsOpened -> EventWrapper<NoExtraKeys>(
{ RecentlyClosedTabs.opened.record(it) }
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ class HistoryFragment : LibraryPageFragment<History>(), UserInteractionHandler {
true
}
R.id.history_search -> {
requireComponents.analytics.metrics.track(Event.HistorySearchIconTapped)
historyInteractor.onSearch()
true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,6 +21,7 @@ interface HistorySearchController {

class HistorySearchDialogController(
private val activity: HomeActivity,
private val metrics: MetricController,
private val fragmentStore: HistorySearchFragmentStore,
private val clearToolbarFocus: () -> Unit,
) : HistorySearchController {
Expand All @@ -32,6 +35,7 @@ class HistorySearchDialogController(
}

override fun handleUrlTapped(url: String, flags: LoadUrlFlags) {
metrics.track(Event.HistorySearchResultTapped)
clearToolbarFocus()

activity.openToBrowserAndLoad(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -82,6 +83,7 @@ class HistorySearchDialogFragment : AppCompatDialogFragment(), UserInteractionHa
interactor = HistorySearchDialogInteractor(
HistorySearchDialogController(
activity = activity,
metrics = activity.components.analytics.metrics,
fragmentStore = store,
clearToolbarFocus = {
dialogHandledAction = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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) }
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -64,6 +67,7 @@ class HistorySearchControllerTest {
createController().handleUrlTapped(url)

verify {
metrics.track(Event.HistorySearchResultTapped)
activity.openToBrowserAndLoad(
searchTermOrURL = url,
newTab = true,
Expand All @@ -78,6 +82,7 @@ class HistorySearchControllerTest {
): HistorySearchDialogController {
return HistorySearchDialogController(
activity = activity,
metrics = metrics,
fragmentStore = store,
clearToolbarFocus = clearToolbarFocus,
)
Expand Down

0 comments on commit 42a862f

Please sign in to comment.