From b889b0336b4527be4e7c98d4430c563029191675 Mon Sep 17 00:00:00 2001 From: Sawyer Blatz Date: Mon, 29 Jul 2019 11:54:00 -0700 Subject: [PATCH 1/3] For #969: Adds more telemetry for collections --- app/metrics.yaml | 41 ++++++++++++++++++- .../mozilla/fenix/browser/BrowserFragment.kt | 7 +++- .../collections/CollectionCreationUIView.kt | 2 + .../collections/CreateCollectionFragment.kt | 2 + .../components/metrics/GleanMetricsService.kt | 10 +++++ .../fenix/components/metrics/Metrics.kt | 7 ++++ .../org/mozilla/fenix/home/HomeFragment.kt | 2 + .../viewholders/SaveTabGroupViewHolder.kt | 6 +++ .../viewholders/TabViewHolder.kt | 2 + 9 files changed, 77 insertions(+), 2 deletions(-) diff --git a/app/metrics.yaml b/app/metrics.yaml index cc51af96bf0d..8fcba59ccfd3 100644 --- a/app/metrics.yaml +++ b/app/metrics.yaml @@ -1051,4 +1051,43 @@ collections: - https://github.com/mozilla-mobile/fenix/pull/3935 notification_emails: - fenix-core@mozilla.com - expires: "2020-03-01" \ No newline at end of file + expires: "2020-03-01" + add_tab_button: + type: event + description: > + A user tapped the "add tab" button in the three dot menu of collections + bugs: + - 969 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/TODO + notification_emails: + - fenix-core@mozilla.com + expires: "2020-03-01" + long_press: + type: event + description: > + A user long pressed on a tab, triggering the collection creation screen + bugs: + - 969 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/TODO + notification_emails: + - fenix-core@mozilla.com + expires: "2020-03-01" + save_button: + type: event + description: > + A user pressed the "save to collection" button on either the home or browser screen, triggering the + collection creation screen to open (tab_select_opened) + bugs: + - 969 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/TODO + notification_emails: + - fenix-core@mozilla.com + expires: "2020-03-01" + extra_keys: + from_screen: + description: > + A string representing the screen from which the user pressed the save button. + Either `browser` or `home` \ No newline at end of file diff --git a/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt b/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt index 8229c558b4a6..d655958b22e0 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt @@ -709,7 +709,11 @@ class BrowserFragment : Fragment(), BackHandler { (activity as HomeActivity).browsingModeManager.mode = BrowsingModeManager.Mode.Normal } - ToolbarMenu.Item.SaveToCollection -> showSaveToCollection() + ToolbarMenu.Item.SaveToCollection -> { + requireComponents.analytics.metrics + .track(Event.CollectionSaveButtonPressed(TELEMETRY_BROWSER_IDENITIFIER)) + showSaveToCollection() + } ToolbarMenu.Item.OpenInFenix -> { // Release the session from this view so that it can immediately be rendered by a different view engineView.release() @@ -913,6 +917,7 @@ class BrowserFragment : Fragment(), BackHandler { } companion object { + private const val TELEMETRY_BROWSER_IDENITIFIER = "browser" private const val SHARED_TRANSITION_MS = 200L private const val TAB_ITEM_TRANSITION_NAME = "tab_item" private const val KEY_CUSTOM_TAB_SESSION_ID = "custom_tab_session_id" diff --git a/app/src/main/java/org/mozilla/fenix/collections/CollectionCreationUIView.kt b/app/src/main/java/org/mozilla/fenix/collections/CollectionCreationUIView.kt index fee2b97fd715..d073ec711b83 100644 --- a/app/src/main/java/org/mozilla/fenix/collections/CollectionCreationUIView.kt +++ b/app/src/main/java/org/mozilla/fenix/collections/CollectionCreationUIView.kt @@ -184,6 +184,7 @@ class CollectionCreationUIView( save_button.setOnClickListener { _ -> if (selectedCollection != null) { + // TODO: Telemetry maybe? actionEmitter.onNext( CollectionCreationAction.SelectCollection( selectedCollection!!, @@ -191,6 +192,7 @@ class CollectionCreationUIView( ) ) } else { + // TODO: Telemetry maybe? actionEmitter.onNext(CollectionCreationAction.SaveTabsToCollection(selectedTabs.toList())) } } diff --git a/app/src/main/java/org/mozilla/fenix/collections/CreateCollectionFragment.kt b/app/src/main/java/org/mozilla/fenix/collections/CreateCollectionFragment.kt index 7ffff4a1aa97..497efb00455c 100644 --- a/app/src/main/java/org/mozilla/fenix/collections/CreateCollectionFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/collections/CreateCollectionFragment.kt @@ -117,6 +117,7 @@ class CreateCollectionFragment : DialogFragment() { is CollectionCreationAction.BackPressed -> handleBackPress(backPressFrom = it.backPressFrom) is CollectionCreationAction.SaveCollectionName -> { dismiss() + // TODO: Telemetry maybe? context?.let { context -> val sessionBundle = it.tabs.toList().toSessionBundle(context) @@ -134,6 +135,7 @@ class CreateCollectionFragment : DialogFragment() { is CollectionCreationAction.SelectCollection -> { dismiss() context?.let { context -> + // TODO: Telemetry maybe? val sessionBundle = it.tabs.toList().toSessionBundle(context) viewLifecycleOwner.lifecycleScope.launch(Dispatchers.IO) { context.components.core.tabCollectionStorage 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 eea9ac348089..e00e96ee6a42 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 @@ -265,6 +265,16 @@ private val Event.wrapper is Event.CollectionTabSelectOpened -> EventWrapper( { Collections.tabSelectOpened.record(it) } ) + is Event.CollectionTabLongPressed -> EventWrapper( + { Collections.longPress.record(it) } + ) + is Event.CollectionSaveButtonPressed -> EventWrapper( + { Collections.saveButton.record(it) }, + { Collections.saveButtonKeys.valueOf(it) } + ) + is Event.CollectionAddTabPressed -> EventWrapper( + { Collections.addTabButton.record(it) } + ) // Don't track other events with Glean else -> 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 71cf6397d002..50ffbbe08485 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 @@ -108,6 +108,8 @@ sealed class Event { object CollectionShared : Event() object CollectionRemoved : Event() object CollectionTabSelectOpened : Event() + object CollectionTabLongPressed : Event() + object CollectionAddTabPressed : Event() data class PreferenceToggled(val preferenceKey: String, val enabled: Boolean, val context: Context) : Event() { private val switchPreferenceTelemetryAllowList = listOf( @@ -131,6 +133,11 @@ sealed class Event { } // Interaction Events + data class CollectionSaveButtonPressed(val fromScreen: String) : Event() { + override val extras: Map? + get() = mapOf("from_screen" to fromScreen) + } + data class CollectionSaved(val tabsOpenCount: Int, val tabsSelectedCount: Int) : Event() { override val extras: Map? get() = mapOf( diff --git a/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt b/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt index b680c7c71bc7..f1667482cd0e 100644 --- a/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt @@ -488,6 +488,7 @@ class HomeFragment : Fragment(), AccountObserver { createDeleteCollectionPrompt(action.collection) } is CollectionAction.AddTab -> { + requireComponents.analytics.metrics.track(Event.CollectionAddTabPressed) showCollectionCreationFragment( selectedTabCollection = action.collection, step = SaveCollectionStep.SelectTabs @@ -876,6 +877,7 @@ class HomeFragment : Fragment(), AccountObserver { private const val FADE_ANIM_DURATION = 150L private const val ANIM_SNACKBAR_DELAY = 100L private const val ACCESSIBILITY_FOCUS_DELAY = 2000L + private const val TELEMETRY_HOME_IDENITIFIER = "home" private const val SHARED_TRANSITION_MS = 200L private const val TAB_ITEM_TRANSITION_NAME = "tab_item" private const val toolbarPaddingDp = 12f diff --git a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/SaveTabGroupViewHolder.kt b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/SaveTabGroupViewHolder.kt index d96036ad9c22..519642a706b1 100644 --- a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/SaveTabGroupViewHolder.kt +++ b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/SaveTabGroupViewHolder.kt @@ -9,6 +9,8 @@ import androidx.recyclerview.widget.RecyclerView import io.reactivex.Observer import kotlinx.android.synthetic.main.save_tab_group_button.view.* import org.mozilla.fenix.R +import org.mozilla.fenix.components.metrics.Event +import org.mozilla.fenix.ext.components import org.mozilla.fenix.home.sessioncontrol.SessionControlAction import org.mozilla.fenix.home.sessioncontrol.TabAction import org.mozilla.fenix.home.sessioncontrol.onNext @@ -20,11 +22,15 @@ class SaveTabGroupViewHolder( init { view.save_tab_group_button.setOnClickListener { + view.context.components.analytics.metrics + .track(Event.CollectionSaveButtonPressed(TELEMETRY_HOME_IDENITIFIER)) + actionEmitter.onNext(TabAction.SaveTabGroup(selectedTabSessionId = null)) } } companion object { + const val TELEMETRY_HOME_IDENITIFIER = "home" const val LAYOUT_ID = R.layout.save_tab_group_button } } diff --git a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/TabViewHolder.kt b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/TabViewHolder.kt index d6b37ad38c0b..ed6f49ea779b 100644 --- a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/TabViewHolder.kt +++ b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/TabViewHolder.kt @@ -21,6 +21,7 @@ import mozilla.components.browser.menu.BrowserMenuBuilder import mozilla.components.browser.menu.item.SimpleBrowserMenuItem import mozilla.components.support.ktx.android.util.dpToFloat import org.mozilla.fenix.R +import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.increaseTapArea import org.mozilla.fenix.home.sessioncontrol.SessionControlAction @@ -57,6 +58,7 @@ class TabViewHolder( } item_tab.setOnLongClickListener { + view.context.components.analytics.metrics.track(Event.CollectionTabLongPressed) actionEmitter.onNext(TabAction.SaveTabGroup(tab?.sessionId!!)) true } From 2476ae896038045796f2c507cc873c842aa472ae Mon Sep 17 00:00:00 2001 From: Sawyer Blatz Date: Mon, 29 Jul 2019 12:26:22 -0700 Subject: [PATCH 2/3] Remove unecessary telemetry stubs --- .../org/mozilla/fenix/collections/CollectionCreationUIView.kt | 2 -- .../org/mozilla/fenix/collections/CreateCollectionFragment.kt | 2 -- 2 files changed, 4 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/collections/CollectionCreationUIView.kt b/app/src/main/java/org/mozilla/fenix/collections/CollectionCreationUIView.kt index d073ec711b83..fee2b97fd715 100644 --- a/app/src/main/java/org/mozilla/fenix/collections/CollectionCreationUIView.kt +++ b/app/src/main/java/org/mozilla/fenix/collections/CollectionCreationUIView.kt @@ -184,7 +184,6 @@ class CollectionCreationUIView( save_button.setOnClickListener { _ -> if (selectedCollection != null) { - // TODO: Telemetry maybe? actionEmitter.onNext( CollectionCreationAction.SelectCollection( selectedCollection!!, @@ -192,7 +191,6 @@ class CollectionCreationUIView( ) ) } else { - // TODO: Telemetry maybe? actionEmitter.onNext(CollectionCreationAction.SaveTabsToCollection(selectedTabs.toList())) } } diff --git a/app/src/main/java/org/mozilla/fenix/collections/CreateCollectionFragment.kt b/app/src/main/java/org/mozilla/fenix/collections/CreateCollectionFragment.kt index 497efb00455c..7ffff4a1aa97 100644 --- a/app/src/main/java/org/mozilla/fenix/collections/CreateCollectionFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/collections/CreateCollectionFragment.kt @@ -117,7 +117,6 @@ class CreateCollectionFragment : DialogFragment() { is CollectionCreationAction.BackPressed -> handleBackPress(backPressFrom = it.backPressFrom) is CollectionCreationAction.SaveCollectionName -> { dismiss() - // TODO: Telemetry maybe? context?.let { context -> val sessionBundle = it.tabs.toList().toSessionBundle(context) @@ -135,7 +134,6 @@ class CreateCollectionFragment : DialogFragment() { is CollectionCreationAction.SelectCollection -> { dismiss() context?.let { context -> - // TODO: Telemetry maybe? val sessionBundle = it.tabs.toList().toSessionBundle(context) viewLifecycleOwner.lifecycleScope.launch(Dispatchers.IO) { context.components.core.tabCollectionStorage From 7b924ff560c20bfb2c8da94aa0727fcec0f2b1dd Mon Sep 17 00:00:00 2001 From: Sawyer Blatz Date: Mon, 29 Jul 2019 12:32:57 -0700 Subject: [PATCH 3/3] Adds PR and metrics.md --- app/metrics.yaml | 6 +++--- docs/metrics.md | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/app/metrics.yaml b/app/metrics.yaml index 8fcba59ccfd3..7de5f49af79d 100644 --- a/app/metrics.yaml +++ b/app/metrics.yaml @@ -1059,7 +1059,7 @@ collections: bugs: - 969 data_reviews: - - https://github.com/mozilla-mobile/fenix/pull/TODO + - https://github.com/mozilla-mobile/fenix/pull/4358 notification_emails: - fenix-core@mozilla.com expires: "2020-03-01" @@ -1070,7 +1070,7 @@ collections: bugs: - 969 data_reviews: - - https://github.com/mozilla-mobile/fenix/pull/TODO + - https://github.com/mozilla-mobile/fenix/pull/4358 notification_emails: - fenix-core@mozilla.com expires: "2020-03-01" @@ -1082,7 +1082,7 @@ collections: bugs: - 969 data_reviews: - - https://github.com/mozilla-mobile/fenix/pull/TODO + - https://github.com/mozilla-mobile/fenix/pull/4358 notification_emails: - fenix-core@mozilla.com expires: "2020-03-01" diff --git a/docs/metrics.md b/docs/metrics.md index 221bbef495fe..4d834118614e 100644 --- a/docs/metrics.md +++ b/docs/metrics.md @@ -888,6 +888,32 @@ tabs_selected: The number of tabs added to the collection 2020-03-01 + + add_tab_button + event + A user tapped the "add tab" button in the three dot menu of collections + link + + 2020-03-01 + + + long_press + event + A user long pressed on a tab, triggering the collection creation screen + link + + 2020-03-01 + + + save_button + event + A user pressed the "save to collection" button on either the home or browser screen, triggering the + collection creation screen to open (tab_select_opened) + link + from_screen: A string representing the screen from which the user pressed the save button. Either `browser` or `home` + + 2020-03-01 +