From 262115f8bd4a6b217c7e2d7c9f4b4875adcfd6d7 Mon Sep 17 00:00:00 2001 From: Jonathan Almeida Date: Thu, 10 Jun 2021 19:16:29 -0400 Subject: [PATCH] Issue #19956: Add telemetry for tab view setting changes This differs from `tab_view_setting` which tells us what the user's tab setting is at startup. It does not tell us if the user explicitly changed it instead of just using the default (which was recently changed in #19809). --- app/metrics.yaml | 20 +++++++++++++++++++ .../mozilla/fenix/components/metrics/Event.kt | 7 +++++++ .../components/metrics/GleanMetricsService.kt | 4 ++++ .../fenix/settings/RadioButtonPreference.kt | 3 +++ .../fenix/settings/TabsSettingsFragment.kt | 15 ++++++++++++++ 5 files changed, 49 insertions(+) diff --git a/app/metrics.yaml b/app/metrics.yaml index 7776dfdde835..ec209f30aa86 100644 --- a/app/metrics.yaml +++ b/app/metrics.yaml @@ -433,6 +433,26 @@ events: notification_emails: - fenix-core@mozilla.com expires: "2021-05-10" + tab_view_changed: + type: event + description: | + Indicates that the user has changed their tab view + settings, either from the default or by personal + preference. + extra_keys: + type: + description: | + A string containing the name of the tab view the user tapped. + These items include: list or grid. + bugs: + - https://github.com/mozilla-mobile/fenix/issues/19956 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/19959#issuecomment-859227308 + data_sensitivity: + - interaction + notification_emails: + - fenix-core@mozilla.com + expires: "2022-05-10" onboarding: fxa_auto_signin: diff --git a/app/src/main/java/org/mozilla/fenix/components/metrics/Event.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/Event.kt index aff2f88d8bd8..99558b6258ad 100644 --- a/app/src/main/java/org/mozilla/fenix/components/metrics/Event.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/Event.kt @@ -621,6 +621,13 @@ sealed class Event { get() = mapOf(Autoplay.settingChangedKeys.autoplaySetting to setting.toString().toLowerCase(Locale.ROOT)) } + data class TabViewSettingChanged(val type: Type) : Event() { + enum class Type { LIST, GRID } + + override val extras: Map? + get() = mapOf(Events.tabViewChangedKeys.type to type.toString().toLowerCase(Locale.ROOT)) + } + sealed class Search internal open val extras: Map<*, String>? 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 74f49ccfad4d..d2d4f67d7f76 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 @@ -832,6 +832,10 @@ private val Event.wrapper: EventWrapper<*>? is Event.HomeScreenDisplayed -> EventWrapper( { HomeScreen.homeScreenDisplayed.record(it) } ) + is Event.TabViewSettingChanged -> EventWrapper( + { Events.tabViewChanged.record(it) }, + { Events.tabViewChangedKeys.valueOf(it) } + ) // Don't record other events in Glean: is Event.AddBookmark -> null diff --git a/app/src/main/java/org/mozilla/fenix/settings/RadioButtonPreference.kt b/app/src/main/java/org/mozilla/fenix/settings/RadioButtonPreference.kt index b99be769ac20..4451a90e9e3f 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/RadioButtonPreference.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/RadioButtonPreference.kt @@ -32,6 +32,9 @@ open class RadioButtonPreference @JvmOverloads constructor( private var defaultValue: Boolean = false private var clickListener: (() -> Unit)? = null + val isChecked: Boolean + get() = radioButton?.isChecked == true + init { layoutResource = R.layout.preference_widget_radiobutton diff --git a/app/src/main/java/org/mozilla/fenix/settings/TabsSettingsFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/TabsSettingsFragment.kt index 982b67e22254..cd81a01bd831 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/TabsSettingsFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/TabsSettingsFragment.kt @@ -9,6 +9,8 @@ import android.view.View import androidx.preference.PreferenceFragmentCompat import org.mozilla.fenix.R import org.mozilla.fenix.components.metrics.Event +import org.mozilla.fenix.components.metrics.Event.TabViewSettingChanged +import org.mozilla.fenix.components.metrics.Event.TabViewSettingChanged.Type import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.showToolbar import org.mozilla.fenix.utils.view.addToRadioGroup @@ -60,6 +62,9 @@ class TabsSettingsFragment : PreferenceFragmentCompat() { startOnHomeRadioAlways = requirePreference(R.string.pref_key_start_on_home_always) startOnHomeRadioNever = requirePreference(R.string.pref_key_start_on_home_never) + listRadioButton.onClickListener(::sendTabViewTelemetry) + gridRadioButton.onClickListener(::sendTabViewTelemetry) + setupRadioGroups() } @@ -82,4 +87,14 @@ class TabsSettingsFragment : PreferenceFragmentCompat() { startOnHomeRadioNever ) } + + private fun sendTabViewTelemetry() { + val metrics = requireContext().components.analytics.metrics + + if (listRadioButton.isChecked && !gridRadioButton.isChecked) { + metrics.track(TabViewSettingChanged(Type.LIST)) + } else { + metrics.track(TabViewSettingChanged(Type.GRID)) + } + } }