From 2322cbdd0ef0e3edb7bb3ac731864cfc79e211b9 Mon Sep 17 00:00:00 2001 From: Roger Yang Date: Mon, 8 Mar 2021 16:34:52 -0500 Subject: [PATCH] Closes #18068: Use AwesomeBarFacts for AwesomeBar Telemetry (#18090) --- app/metrics.yaml | 80 +++++++++++++++++++ .../mozilla/fenix/components/metrics/Event.kt | 6 ++ .../components/metrics/GleanMetricsService.kt | 20 +++++ .../components/metrics/MetricController.kt | 19 +++++ .../metrics/GleanMetricsServiceTest.kt | 30 ++++++- .../metrics/MetricControllerTest.kt | 34 ++++++++ docs/metrics.md | 6 ++ 7 files changed, 194 insertions(+), 1 deletion(-) diff --git a/app/metrics.yaml b/app/metrics.yaml index 362102e3a..b48c396bf 100644 --- a/app/metrics.yaml +++ b/app/metrics.yaml @@ -4553,3 +4553,83 @@ synced_tabs: notification_emails: - fenix-core@mozilla.com expires: "2021-08-01" + +awesomebar: + bookmark_suggestion_clicked: + type: event + description: | + The bookmark suggestion in awesomebar was clicked. + bugs: + - https://github.com/mozilla-mobile/fenix/issues/18068 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/18090 + data_sensitivity: + - interaction + notification_emails: + - fenix-core@mozilla.com + expires: "2021-08-01" + clipboard_suggestion_clicked: + type: event + description: | + The clipboard suggestion in awesomebar was clicked. + bugs: + - https://github.com/mozilla-mobile/fenix/issues/18068 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/18090 + data_sensitivity: + - interaction + notification_emails: + - fenix-core@mozilla.com + expires: "2021-08-01" + history_suggestion_clicked: + type: event + description: | + The history suggestion in awesomebar was clicked. + bugs: + - https://github.com/mozilla-mobile/fenix/issues/18068 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/18090 + data_sensitivity: + - interaction + notification_emails: + - fenix-core@mozilla.com + expires: "2021-08-01" + search_action_clicked: + type: event + description: | + The search action in awesomebar was clicked. + bugs: + - https://github.com/mozilla-mobile/fenix/issues/18068 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/18090 + data_sensitivity: + - interaction + notification_emails: + - fenix-core@mozilla.com + expires: "2021-08-01" + search_suggestion_clicked: + type: event + description: | + The search suggestion in awesomebar was clicked. + bugs: + - https://github.com/mozilla-mobile/fenix/issues/18068 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/18090 + data_sensitivity: + - interaction + notification_emails: + - fenix-core@mozilla.com + expires: "2021-08-01" + opened_tab_suggestion_clicked: + type: event + description: | + The opened tab suggestion in awesomebar was clicked. + bugs: + - https://github.com/mozilla-mobile/fenix/issues/18068 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/18090 + data_sensitivity: + - interaction + notification_emails: + - fenix-core@mozilla.com + expires: "2021-08-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 bdbdfd819..23240bcf8 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 @@ -215,6 +215,12 @@ sealed class Event { object HaveNoTopSites : Event() object SyncedTabSuggestionClicked : Event() + object BookmarkSuggestionClicked : Event() + object ClipboardSuggestionClicked : Event() + object HistorySuggestionClicked : Event() + object SearchActionClicked : Event() + object SearchSuggestionClicked : Event() + object OpenedTabSuggestionClicked : Event() // Interaction events with extras 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 3e3304b09..7507bac1e 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 @@ -17,6 +17,7 @@ import org.mozilla.fenix.GleanMetrics.AboutPage import org.mozilla.fenix.GleanMetrics.Addons import org.mozilla.fenix.GleanMetrics.AppTheme import org.mozilla.fenix.GleanMetrics.Autoplay +import org.mozilla.fenix.GleanMetrics.Awesomebar import org.mozilla.fenix.GleanMetrics.BannerOpenInApp import org.mozilla.fenix.GleanMetrics.BookmarksManagement import org.mozilla.fenix.GleanMetrics.BrowserSearch @@ -754,6 +755,25 @@ private val Event.wrapper: EventWrapper<*>? { SyncedTabs.syncedTabsSuggestionClicked.record(it) } ) + is Event.BookmarkSuggestionClicked -> EventWrapper( + { Awesomebar.bookmarkSuggestionClicked.record(it) } + ) + is Event.ClipboardSuggestionClicked -> EventWrapper( + { Awesomebar.clipboardSuggestionClicked.record(it) } + ) + is Event.HistorySuggestionClicked -> EventWrapper( + { Awesomebar.historySuggestionClicked.record(it) } + ) + is Event.SearchActionClicked -> EventWrapper( + { Awesomebar.searchActionClicked.record(it) } + ) + is Event.SearchSuggestionClicked -> EventWrapper( + { Awesomebar.searchSuggestionClicked.record(it) } + ) + is Event.OpenedTabSuggestionClicked -> EventWrapper( + { Awesomebar.openedTabSuggestionClicked.record(it) } + ) + // Don't record other events in Glean: is Event.AddBookmark -> null is Event.OpenedBookmark -> null diff --git a/app/src/main/java/org/mozilla/fenix/components/metrics/MetricController.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/MetricController.kt index 19e220447..649ace833 100644 --- a/app/src/main/java/org/mozilla/fenix/components/metrics/MetricController.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/MetricController.kt @@ -10,6 +10,7 @@ import mozilla.components.browser.awesomebar.facts.BrowserAwesomeBarFacts import mozilla.components.browser.menu.facts.BrowserMenuFacts import mozilla.components.browser.toolbar.facts.ToolbarFacts import mozilla.components.concept.awesomebar.AwesomeBar +import mozilla.components.feature.awesomebar.facts.AwesomeBarFacts import mozilla.components.feature.awesomebar.provider.BookmarksStorageSuggestionProvider import mozilla.components.feature.awesomebar.provider.ClipboardSuggestionProvider import mozilla.components.feature.awesomebar.provider.HistoryStorageSuggestionProvider @@ -271,6 +272,24 @@ internal class ReleaseMetricController( Component.FEATURE_SYNCEDTABS to SyncedTabsFacts.Items.SYNCED_TABS_SUGGESTION_CLICKED -> { Event.SyncedTabSuggestionClicked } + Component.FEATURE_AWESOMEBAR to AwesomeBarFacts.Items.BOOKMARK_SUGGESTION_CLICKED -> { + Event.BookmarkSuggestionClicked + } + Component.FEATURE_AWESOMEBAR to AwesomeBarFacts.Items.CLIPBOARD_SUGGESTION_CLICKED -> { + Event.ClipboardSuggestionClicked + } + Component.FEATURE_AWESOMEBAR to AwesomeBarFacts.Items.HISTORY_SUGGESTION_CLICKED -> { + Event.HistorySuggestionClicked + } + Component.FEATURE_AWESOMEBAR to AwesomeBarFacts.Items.SEARCH_ACTION_CLICKED -> { + Event.SearchActionClicked + } + Component.FEATURE_AWESOMEBAR to AwesomeBarFacts.Items.SEARCH_SUGGESTION_CLICKED -> { + Event.SearchSuggestionClicked + } + Component.FEATURE_AWESOMEBAR to AwesomeBarFacts.Items.OPENED_TAB_SUGGESTION_CLICKED -> { + Event.OpenedTabSuggestionClicked + } else -> null } 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 3317d9fcc..63070c470 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 @@ -17,6 +17,7 @@ import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith +import org.mozilla.fenix.GleanMetrics.Awesomebar import org.mozilla.fenix.GleanMetrics.Events import org.mozilla.fenix.GleanMetrics.Metrics import org.mozilla.fenix.GleanMetrics.SearchDefaultEngine @@ -88,9 +89,36 @@ class GleanMetricsServiceTest { } @Test - fun `synced tab events is correctly recorded`() { + fun `synced tab event is correctly recorded`() { assertFalse(SyncedTabs.syncedTabsSuggestionClicked.testHasValue()) gleanService.track(Event.SyncedTabSuggestionClicked) assertTrue(SyncedTabs.syncedTabsSuggestionClicked.testHasValue()) } + + @Test + fun `awesomebar events are correctly recorded`() { + assertFalse(Awesomebar.bookmarkSuggestionClicked.testHasValue()) + gleanService.track(Event.BookmarkSuggestionClicked) + assertTrue(Awesomebar.bookmarkSuggestionClicked.testHasValue()) + + assertFalse(Awesomebar.clipboardSuggestionClicked.testHasValue()) + gleanService.track(Event.ClipboardSuggestionClicked) + assertTrue(Awesomebar.clipboardSuggestionClicked.testHasValue()) + + assertFalse(Awesomebar.historySuggestionClicked.testHasValue()) + gleanService.track(Event.HistorySuggestionClicked) + assertTrue(Awesomebar.historySuggestionClicked.testHasValue()) + + assertFalse(Awesomebar.searchActionClicked.testHasValue()) + gleanService.track(Event.SearchActionClicked) + assertTrue(Awesomebar.searchActionClicked.testHasValue()) + + assertFalse(Awesomebar.searchSuggestionClicked.testHasValue()) + gleanService.track(Event.SearchSuggestionClicked) + assertTrue(Awesomebar.searchSuggestionClicked.testHasValue()) + + assertFalse(Awesomebar.openedTabSuggestionClicked.testHasValue()) + gleanService.track(Event.OpenedTabSuggestionClicked) + assertTrue(Awesomebar.openedTabSuggestionClicked.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 c4630c852..ba1cfacca 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 @@ -241,4 +241,38 @@ class MetricControllerTest { controller.track(Event.SyncedTabSuggestionClicked) verify { marketingService1.track(Event.SyncedTabSuggestionClicked) } } + + @Test + fun `tracking awesomebar events should be sent to enabled service`() { + val controller = ReleaseMetricController( + listOf(marketingService1), + isDataTelemetryEnabled = { true }, + isMarketingDataTelemetryEnabled = { true } + ) + every { marketingService1.shouldTrack(Event.BookmarkSuggestionClicked) } returns true + every { marketingService1.shouldTrack(Event.ClipboardSuggestionClicked) } returns true + every { marketingService1.shouldTrack(Event.HistorySuggestionClicked) } returns true + every { marketingService1.shouldTrack(Event.SearchActionClicked) } returns true + every { marketingService1.shouldTrack(Event.SearchSuggestionClicked) } returns true + every { marketingService1.shouldTrack(Event.OpenedTabSuggestionClicked) } returns true + controller.start(MetricServiceType.Marketing) + + controller.track(Event.BookmarkSuggestionClicked) + verify { marketingService1.track(Event.BookmarkSuggestionClicked) } + + controller.track(Event.ClipboardSuggestionClicked) + verify { marketingService1.track(Event.ClipboardSuggestionClicked) } + + controller.track(Event.HistorySuggestionClicked) + verify { marketingService1.track(Event.HistorySuggestionClicked) } + + controller.track(Event.SearchActionClicked) + verify { marketingService1.track(Event.SearchActionClicked) } + + controller.track(Event.SearchSuggestionClicked) + verify { marketingService1.track(Event.SearchSuggestionClicked) } + + controller.track(Event.OpenedTabSuggestionClicked) + verify { marketingService1.track(Event.OpenedTabSuggestionClicked) } + } } diff --git a/docs/metrics.md b/docs/metrics.md index 9fa8c0844..16799c38e 100644 --- a/docs/metrics.md +++ b/docs/metrics.md @@ -59,6 +59,12 @@ In addition to those built-in metrics, the following metrics are added to the pi | app_theme.dark_theme_selected |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user selected Dark Theme |[mozilla-mobile/fenix#7968](https://github.com/mozilla-mobile/fenix/pull/7968), [mozilla-mobile/fenix#13958](https://github.com/mozilla-mobile/fenix/pull/13958#issuecomment-676857877)|
  • source: The source from where dark theme was selected. The source can be 'SETTINGS' or 'ONBOARDING'
