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 31, 2022
1 parent 8652ff5 commit 9cc93dd
Show file tree
Hide file tree
Showing 13 changed files with 171 additions and 132 deletions.
5 changes: 5 additions & 0 deletions app/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4093,8 +4093,10 @@ collections:
extra_keys:
tabs_open:
description: "The number of tabs open in the current session"
type: string
tabs_selected:
description: "The number of tabs added to the collection"
type: string
bugs:
- https://github.com/mozilla-mobile/fenix/issues/969
- https://github.com/mozilla-mobile/fenix/issues/19923
Expand All @@ -4121,8 +4123,10 @@ collections:
extra_keys:
tabs_open:
description: The number of tabs open in the current session
type: string
tabs_selected:
description: The number of tabs added to the collection
type: string
bugs:
- https://github.com/mozilla-mobile/fenix/issues/969
- https://github.com/mozilla-mobile/fenix/issues/19923
Expand Down Expand Up @@ -4236,6 +4240,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,9 +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

interface CollectionCreationController {
Expand Down Expand Up @@ -67,15 +67,13 @@ fun List<Tab>.toTabSessionStateList(store: BrowserStore): List<TabSessionState>
* @param store Store used to hold in-memory collection state.
* @param browserStore The global `BrowserStore` instance.
* @param dismiss Callback to dismiss the collection creation dialog.
* @param metrics Controller that handles telemetry events.
* @param tabCollectionStorage Storage used to save tab collections to disk.
* @param scope Coroutine scope to launch coroutines.
*/
class DefaultCollectionCreationController(
private val store: CollectionCreationStore,
private val browserStore: BrowserStore,
private val dismiss: () -> Unit,
private val metrics: MetricController,
private val tabCollectionStorage: TabCollectionStorage,
private val scope: CoroutineScope
) : CollectionCreationController {
Expand All @@ -93,8 +91,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.toString(),
sessionBundle.size.toString()
)
)
}

Expand All @@ -103,7 +104,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 +136,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.toString(),
sessionBundle.size.toString()
)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class CollectionCreationFragment : DialogFragment() {
collectionCreationStore,
requireComponents.core.store,
::dismiss,
requireComponents.analytics.metrics,
requireComponents.core.tabCollectionStorage,
scope = lifecycleScope
)
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 @@ -10,7 +10,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.Events
import org.mozilla.fenix.GleanMetrics.History
Expand Down Expand Up @@ -100,16 +99,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 @@ -372,27 +361,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 SearchBarTapped(val source: Source) : Event() {
enum class Source { HOME, BROWSER }

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 @@ -339,27 +338,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 @@ -372,27 +350,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
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 @@ -232,7 +234,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 @@ -264,7 +266,7 @@ class DefaultSessionControlController(
}
)

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

override fun handleCollectionOpenTabsTapped(collection: TabCollection) {
Expand All @@ -278,15 +280,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 @@ -303,7 +305,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 @@ -391,7 +393,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 @@ -17,6 +17,7 @@ import mozilla.components.concept.engine.prompt.ShareData
import mozilla.components.service.fxa.manager.FxaAccountManager
import mozilla.telemetry.glean.private.NoExtras
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 @@ -209,16 +210,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.toString(),
tabs.size.toString()
)
)
} else {
Event.CollectionTabsAdded(browserStore.state.normalTabs.size, tabs.size)
Collections.tabsAdded.record(
Collections.TabsAddedExtra(
browserStore.state.normalTabs.size.toString(),
tabs.size.toString()
)
)
}
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 9cc93dd

Please sign in to comment.