From 101ecfbf66681ce50ab53cd3ef21d00a73c4d9f0 Mon Sep 17 00:00:00 2001 From: Sawyer Blatz Date: Fri, 26 Jun 2020 16:37:07 -0700 Subject: [PATCH] For #11273: Add tabs tray telemetry (#12036) --- app/metrics.yaml | 137 ++++++++++++++++++ .../components/metrics/GleanMetricsService.kt | 40 ++++- .../fenix/components/metrics/Metrics.kt | 13 ++ .../fenix/tabtray/TabTrayDialogFragment.kt | 6 + .../org/mozilla/fenix/tabtray/TabTrayView.kt | 26 ++++ docs/metrics.md | 12 ++ 6 files changed, 232 insertions(+), 2 deletions(-) diff --git a/app/metrics.yaml b/app/metrics.yaml index 952ab58c3..ebf33eb58 100644 --- a/app/metrics.yaml +++ b/app/metrics.yaml @@ -1608,6 +1608,143 @@ reader_mode: - fenix-core@mozilla.com expires: "2020-09-01" +tabs_tray: + opened: + type: event + description: | + A user opened the tabs tray + bugs: + - https://github.com/mozilla-mobile/fenix/issues/11273 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/12036 + notification_emails: + - fenix-core@mozilla.com + expires: "2020-09-01" + closed: + type: event + description: | + A user closed the tabs tray + bugs: + - https://github.com/mozilla-mobile/fenix/issues/11273 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/12036 + notification_emails: + - fenix-core@mozilla.com + expires: "2020-09-01" + opened_existing_tab: + type: event + description: | + A user opened an existing tab + bugs: + - https://github.com/mozilla-mobile/fenix/issues/11273 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/12036 + notification_emails: + - fenix-core@mozilla.com + expires: "2020-09-01" + closed_existing_tab: + type: event + description: | + A user closed an existing tab + bugs: + - https://github.com/mozilla-mobile/fenix/issues/11273 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/12036 + notification_emails: + - fenix-core@mozilla.com + expires: "2020-09-01" + private_mode_tapped: + type: event + description: | + A user switched to private mode + bugs: + - https://github.com/mozilla-mobile/fenix/issues/11273 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/12036 + notification_emails: + - fenix-core@mozilla.com + expires: "2020-09-01" + normal_mode_tapped: + type: event + description: | + A user switched to normal mode + bugs: + - https://github.com/mozilla-mobile/fenix/issues/11273 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/12036 + notification_emails: + - fenix-core@mozilla.com + expires: "2020-09-01" + new_tab_tapped: + type: event + description: | + A user opened a new tab + bugs: + - https://github.com/mozilla-mobile/fenix/issues/11273 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/12036 + notification_emails: + - fenix-core@mozilla.com + expires: "2020-09-01" + new_private_tab_tapped: + type: event + description: | + A user opened a new private tab + bugs: + - https://github.com/mozilla-mobile/fenix/issues/11273 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/12036 + notification_emails: + - fenix-core@mozilla.com + expires: "2020-09-01" + menu_opened: + type: event + description: | + A user opened three three dot menu in the tabs tray + bugs: + - https://github.com/mozilla-mobile/fenix/issues/11273 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/12036 + notification_emails: + - fenix-core@mozilla.com + expires: "2020-09-01" + save_to_collection: + type: event + description: | + A user tapped the save to collection button in the + three dot menu within the tabs tray + bugs: + - https://github.com/mozilla-mobile/fenix/issues/11273 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/12036 + notification_emails: + - fenix-core@mozilla.com + expires: "2020-09-01" + share_all_tabs: + type: event + description: | + A user tapped the share all tabs button in the + three dot menu within the tabs tray + bugs: + - https://github.com/mozilla-mobile/fenix/issues/11273 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/12036 + notification_emails: + - fenix-core@mozilla.com + expires: "2020-09-01" + close_all_tabs: + type: event + description: | + A user tapped the close all tabs button in the + three dot menu within the tabs tray + bugs: + - https://github.com/mozilla-mobile/fenix/issues/11273 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/12036 + notification_emails: + - fenix-core@mozilla.com + expires: "2020-09-01" + collections: renamed: type: 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 882e63fd3..e6627603b 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 @@ -22,16 +22,15 @@ import org.mozilla.fenix.GleanMetrics.CustomTab import org.mozilla.fenix.GleanMetrics.DownloadNotification import org.mozilla.fenix.GleanMetrics.ErrorPage import org.mozilla.fenix.GleanMetrics.Events -import org.mozilla.fenix.GleanMetrics.Events.preferenceToggled import org.mozilla.fenix.GleanMetrics.FindInPage import org.mozilla.fenix.GleanMetrics.History import org.mozilla.fenix.GleanMetrics.Logins import org.mozilla.fenix.GleanMetrics.MediaNotification import org.mozilla.fenix.GleanMetrics.MediaState import org.mozilla.fenix.GleanMetrics.Metrics +import org.mozilla.fenix.GleanMetrics.Onboarding import org.mozilla.fenix.GleanMetrics.Pings import org.mozilla.fenix.GleanMetrics.Pocket -import org.mozilla.fenix.GleanMetrics.Onboarding import org.mozilla.fenix.GleanMetrics.Preferences import org.mozilla.fenix.GleanMetrics.PrivateBrowsingMode import org.mozilla.fenix.GleanMetrics.PrivateBrowsingShortcut @@ -602,6 +601,43 @@ private val Event.wrapper: EventWrapper<*>? { ContextualHintTrackingProtection.outsideTap.record(it) } ) + is Event.TabsTrayOpened -> EventWrapper( + { org.mozilla.fenix.GleanMetrics.TabsTray.opened.record(it) } + ) + is Event.TabsTrayClosed -> EventWrapper( + { org.mozilla.fenix.GleanMetrics.TabsTray.closed.record(it) } + ) + is Event.OpenedExistingTab -> EventWrapper( + { org.mozilla.fenix.GleanMetrics.TabsTray.openedExistingTab.record(it) } + ) + is Event.ClosedExistingTab -> EventWrapper( + { org.mozilla.fenix.GleanMetrics.TabsTray.closedExistingTab.record(it) } + ) + is Event.TabsTrayPrivateModeTapped -> EventWrapper( + { org.mozilla.fenix.GleanMetrics.TabsTray.privateModeTapped.record(it) } + ) + is Event.TabsTrayNormalModeTapped -> EventWrapper( + { org.mozilla.fenix.GleanMetrics.TabsTray.normalModeTapped.record(it) } + ) + is Event.NewTabTapped -> EventWrapper( + { org.mozilla.fenix.GleanMetrics.TabsTray.newTabTapped.record(it) } + ) + is Event.NewPrivateTabTapped -> EventWrapper( + { org.mozilla.fenix.GleanMetrics.TabsTray.newPrivateTabTapped.record(it) } + ) + is Event.TabsTrayMenuOpened -> EventWrapper( + { org.mozilla.fenix.GleanMetrics.TabsTray.menuOpened.record(it) } + ) + is Event.TabsTraySaveToCollectionPressed -> EventWrapper( + { org.mozilla.fenix.GleanMetrics.TabsTray.saveToCollection.record(it) } + ) + is Event.TabsTrayShareAllTabsPressed -> EventWrapper( + { org.mozilla.fenix.GleanMetrics.TabsTray.shareAllTabs.record(it) } + ) + is Event.TabsTrayCloseAllTabsPressed -> EventWrapper( + { org.mozilla.fenix.GleanMetrics.TabsTray.closeAllTabs.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/Metrics.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/Metrics.kt index 46b1ea9e1..50da78067 100644 --- a/app/src/main/java/org/mozilla/fenix/components/metrics/Metrics.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/Metrics.kt @@ -185,6 +185,19 @@ sealed class Event { object ContextualHintETPOutsideTap : Event() object ContextualHintETPInsideTap : Event() + object TabsTrayOpened : Event() + object TabsTrayClosed : Event() + object OpenedExistingTab : Event() + object ClosedExistingTab : Event() + object TabsTrayPrivateModeTapped : Event() + object TabsTrayNormalModeTapped : Event() + object NewTabTapped : Event() + object NewPrivateTabTapped : Event() + object TabsTrayMenuOpened : Event() + object TabsTraySaveToCollectionPressed : Event() + object TabsTrayShareAllTabsPressed : Event() + object TabsTrayCloseAllTabsPressed : Event() + // Interaction events with extras data class OnboardingToolbarPosition(val position: Position) : Event() { enum class Position { TOP, BOTTOM } diff --git a/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayDialogFragment.kt b/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayDialogFragment.kt index 21f416e1e..1416b247b 100644 --- a/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayDialogFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayDialogFragment.kt @@ -31,6 +31,7 @@ import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.R import org.mozilla.fenix.components.FenixSnackbar import org.mozilla.fenix.components.TabCollectionStorage +import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.requireComponents import org.mozilla.fenix.utils.allowUndo @@ -54,11 +55,13 @@ class TabTrayDialogFragment : AppCompatDialogFragment() { private val selectTabUseCase = object : TabsUseCases.SelectTabUseCase { override fun invoke(tabId: String) { + requireContext().components.analytics.metrics.track(Event.OpenedExistingTab) requireComponents.useCases.tabsUseCases.selectTab(tabId) navigateToBrowser() } override fun invoke(session: Session) { + requireContext().components.analytics.metrics.track(Event.OpenedExistingTab) requireComponents.useCases.tabsUseCases.selectTab(session) navigateToBrowser() } @@ -66,11 +69,13 @@ class TabTrayDialogFragment : AppCompatDialogFragment() { private val removeTabUseCase = object : TabsUseCases.RemoveTabUseCase { override fun invoke(sessionId: String) { + requireContext().components.analytics.metrics.track(Event.ClosedExistingTab) showUndoSnackbarForTab(sessionId) requireComponents.useCases.tabsUseCases.removeTab(sessionId) } override fun invoke(session: Session) { + requireContext().components.analytics.metrics.track(Event.ClosedExistingTab) showUndoSnackbarForTab(session.id) requireComponents.useCases.tabsUseCases.removeTab(session) } @@ -134,6 +139,7 @@ class TabTrayDialogFragment : AppCompatDialogFragment() { ) tabLayout.setOnClickListener { + requireContext().components.analytics.metrics.track(Event.TabsTrayClosed) dismissAllowingStateLoss() } diff --git a/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayView.kt b/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayView.kt index cf7ece6a5..0562f2fba 100644 --- a/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayView.kt +++ b/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayView.kt @@ -30,6 +30,7 @@ import mozilla.components.browser.state.state.BrowserState import mozilla.components.browser.state.state.TabSessionState import mozilla.components.browser.tabstray.BrowserTabsTray import org.mozilla.fenix.R +import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.settings @@ -64,6 +65,8 @@ class TabTrayView( get() = container init { + container.context.components.analytics.metrics.track(Event.TabsTrayOpened) + val hasAccessibilityEnabled = view.context.settings().accessibilityServicesEnabled toggleFabText(isPrivate) @@ -81,6 +84,7 @@ class TabTrayView( override fun onStateChanged(bottomSheet: View, newState: Int) { if (newState == BottomSheetBehavior.STATE_HIDDEN) { + container.context.components.analytics.metrics.track(Event.TabsTrayClosed) interactor.onTabTrayDismissed() } } @@ -154,6 +158,7 @@ class TabTrayView( } view.tab_tray_overflow.setOnClickListener { + container.context.components.analytics.metrics.track(Event.TabsTrayMenuOpened) menu = tabTrayItemMenu.menuBuilder.build(container.context) menu?.show(it) ?.also { pu -> @@ -167,6 +172,7 @@ class TabTrayView( view.tab_tray_new_tab.apply { isVisible = hasAccessibilityEnabled setOnClickListener { + sendNewTabEvent(isPrivateModeSelected) interactor.onNewTabTapped(isPrivateModeSelected) } } @@ -174,11 +180,22 @@ class TabTrayView( fabView.new_tab_button.apply { isVisible = !hasAccessibilityEnabled setOnClickListener { + sendNewTabEvent(isPrivateModeSelected) interactor.onNewTabTapped(isPrivateModeSelected) } } } + private fun sendNewTabEvent(isPrivateModeSelected: Boolean) { + val eventToSend = if (isPrivateModeSelected) { + Event.NewPrivateTabTapped + } else { + Event.NewTabTapped + } + + container.context.components.analytics.metrics.track(eventToSend) + } + fun expand() { behavior.state = BottomSheetBehavior.STATE_EXPANDED } @@ -195,6 +212,12 @@ class TabTrayView( updateState(view.context.components.core.store.state) scrollToSelectedTab() + + if (isPrivateModeSelected) { + container.context.components.analytics.metrics.track(Event.TabsTrayPrivateModeTapped) + } else { + container.context.components.analytics.metrics.track(Event.TabsTrayNormalModeTapped) + } } override fun onTabReselected(tab: TabLayout.Tab?) { /*noop*/ } @@ -294,6 +317,7 @@ class TabTrayItemMenu( context.getString(R.string.tab_tray_menu_item_save), textColorResource = R.color.primary_text_normal_theme ) { + context.components.analytics.metrics.track(Event.TabsTraySaveToCollectionPressed) onItemTapped.invoke(Item.SaveToCollection) }.apply { visible = shouldShowSaveToCollection }, @@ -301,6 +325,7 @@ class TabTrayItemMenu( context.getString(R.string.tab_tray_menu_item_share), textColorResource = R.color.primary_text_normal_theme ) { + context.components.analytics.metrics.track(Event.TabsTrayShareAllTabsPressed) onItemTapped.invoke(Item.ShareAllTabs) }, @@ -308,6 +333,7 @@ class TabTrayItemMenu( context.getString(R.string.tab_tray_menu_item_close), textColorResource = R.color.primary_text_normal_theme ) { + context.components.analytics.metrics.track(Event.TabsTrayCloseAllTabsPressed) onItemTapped.invoke(Item.CloseAllTabs) } ) diff --git a/docs/metrics.md b/docs/metrics.md index 68ebc7c3a..43ae931bc 100644 --- a/docs/metrics.md +++ b/docs/metrics.md @@ -183,6 +183,18 @@ The following metrics are added to the ping: | sync_auth.use_email_problem |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user chose to use their email to sign in after an account problem |[1](https://github.com/mozilla-mobile/fenix/pull/9835#pullrequestreview-398641844)||2020-09-01 | | tab.media_pause |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user pressed the pause icon on a tab from the home screen |[1](https://github.com/mozilla-mobile/fenix/pull/5266)||2020-09-01 | | tab.media_play |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user pressed the play icon on a tab from the home screen |[1](https://github.com/mozilla-mobile/fenix/pull/5266)||2020-09-01 | +| tabs_tray.close_all_tabs |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user tapped the close all tabs button in the three dot menu within the tabs tray |[1](https://github.com/mozilla-mobile/fenix/pull/12036)||2020-09-01 | +| tabs_tray.closed |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user closed the tabs tray |[1](https://github.com/mozilla-mobile/fenix/pull/12036)||2020-09-01 | +| tabs_tray.closed_existing_tab |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user closed an existing tab |[1](https://github.com/mozilla-mobile/fenix/pull/12036)||2020-09-01 | +| tabs_tray.menu_opened |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user opened three three dot menu in the tabs tray |[1](https://github.com/mozilla-mobile/fenix/pull/12036)||2020-09-01 | +| tabs_tray.new_private_tab_tapped |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user opened a new private tab |[1](https://github.com/mozilla-mobile/fenix/pull/12036)||2020-09-01 | +| tabs_tray.new_tab_tapped |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user opened a new tab |[1](https://github.com/mozilla-mobile/fenix/pull/12036)||2020-09-01 | +| tabs_tray.normal_mode_tapped |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user switched to normal mode |[1](https://github.com/mozilla-mobile/fenix/pull/12036)||2020-09-01 | +| tabs_tray.opened |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user opened the tabs tray |[1](https://github.com/mozilla-mobile/fenix/pull/12036)||2020-09-01 | +| tabs_tray.opened_existing_tab |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user opened an existing tab |[1](https://github.com/mozilla-mobile/fenix/pull/12036)||2020-09-01 | +| tabs_tray.private_mode_tapped |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user switched to private mode |[1](https://github.com/mozilla-mobile/fenix/pull/12036)||2020-09-01 | +| tabs_tray.save_to_collection |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user tapped the save to collection button in the three dot menu within the tabs tray |[1](https://github.com/mozilla-mobile/fenix/pull/12036)||2020-09-01 | +| tabs_tray.share_all_tabs |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user tapped the share all tabs button in the three dot menu within the tabs tray |[1](https://github.com/mozilla-mobile/fenix/pull/12036)||2020-09-01 | | tip.closed |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |The tip was closed |[1](https://github.com/mozilla-mobile/fenix/pull/9836)|
  • identifier: The identifier of the tip closed
|2020-09-01 | | tip.displayed |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |The tip was displayed |[1](https://github.com/mozilla-mobile/fenix/pull/9836)|
  • identifier: The identifier of the tip displayed
|2020-09-01 | | tip.pressed |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |The tip's button was pressed |[1](https://github.com/mozilla-mobile/fenix/pull/9836)|
  • identifier: The identifier of the tip the action was taken on
|2020-09-01 |