Skip to content

Commit

Permalink
For mozilla-mobile#24099 - Remove Event.wrapper for Collections telem…
Browse files Browse the repository at this point in the history
…etry
  • Loading branch information
Alexandru2909 committed Mar 17, 2022
1 parent eb8f118 commit c769871
Show file tree
Hide file tree
Showing 12 changed files with 154 additions and 126 deletions.
5 changes: 5 additions & 0 deletions app/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4068,8 +4068,10 @@ collections:
extra_keys:
tabs_open:
description: "The number of tabs open in the current session"
type: quantity
tabs_selected:
description: "The number of tabs added to the collection"
type: quantity
bugs:
- https://github.com/mozilla-mobile/fenix/issues/969
- https://github.com/mozilla-mobile/fenix/issues/19923
Expand All @@ -4096,8 +4098,10 @@ collections:
extra_keys:
tabs_open:
description: The number of tabs open in the current session
type: quantity
tabs_selected:
description: The number of tabs added to the collection
type: quantity
bugs:
- https://github.com/mozilla-mobile/fenix/issues/969
- https://github.com/mozilla-mobile/fenix/issues/19923
Expand Down Expand Up @@ -4211,6 +4215,7 @@ collections:
description: |
A string representing the screen from which the user pressed the save
button. Currently one of: `browserMenu`, `homeMenu` or `home`
type: string
metadata:
tags:
- Collections
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import mozilla.components.browser.state.selector.normalTabs
import mozilla.components.browser.state.state.TabSessionState
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.feature.tab.collections.TabCollection
import mozilla.telemetry.glean.private.NoExtras
import org.mozilla.fenix.GleanMetrics.Collections
import org.mozilla.fenix.components.TabCollectionStorage
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.metrics.MetricController
import org.mozilla.fenix.ext.getDefaultCollectionNumber

Expand Down Expand Up @@ -93,8 +94,11 @@ class DefaultCollectionCreationController(
tabCollectionStorage.createCollection(name, sessionBundle)
}

metrics.track(
Event.CollectionSaved(browserStore.state.normalTabs.size, sessionBundle.size)
Collections.saved.record(
Collections.SavedExtra(
browserStore.state.normalTabs.size,
sessionBundle.size
)
)
}

Expand All @@ -103,7 +107,7 @@ class DefaultCollectionCreationController(
scope.launch {
tabCollectionStorage.renameCollection(collection, name)
}
metrics.track(Event.CollectionRenamed)
Collections.renamed.record(NoExtras())
}

