From 9049513017bbe74218d4d4ccb6de8e850eaa02f1 Mon Sep 17 00:00:00 2001 From: Roger Yang Date: Mon, 8 Mar 2021 19:15:29 -0500 Subject: [PATCH] Closes #18178: Rework History Telemetry (#18261) --- app/metrics.yaml | 59 +++++++++++++++++-- .../mozilla/fenix/components/metrics/Event.kt | 4 ++ .../components/metrics/GleanMetricsService.kt | 12 ++++ .../fenix/library/history/HistoryFragment.kt | 10 +++- .../metrics/GleanMetricsServiceTest.kt | 20 +++++++ .../metrics/MetricControllerTest.kt | 25 ++++++++ docs/metrics.md | 6 +- 7 files changed, 128 insertions(+), 8 deletions(-) diff --git a/app/metrics.yaml b/app/metrics.yaml index d6eff7b12..1b4c35809 100644 --- a/app/metrics.yaml +++ b/app/metrics.yaml @@ -2117,15 +2117,66 @@ history: description: | A user opened a history item bugs: - - https://github.com/mozilla-mobile/fenix/issues/2362 + - https://github.com/mozilla-mobile/fenix/issues/18178 data_reviews: - - https://github.com/mozilla-mobile/fenix/pull/3940 - - https://github.com/mozilla-mobile/fenix/pull/15713#issuecomment-703972068 + - https://github.com/mozilla-mobile/fenix/pull/18261 data_sensitivity: - interaction notification_emails: - fenix-core@mozilla.com - expires: "2021-08-01" + expires: "2022-08-01" + opened_item_in_new_tab: + type: event + description: | + A user opened a history item in a new tab + bugs: + - https://github.com/mozilla-mobile/fenix/issues/18178 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/18261 + data_sensitivity: + - interaction + notification_emails: + - fenix-core@mozilla.com + expires: "2022-08-01" + opened_items_in_new_tabs: + type: event + description: | + A user opened multiple history items in new tabs + bugs: + - https://github.com/mozilla-mobile/fenix/issues/18178 + data_reviews: + - https://gith ub.com/mozilla-mobile/fenix/pull/18261 + data_sensitivity: + - interaction + notification_emails: + - fenix-core@mozilla.com + expires: "2022-08-01" + opened_item_in_private_tab: + type: event + description: | + A user opened a history item in a private tab + bugs: + - https://github.com/mozilla-mobile/fenix/issues/18178 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/18261 + data_sensitivity: + - interaction + notification_emails: + - fenix-core@mozilla.com + expires: "2022-08-01" + opened_items_in_private_tabs: + type: event + description: | + A user opened multiple history items in private tabs + bugs: + - https://github.com/mozilla-mobile/fenix/issues/18178 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/18261 + data_sensitivity: + - interaction + notification_emails: + - fenix-core@mozilla.com + expires: "2022-08-01" tip: displayed: 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 23240bcf8..a91932209 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 @@ -73,6 +73,10 @@ sealed class Event { object HistoryOpened : Event() object HistoryItemShared : Event() object HistoryItemOpened : Event() + object HistoryOpenedInNewTab : Event() + object HistoryOpenedInNewTabs : Event() + object HistoryOpenedInPrivateTab : Event() + object HistoryOpenedInPrivateTabs : Event() object HistoryItemRemoved : Event() object HistoryAllItemsRemoved : Event() object ReaderModeAvailable : 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 20c164d3f..dfe1d517d 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 @@ -307,6 +307,18 @@ private val Event.wrapper: EventWrapper<*>? is Event.HistoryItemOpened -> EventWrapper( { History.openedItem.record(it) } ) + is Event.HistoryOpenedInNewTab -> EventWrapper( + { History.openedItemInNewTab.record(it) } + ) + is Event.HistoryOpenedInNewTabs -> EventWrapper( + { History.openedItemsInNewTabs.record(it) } + ) + is Event.HistoryOpenedInPrivateTab -> EventWrapper( + { History.openedItemInPrivateTab.record(it) } + ) + is Event.HistoryOpenedInPrivateTabs -> EventWrapper( + { History.openedItemsInPrivateTabs.record(it) } + ) is Event.HistoryItemRemoved -> EventWrapper( { History.removed.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 259d7ce11..e3a826621 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 @@ -188,7 +188,7 @@ class HistoryFragment : LibraryPageFragment(), UserInteractionHandl } R.id.open_history_in_new_tabs_multi_select -> { openItemsInNewTab { selectedItem -> - requireComponents.analytics.metrics.track(Event.HistoryItemOpened) + requireComponents.analytics.metrics.track(Event.HistoryOpenedInNewTabs) selectedItem.url } @@ -197,7 +197,7 @@ class HistoryFragment : LibraryPageFragment(), UserInteractionHandl } R.id.open_history_in_private_tabs_multi_select -> { openItemsInNewTab(private = true) { selectedItem -> - requireComponents.analytics.metrics.track(Event.HistoryItemOpened) + requireComponents.analytics.metrics.track(Event.HistoryOpenedInPrivateTabs) selectedItem.url } @@ -248,7 +248,11 @@ class HistoryFragment : LibraryPageFragment(), UserInteractionHandl } private fun openItem(item: HistoryItem, mode: BrowsingMode? = null) { - requireComponents.analytics.metrics.track(Event.HistoryItemOpened) + when (mode?.isPrivate) { + true -> requireComponents.analytics.metrics.track(Event.HistoryOpenedInPrivateTab) + false -> requireComponents.analytics.metrics.track(Event.HistoryOpenedInNewTab) + null -> requireComponents.analytics.metrics.track(Event.HistoryItemOpened) + } mode?.let { (activity as HomeActivity).browsingModeManager.mode = it } 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 8095c5b2b..e46ff7356 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 @@ -20,6 +20,7 @@ import org.junit.runner.RunWith 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.Metrics import org.mozilla.fenix.GleanMetrics.SearchDefaultEngine import org.mozilla.fenix.GleanMetrics.SyncedTabs @@ -177,4 +178,23 @@ class GleanMetricsServiceTest { gleanService.track(Event.RemoveBookmarkFolder) assertTrue(BookmarksManagement.folderRemove.testHasValue()) } + + @Test + fun `History events is correctly recorded`() { + assertFalse(History.openedItemInNewTab.testHasValue()) + gleanService.track(Event.HistoryOpenedInNewTab) + assertTrue(History.openedItemInNewTab.testHasValue()) + + assertFalse(History.openedItemsInNewTabs.testHasValue()) + gleanService.track(Event.HistoryOpenedInNewTabs) + assertTrue(History.openedItemsInNewTabs.testHasValue()) + + assertFalse(History.openedItemInPrivateTab.testHasValue()) + gleanService.track(Event.HistoryOpenedInPrivateTab) + assertTrue(History.openedItemInPrivateTab.testHasValue()) + + assertFalse(History.openedItemsInPrivateTabs.testHasValue()) + gleanService.track(Event.HistoryOpenedInPrivateTabs) + assertTrue(History.openedItemsInPrivateTabs.testHasValue()) + } } 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 50472ab1a..01fd81be2 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 @@ -330,4 +330,29 @@ class MetricControllerTest { verify { marketingService1.track(Event.RemoveBookmarkFolder) } verify { marketingService1.track(Event.RemoveBookmarks) } } + + @Test + fun `history events should be sent to enabled service`() { + val controller = ReleaseMetricController( + listOf(marketingService1), + isDataTelemetryEnabled = { true }, + isMarketingDataTelemetryEnabled = { true } + ) + every { marketingService1.shouldTrack(Event.HistoryOpenedInNewTab) } returns true + every { marketingService1.shouldTrack(Event.HistoryOpenedInNewTabs) } returns true + every { marketingService1.shouldTrack(Event.HistoryOpenedInPrivateTab) } returns true + every { marketingService1.shouldTrack(Event.HistoryOpenedInPrivateTabs) } returns true + + controller.start(MetricServiceType.Marketing) + + controller.track(Event.HistoryOpenedInNewTab) + controller.track(Event.HistoryOpenedInNewTabs) + controller.track(Event.HistoryOpenedInPrivateTab) + controller.track(Event.HistoryOpenedInPrivateTabs) + + verify { marketingService1.track(Event.HistoryOpenedInNewTab) } + verify { marketingService1.track(Event.HistoryOpenedInNewTabs) } + verify { marketingService1.track(Event.HistoryOpenedInPrivateTab) } + verify { marketingService1.track(Event.HistoryOpenedInPrivateTabs) } + } } diff --git a/docs/metrics.md b/docs/metrics.md index d41ec4c1a..053678beb 100644 --- a/docs/metrics.md +++ b/docs/metrics.md @@ -138,7 +138,11 @@ In addition to those built-in metrics, the following metrics are added to the pi | find_in_page.opened |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user opened the find in page UI |[mozilla-mobile/fenix#1344](https://github.com/mozilla-mobile/fenix/pull/1344#issuecomment-479285010), [mozilla-mobile/fenix#15713](https://github.com/mozilla-mobile/fenix/pull/15713#issuecomment-703972068)||2021-08-01 |2 | | find_in_page.searched_page |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user searched the page |[mozilla-mobile/fenix#1344](https://github.com/mozilla-mobile/fenix/pull/1344#issuecomment-479285010), [mozilla-mobile/fenix#15713](https://github.com/mozilla-mobile/fenix/pull/15713#issuecomment-703972068)||2021-08-01 |2 | | history.opened |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user opened the history screen |[mozilla-mobile/fenix#3940](https://github.com/mozilla-mobile/fenix/pull/3940), [mozilla-mobile/fenix#15713](https://github.com/mozilla-mobile/fenix/pull/15713#issuecomment-703972068)||2021-08-01 |2 | -| history.opened_item |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user opened a history item |[mozilla-mobile/fenix#3940](https://github.com/mozilla-mobile/fenix/pull/3940), [mozilla-mobile/fenix#15713](https://github.com/mozilla-mobile/fenix/pull/15713#issuecomment-703972068)||2021-08-01 |2 | +| history.opened_item |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user opened a history item |[mozilla-mobile/fenix#18261](https://github.com/mozilla-mobile/fenix/pull/18261)||2022-08-01 |2 | +| history.opened_item_in_new_tab |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user opened a history item in a new tab |[mozilla-mobile/fenix#18261](https://github.com/mozilla-mobile/fenix/pull/18261)||2022-08-01 |2 | +| history.opened_item_in_private_tab |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user opened a history item in a private tab |[mozilla-mobile/fenix#18261](https://github.com/mozilla-mobile/fenix/pull/18261)||2022-08-01 |2 | +| history.opened_items_in_new_tabs |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user opened multiple history items in new tabs |[Review 1](https://gith ub.com/mozilla-mobile/fenix/pull/18261)||2022-08-01 |2 | +| history.opened_items_in_private_tabs |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user opened multiple history items in private tabs |[mozilla-mobile/fenix#18261](https://github.com/mozilla-mobile/fenix/pull/18261)||2022-08-01 |2 | | history.removed |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user removed a history item |[mozilla-mobile/fenix#3940](https://github.com/mozilla-mobile/fenix/pull/3940), [mozilla-mobile/fenix#15713](https://github.com/mozilla-mobile/fenix/pull/15713#issuecomment-703972068)||2021-08-01 |2 | | history.removed_all |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user removed all history items |[mozilla-mobile/fenix#3940](https://github.com/mozilla-mobile/fenix/pull/3940), [mozilla-mobile/fenix#15713](https://github.com/mozilla-mobile/fenix/pull/15713#issuecomment-703972068)||2021-08-01 |2 | | history.shared |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user shared a history item |[mozilla-mobile/fenix#3940](https://github.com/mozilla-mobile/fenix/pull/3940), [mozilla-mobile/fenix#15713](https://github.com/mozilla-mobile/fenix/pull/15713#issuecomment-703972068)||2021-08-01 |2 |