|2021-04-01 |2 | | autoplay.setting_changed |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user changed their autoplay setting to either block_cellular, block_audio, or block_all. |[mozilla-mobile/fenix#13041](https://github.com/mozilla-mobile/fenix/pull/13041#issuecomment-665777411)|
  • autoplay_setting: The new setting for autoplay: block_cellular, block_audio, or block_all.
|2021-08-01 |2 | | autoplay.visited_setting |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user visited the autoplay settings screen |[mozilla-mobile/fenix#13041](https://github.com/mozilla-mobile/fenix/pull/13041#issuecomment-665777411)||2021-08-01 |2 | +| awesomebar.bookmark_suggestion_clicked |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |The bookmark suggestion in awesomebar was clicked. |[mozilla-mobile/fenix#18090](https://github.com/mozilla-mobile/fenix/pull/18090)||2021-08-01 |2 | +| awesomebar.clipboard_suggestion_clicked |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |The clipboard suggestion in awesomebar was clicked. |[mozilla-mobile/fenix#18090](https://github.com/mozilla-mobile/fenix/pull/18090)||2021-08-01 |2 | +| awesomebar.history_suggestion_clicked |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |The history suggestion in awesomebar was clicked. |[mozilla-mobile/fenix#18090](https://github.com/mozilla-mobile/fenix/pull/18090)||2021-08-01 |2 | +| awesomebar.opened_tab_suggestion_clicked |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |The opened tab suggestion in awesomebar was clicked. |[mozilla-mobile/fenix#18090](https://github.com/mozilla-mobile/fenix/pull/18090)||2021-08-01 |2 | +| awesomebar.search_action_clicked |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |The search action in awesomebar was clicked. |[mozilla-mobile/fenix#18090](https://github.com/mozilla-mobile/fenix/pull/18090)||2021-08-01 |2 | +| awesomebar.search_suggestion_clicked |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |The search suggestion in awesomebar was clicked. |[mozilla-mobile/fenix#18090](https://github.com/mozilla-mobile/fenix/pull/18090)||2021-08-01 |2 | | banner_open_in_app.dismissed |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |User tapped 'dismiss' on Open in App banner. |[mozilla-mobile/fenix#17049](https://github.com/mozilla-mobile/fenix/pull/17049)||2021-08-01 |2 | | banner_open_in_app.displayed |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |Open in App banner was shown. |[mozilla-mobile/fenix#17049](https://github.com/mozilla-mobile/fenix/pull/17049)||2021-08-01 |2 | | banner_open_in_app.go_to_settings |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |User tapped 'go to settings' on Open in App banner. |[mozilla-mobile/fenix#17049](https://github.com/mozilla-mobile/fenix/pull/17049)||2021-08-01 |2 |