Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
For #11273: Add tabs tray telemetry (#12036)
Browse files Browse the repository at this point in the history
  • Loading branch information
sblatz committed Jun 26, 2020
1 parent 7287b55 commit 101ecfb
Show file tree
Hide file tree
Showing 6 changed files with 232 additions and 2 deletions.
137 changes: 137 additions & 0 deletions app/metrics.yaml
Expand Up @@ -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
Expand Down
Expand Up @@ -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
Expand Down Expand Up @@ -602,6 +601,43 @@ private val Event.wrapper: EventWrapper<*>?
{ ContextualHintTrackingProtection.outsideTap.record(it) }
)

is Event.TabsTrayOpened -> EventWrapper<NoExtraKeys>(
{ org.mozilla.fenix.GleanMetrics.TabsTray.opened.record(it) }
)
is Event.TabsTrayClosed -> EventWrapper<NoExtraKeys>(
{ org.mozilla.fenix.GleanMetrics.TabsTray.closed.record(it) }
)
is Event.OpenedExistingTab -> EventWrapper<NoExtraKeys>(
{ org.mozilla.fenix.GleanMetrics.TabsTray.openedExistingTab.record(it) }
)
is Event.ClosedExistingTab -> EventWrapper<NoExtraKeys>(
{ org.mozilla.fenix.GleanMetrics.TabsTray.closedExistingTab.record(it) }
)
is Event.TabsTrayPrivateModeTapped -> EventWrapper<NoExtraKeys>(
{ org.mozilla.fenix.GleanMetrics.TabsTray.privateModeTapped.record(it) }
)
is Event.TabsTrayNormalModeTapped -> EventWrapper<NoExtraKeys>(
{ org.mozilla.fenix.GleanMetrics.TabsTray.normalModeTapped.record(it) }
)
is Event.NewTabTapped -> EventWrapper<NoExtraKeys>(
{ org.mozilla.fenix.GleanMetrics.TabsTray.newTabTapped.record(it) }
)
is Event.NewPrivateTabTapped -> EventWrapper<NoExtraKeys>(
{ org.mozilla.fenix.GleanMetrics.TabsTray.newPrivateTabTapped.record(it) }
)
is Event.TabsTrayMenuOpened -> EventWrapper<NoExtraKeys>(
{ org.mozilla.fenix.GleanMetrics.TabsTray.menuOpened.record(it) }
)
is Event.TabsTraySaveToCollectionPressed -> EventWrapper<NoExtraKeys>(
{ org.mozilla.fenix.GleanMetrics.TabsTray.saveToCollection.record(it) }
)
is Event.TabsTrayShareAllTabsPressed -> EventWrapper<NoExtraKeys>(
{ org.mozilla.fenix.GleanMetrics.TabsTray.shareAllTabs.record(it) }
)
is Event.TabsTrayCloseAllTabsPressed -> EventWrapper<NoExtraKeys>(
{ org.mozilla.fenix.GleanMetrics.TabsTray.closeAllTabs.record(it) }
)

// Don't record other events in Glean:
is Event.AddBookmark -> null
is Event.OpenedBookmark -> null
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/org/mozilla/fenix/components/metrics/Metrics.kt
Expand Up @@ -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 }
Expand Down
Expand Up @@ -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
Expand All @@ -54,23 +55,27 @@ 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()
}
}

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)
}
Expand Down Expand Up @@ -134,6 +139,7 @@ class TabTrayDialogFragment : AppCompatDialogFragment() {
)

tabLayout.setOnClickListener {
requireContext().components.analytics.metrics.track(Event.TabsTrayClosed)
dismissAllowingStateLoss()
}

Expand Down
26 changes: 26 additions & 0 deletions app/src/main/java/org/mozilla/fenix/tabtray/TabTrayView.kt
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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()
}
}
Expand Down Expand Up @@ -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 ->
Expand All @@ -167,18 +172,30 @@ class TabTrayView(
view.tab_tray_new_tab.apply {
isVisible = hasAccessibilityEnabled
setOnClickListener {
sendNewTabEvent(isPrivateModeSelected)
interactor.onNewTabTapped(isPrivateModeSelected)
}
}

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
}
Expand All @@ -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*/ }
Expand Down Expand Up @@ -294,20 +317,23 @@ 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 },

SimpleBrowserMenuItem(
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)
},

SimpleBrowserMenuItem(
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)
}
)
Expand Down
12 changes: 12 additions & 0 deletions docs/metrics.md
Expand Up @@ -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)|<ul><li>identifier: The identifier of the tip closed</li></ul>|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)|<ul><li>identifier: The identifier of the tip displayed</li></ul>|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)|<ul><li>identifier: The identifier of the tip the action was taken on</li></ul>|2020-09-01 |
Expand Down

0 comments on commit 101ecfb

Please sign in to comment.