override fun backPressed(fromStep: SaveCollectionStep) {
Expand Down Expand Up @@ -135,8 +139,11 @@ class DefaultCollectionCreationController(
.addTabsToCollection(collection, sessionBundle)
}

metrics.track(
Event.CollectionTabsAdded(browserStore.state.normalTabs.size, sessionBundle.size)
Collections.tabsAdded.record(
Collections.TabsAddedExtra(
browserStore.state.normalTabs.size,
sessionBundle.size
)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ import androidx.transition.TransitionManager
import mozilla.components.feature.tab.collections.TabCollection
import mozilla.components.support.ktx.android.view.hideKeyboard
import mozilla.components.support.ktx.android.view.showKeyboard
import mozilla.telemetry.glean.private.NoExtras
import org.mozilla.fenix.GleanMetrics.Collections
import org.mozilla.fenix.R
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.databinding.ComponentCollectionCreationBinding
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.toShortUrl
Expand Down Expand Up @@ -109,7 +110,7 @@ class CollectionCreationView(
}

private fun updateForSelectTabs(state: CollectionCreationState) {
container.context.components.analytics.metrics.track(Event.CollectionTabSelectOpened)
Collections.tabSelectOpened.record(NoExtras())

binding.tabList.isClickable = true

Expand Down
32 changes: 0 additions & 32 deletions app/src/main/java/org/mozilla/fenix/components/metrics/Event.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import mozilla.components.feature.top.sites.TopSite
import org.mozilla.fenix.GleanMetrics.Addons
import org.mozilla.fenix.GleanMetrics.AppTheme
import org.mozilla.fenix.GleanMetrics.Autoplay
import org.mozilla.fenix.GleanMetrics.Collections
import org.mozilla.fenix.GleanMetrics.ContextMenu
import org.mozilla.fenix.GleanMetrics.ErrorPage
import org.mozilla.fenix.GleanMetrics.Events
Expand Down Expand Up @@ -107,16 +106,6 @@ sealed class Event {
object ReaderModeOpened : Event()
object ReaderModeClosed : Event()
object ReaderModeAppearanceOpened : Event()
object CollectionRenamed : Event()
object CollectionTabRestored : Event()
object CollectionAllTabsRestored : Event()
object CollectionTabRemoved : Event()
object CollectionShared : Event()
object CollectionRemoved : Event()
object CollectionTabSelectOpened : Event()
object CollectionTabLongPressed : Event()
object CollectionAddTabPressed : Event()
object CollectionRenamePressed : Event()
object SearchWidgetNewTabPressed : Event()
object SearchWidgetVoiceSearchPressed : Event()
object TabMediaPlay : Event()
Expand Down Expand Up @@ -464,27 +453,6 @@ sealed class Event {
get() = hashMapOf(Events.appOpenedKeys.source to source.name)
}

data class CollectionSaveButtonPressed(val fromScreen: String) : Event() {
override val extras: Map<Collections.saveButtonKeys, String>?
get() = mapOf(Collections.saveButtonKeys.fromScreen to fromScreen)
}

data class CollectionSaved(val tabsOpenCount: Int, val tabsSelectedCount: Int) : Event() {
override val extras: Map<Collections.savedKeys, String>?
get() = mapOf(
Collections.savedKeys.tabsOpen to tabsOpenCount.toString(),
Collections.savedKeys.tabsSelected to tabsSelectedCount.toString()
)
}

data class CollectionTabsAdded(val tabsOpenCount: Int, val tabsSelectedCount: Int) : Event() {
override val extras: Map<Collections.tabsAddedKeys, String>?
get() = mapOf(
Collections.tabsAddedKeys.tabsOpen to tabsOpenCount.toString(),
Collections.tabsAddedKeys.tabsSelected to tabsSelectedCount.toString()
)
}

data class ErrorPageVisited(val errorType: ErrorType) : Event() {
override val extras: Map<ErrorPage.visitedErrorKeys, String>?
get() = mapOf(ErrorPage.visitedErrorKeys.errorType to errorType.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import org.mozilla.fenix.GleanMetrics.Autoplay
import org.mozilla.fenix.GleanMetrics.Awesomebar
import org.mozilla.fenix.GleanMetrics.BookmarksManagement
import org.mozilla.fenix.GleanMetrics.BrowserSearch
import org.mozilla.fenix.GleanMetrics.Collections
import org.mozilla.fenix.GleanMetrics.ContextMenu
import org.mozilla.fenix.GleanMetrics.ContextualMenu
import org.mozilla.fenix.GleanMetrics.CreditCards
Expand Down Expand Up @@ -366,27 +365,6 @@ private val Event.wrapper: EventWrapper<*>?
is Event.RecentlyClosedTabsExitMultiselect -> EventWrapper<NoExtraKeys>(
{ RecentlyClosedTabs.exitMultiselect.record(it) }
)
is Event.CollectionRenamed -> EventWrapper<NoExtraKeys>(
{ Collections.renamed.record(it) }
)
is Event.CollectionTabRestored -> EventWrapper<NoExtraKeys>(
{ Collections.tabRestored.record(it) }
)
is Event.CollectionAllTabsRestored -> EventWrapper<NoExtraKeys>(
{ Collections.allTabsRestored.record(it) }
)
is Event.CollectionTabRemoved -> EventWrapper<NoExtraKeys>(
{ Collections.tabRemoved.record(it) }
)
is Event.CollectionShared -> EventWrapper<NoExtraKeys>(
{ Collections.shared.record(it) }
)
is Event.CollectionRemoved -> EventWrapper<NoExtraKeys>(
{ Collections.removed.record(it) }
)
is Event.CollectionTabSelectOpened -> EventWrapper<NoExtraKeys>(
{ Collections.tabSelectOpened.record(it) }
)
is Event.ReaderModeAvailable -> EventWrapper<NoExtraKeys>(
{ ReaderMode.available.record(it) }
)
Expand All @@ -399,27 +377,6 @@ private val Event.wrapper: EventWrapper<*>?
is Event.ReaderModeAppearanceOpened -> EventWrapper<NoExtraKeys>(
{ ReaderMode.appearance.record(it) }
)
is Event.CollectionTabLongPressed -> EventWrapper<NoExtraKeys>(
{ Collections.longPress.record(it) }
)
is Event.CollectionSaveButtonPressed -> EventWrapper(
{ Collections.saveButton.record(it) },
{ Collections.saveButtonKeys.valueOf(it) }
)
is Event.CollectionAddTabPressed -> EventWrapper<NoExtraKeys>(
{ Collections.addTabButton.record(it) }
)
is Event.CollectionRenamePressed -> EventWrapper<NoExtraKeys>(
{ Collections.renameButton.record(it) }
)
is Event.CollectionSaved -> EventWrapper(
{ Collections.saved.record(it) },
{ Collections.savedKeys.valueOf(it) }
)
is Event.CollectionTabsAdded -> EventWrapper(
{ Collections.tabsAdded.record(it) },
{ Collections.tabsAddedKeys.valueOf(it) }
)
is Event.SearchWidgetNewTabPressed -> EventWrapper<NoExtraKeys>(
{ SearchWidget.newTabButton.record(it) }
)
Expand Down Expand Up @@ -975,7 +932,7 @@ private val Event.wrapper: EventWrapper<*>?
{ RecentlyVisitedHomepage.searchGroupOpened.record() }
)

// Don't record other events in Glean:
// Don't record these events in Glean:
is Event.AddBookmark -> null
is Event.OpenedAppFirstRun -> null
is Event.InteractWithSearchURLArea -> null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import mozilla.components.feature.top.sites.DefaultTopSitesStorage
import mozilla.components.feature.top.sites.PinnedSiteStorage
import mozilla.components.feature.top.sites.TopSite
import mozilla.components.support.base.feature.ViewBoundFeatureWrapper
import org.mozilla.fenix.GleanMetrics.Collections
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.NavGraphDirections
import org.mozilla.fenix.R
Expand Down Expand Up @@ -307,8 +308,11 @@ class DefaultBrowserToolbarMenuController(
)
}
is ToolbarMenu.Item.SaveToCollection -> {
metrics
.track(Event.CollectionSaveButtonPressed(TELEMETRY_BROWSER_IDENTIFIER))
Collections.saveButton.record(
Collections.SaveButtonExtra(
TELEMETRY_BROWSER_IDENTIFIER
)
)

currentSession?.let { currentSession ->
val directions =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ import mozilla.components.feature.tabs.TabsUseCases
import mozilla.components.feature.top.sites.TopSite
import mozilla.components.support.ktx.android.view.showKeyboard
import mozilla.components.support.ktx.kotlin.isUrl
import mozilla.telemetry.glean.private.NoExtras
import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.FeatureFlags
import org.mozilla.fenix.GleanMetrics.Collections
import org.mozilla.fenix.GleanMetrics.Pings
import org.mozilla.fenix.GleanMetrics.TopSites
import org.mozilla.fenix.HomeActivity
Expand Down Expand Up @@ -225,7 +227,7 @@ class DefaultSessionControlController(
) : SessionControlController {

override fun handleCollectionAddTabTapped(collection: TabCollection) {
metrics.track(Event.CollectionAddTabPressed)
Collections.addTabButton.record(NoExtras())
showCollectionCreationFragment(
step = SaveCollectionStep.SelectTabs,
selectedTabCollectionId = collection.id
Expand Down Expand Up @@ -257,7 +259,7 @@ class DefaultSessionControlController(
}
)

metrics.track(Event.CollectionTabRestored)
Collections.tabRestored.record(NoExtras())
}

override fun handleCollectionOpenTabsTapped(collection: TabCollection) {
Expand All @@ -271,15 +273,15 @@ class DefaultSessionControlController(
)

showTabTray()
metrics.track(Event.CollectionAllTabsRestored)
Collections.allTabsRestored.record(NoExtras())
}

override fun handleCollectionRemoveTab(
collection: TabCollection,
tab: ComponentTab,
wasSwiped: Boolean
) {
metrics.track(Event.CollectionTabRemoved)
Collections.tabRemoved.record(NoExtras())

if (collection.tabs.size == 1) {
removeCollectionWithUndo(collection)
Expand All @@ -296,7 +298,7 @@ class DefaultSessionControlController(
collection.title,
collection.tabs.map { ShareData(url = it.url, title = it.title) }
)
metrics.track(Event.CollectionShared)
Collections.shared.record(NoExtras())
}

override fun handleDeleteCollectionTapped(collection: TabCollection) {
Expand Down Expand Up @@ -384,7 +386,7 @@ class DefaultSessionControlController(
step = SaveCollectionStep.RenameCollection,
selectedTabCollectionId = collection.id
)
metrics.track(Event.CollectionRenamePressed)
Collections.renameButton.record(NoExtras())
}

override fun handleSelectTopSite(topSite: TopSite, position: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import mozilla.components.browser.storage.sync.Tab as SyncTab
import mozilla.components.concept.engine.prompt.ShareData
import mozilla.components.service.fxa.manager.FxaAccountManager
import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.GleanMetrics.Collections
import org.mozilla.fenix.GleanMetrics.TabsTray
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.collections.CollectionsDialog
Expand Down Expand Up @@ -208,16 +209,24 @@ class DefaultNavigationInteractor(
onPositiveButtonClick = { id, isNewCollection ->

// If collection is null, a new one was created.
val event = if (isNewCollection) {
Event.CollectionSaved(browserStore.state.normalTabs.size, tabs.size)
if (isNewCollection) {
Collections.saved.record(
Collections.SavedExtra(
browserStore.state.normalTabs.size,
tabs.size
)
)
} else {
Event.CollectionTabsAdded(browserStore.state.normalTabs.size, tabs.size)
Collections.tabsAdded.record(
Collections.TabsAddedExtra(
browserStore.state.normalTabs.size,
tabs.size
)
)
}
id?.apply {
showCollectionSnackbar(tabs.size, isNewCollection, id)
}

metrics.track(event)
},
onNegativeButtonClick = {}
).show(context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ import mozilla.components.browser.toolbar.MAX_URI_LENGTH
import mozilla.components.concept.base.images.ImageLoadRequest
import mozilla.components.concept.base.images.ImageLoader
import mozilla.components.concept.engine.mediasession.MediaSession
import mozilla.telemetry.glean.private.NoExtras
import org.mozilla.fenix.FeatureFlags
import org.mozilla.fenix.GleanMetrics.Collections
import org.mozilla.fenix.R
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.metrics.MetricController
Expand Down Expand Up @@ -230,7 +232,7 @@ abstract class AbstractBrowserTabViewHolder(

itemView.setOnLongClickListener {
if (holder.selectedItems.isEmpty()) {
metrics.track(Event.CollectionTabLongPressed)
Collections.longPress.record(NoExtras())
interactor.select(item)
true
} else {
Expand Down
Loading

0 comments on commit c769871

Please sign in to comment.