2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-03 23:15:31 +00:00

For #24209 - Remove Event.wrapper for CustomizeHome telemetry

This commit is contained in:
Alexandru2909 2022-03-17 21:16:20 +02:00 committed by mergify[bot]
parent 0e5f75bfe2
commit da723ee2fd
4 changed files with 63 additions and 57 deletions

View File

@ -1574,6 +1574,7 @@ customize_home:
A user toggles the preference for the home screen items. A user toggles the preference for the home screen items.
extra_keys: extra_keys:
preference_key: preference_key:
type: string
description: | description: |
The preference key for the boolean (true/false) preference the user The preference key for the boolean (true/false) preference the user
toggled. toggled.
@ -1581,6 +1582,7 @@ customize_home:
We currently track: most_visited_sites, jump_back_in, We currently track: most_visited_sites, jump_back_in,
recently_visited, recently_saved, pocket, and contile. recently_visited, recently_saved, pocket, and contile.
enabled: enabled:
type: boolean
description: "Whether or not the preference is *now* enabled" description: "Whether or not the preference is *now* enabled"
bugs: bugs:
- https://github.com/mozilla-mobile/fenix/issues/21095 - https://github.com/mozilla-mobile/fenix/issues/21095

View File

@ -313,32 +313,6 @@ sealed class Event {
} }
} }
data class CustomizeHomePreferenceToggled(
val preferenceKey: String,
val enabled: Boolean,
val context: Context
) : Event() {
private val telemetryAllowMap = mapOf(
context.getString(R.string.pref_key_show_top_sites) to "most_visited_sites",
context.getString(R.string.pref_key_recent_tabs) to "jump_back_in",
context.getString(R.string.pref_key_recent_bookmarks) to "recently_saved",
context.getString(R.string.pref_key_history_metadata_feature) to "recently_visited",
context.getString(R.string.pref_key_pocket_homescreen_recommendations) to "pocket",
context.getString(R.string.pref_key_enable_contile) to "contile",
)
override val extras: Map<Events.preferenceToggledKeys, String>
get() = mapOf(
Events.preferenceToggledKeys.preferenceKey to (telemetryAllowMap[preferenceKey] ?: ""),
Events.preferenceToggledKeys.enabled to enabled.toString()
)
init {
// If the event is not in the allow list, we don't want to track it
require(telemetryAllowMap.contains(preferenceKey))
}
}
data class AddonsOpenInToolbarMenu(val addonId: String) : Event() { data class AddonsOpenInToolbarMenu(val addonId: String) : Event() {
override val extras: Map<Addons.openAddonInToolbarMenuKeys, String>? override val extras: Map<Addons.openAddonInToolbarMenuKeys, String>?
get() = hashMapOf(Addons.openAddonInToolbarMenuKeys.addonId to addonId) get() = hashMapOf(Addons.openAddonInToolbarMenuKeys.addonId to addonId)

View File

@ -20,7 +20,6 @@ import org.mozilla.fenix.GleanMetrics.ContextMenu
import org.mozilla.fenix.GleanMetrics.ContextualMenu import org.mozilla.fenix.GleanMetrics.ContextualMenu
import org.mozilla.fenix.GleanMetrics.CreditCards import org.mozilla.fenix.GleanMetrics.CreditCards
import org.mozilla.fenix.GleanMetrics.CustomTab import org.mozilla.fenix.GleanMetrics.CustomTab
import org.mozilla.fenix.GleanMetrics.CustomizeHome
import org.mozilla.fenix.GleanMetrics.Events import org.mozilla.fenix.GleanMetrics.Events
import org.mozilla.fenix.GleanMetrics.ExperimentsDefaultBrowser import org.mozilla.fenix.GleanMetrics.ExperimentsDefaultBrowser
import org.mozilla.fenix.GleanMetrics.History import org.mozilla.fenix.GleanMetrics.History
@ -249,10 +248,6 @@ private val Event.wrapper: EventWrapper<*>?
{ Events.preferenceToggled.record(it) }, { Events.preferenceToggled.record(it) },
{ Events.preferenceToggledKeys.valueOf(it) } { Events.preferenceToggledKeys.valueOf(it) }
) )
is Event.CustomizeHomePreferenceToggled -> EventWrapper(
{ CustomizeHome.preferenceToggled.record(it) },
{ CustomizeHome.preferenceToggledKeys.valueOf(it) }
)
is Event.HistoryOpened -> EventWrapper<NoExtraKeys>( is Event.HistoryOpened -> EventWrapper<NoExtraKeys>(
{ History.opened.record(it) } { History.opened.record(it) }
) )

View File

@ -11,9 +11,8 @@ import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreference import androidx.preference.SwitchPreference
import org.mozilla.fenix.FeatureFlags import org.mozilla.fenix.FeatureFlags
import org.mozilla.fenix.GleanMetrics.CustomizeHome
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.settings import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.ext.showToolbar import org.mozilla.fenix.ext.showToolbar
import org.mozilla.fenix.utils.view.addToRadioGroup import org.mozilla.fenix.utils.view.addToRadioGroup
@ -36,37 +35,91 @@ class HomeSettingsFragment : PreferenceFragmentCompat() {
private fun setupPreferences() { private fun setupPreferences() {
requirePreference<SwitchPreference>(R.string.pref_key_show_top_sites).apply { requirePreference<SwitchPreference>(R.string.pref_key_show_top_sites).apply {
isChecked = context.settings().showTopSitesFeature isChecked = context.settings().showTopSitesFeature
onPreferenceChangeListener = CustomizeHomeMetricsUpdater() onPreferenceChangeListener = object : SharedPreferenceUpdater() {
override fun onPreferenceChange(preference: Preference, newValue: Any?): Boolean {
CustomizeHome.preferenceToggled.record(
CustomizeHome.PreferenceToggledExtra(
newValue as Boolean,
"most_visited_sites"
)
)
return super.onPreferenceChange(preference, newValue)
}
}
} }
requirePreference<CheckBoxPreference>(R.string.pref_key_enable_contile).apply { requirePreference<CheckBoxPreference>(R.string.pref_key_enable_contile).apply {
isVisible = FeatureFlags.contileFeature isVisible = FeatureFlags.contileFeature
isChecked = context.settings().showContileFeature isChecked = context.settings().showContileFeature
onPreferenceChangeListener = CustomizeHomeMetricsUpdater()
} }
requirePreference<SwitchPreference>(R.string.pref_key_recent_tabs).apply { requirePreference<SwitchPreference>(R.string.pref_key_recent_tabs).apply {
isVisible = FeatureFlags.showRecentTabsFeature isVisible = FeatureFlags.showRecentTabsFeature
isChecked = context.settings().showRecentTabsFeature isChecked = context.settings().showRecentTabsFeature
onPreferenceChangeListener = CustomizeHomeMetricsUpdater() onPreferenceChangeListener = object : SharedPreferenceUpdater() {
override fun onPreferenceChange(preference: Preference, newValue: Any?): Boolean {
CustomizeHome.preferenceToggled.record(
CustomizeHome.PreferenceToggledExtra(
newValue as Boolean,
"jump_back_in"
)
)
return super.onPreferenceChange(preference, newValue)
}
}
} }
requirePreference<SwitchPreference>(R.string.pref_key_recent_bookmarks).apply { requirePreference<SwitchPreference>(R.string.pref_key_recent_bookmarks).apply {
isVisible = FeatureFlags.recentBookmarksFeature isVisible = FeatureFlags.recentBookmarksFeature
isChecked = context.settings().showRecentBookmarksFeature isChecked = context.settings().showRecentBookmarksFeature
onPreferenceChangeListener = CustomizeHomeMetricsUpdater() onPreferenceChangeListener = object : SharedPreferenceUpdater() {
override fun onPreferenceChange(preference: Preference, newValue: Any?): Boolean {
CustomizeHome.preferenceToggled.record(
CustomizeHome.PreferenceToggledExtra(
newValue as Boolean,
"recently_saved"
)
)
return super.onPreferenceChange(preference, newValue)
}
}
} }
requirePreference<SwitchPreference>(R.string.pref_key_pocket_homescreen_recommendations).apply { requirePreference<SwitchPreference>(R.string.pref_key_pocket_homescreen_recommendations).apply {
isVisible = FeatureFlags.isPocketRecommendationsFeatureEnabled(context) isVisible = FeatureFlags.isPocketRecommendationsFeatureEnabled(context)
isChecked = context.settings().showPocketRecommendationsFeature isChecked = context.settings().showPocketRecommendationsFeature
onPreferenceChangeListener = CustomizeHomeMetricsUpdater() onPreferenceChangeListener = object : SharedPreferenceUpdater() {
override fun onPreferenceChange(preference: Preference, newValue: Any?): Boolean {
CustomizeHome.preferenceToggled.record(
CustomizeHome.PreferenceToggledExtra(
newValue as Boolean,
"pocket"
)
)
return super.onPreferenceChange(preference, newValue)
}
}
} }
requirePreference<SwitchPreference>(R.string.pref_key_history_metadata_feature).apply { requirePreference<SwitchPreference>(R.string.pref_key_history_metadata_feature).apply {
isVisible = FeatureFlags.historyMetadataUIFeature isVisible = FeatureFlags.historyMetadataUIFeature
isChecked = context.settings().historyMetadataUIFeature isChecked = context.settings().historyMetadataUIFeature
onPreferenceChangeListener = CustomizeHomeMetricsUpdater() onPreferenceChangeListener = object : SharedPreferenceUpdater() {
override fun onPreferenceChange(preference: Preference, newValue: Any?): Boolean {
CustomizeHome.preferenceToggled.record(
CustomizeHome.PreferenceToggledExtra(
newValue as Boolean,
"recently_visited"
)
)
return super.onPreferenceChange(preference, newValue)
}
}
} }
val openingScreenRadioHomepage = val openingScreenRadioHomepage =
@ -92,22 +145,4 @@ class HomeSettingsFragment : PreferenceFragmentCompat() {
openingScreenAfterFourHours openingScreenAfterFourHours
) )
} }
inner class CustomizeHomeMetricsUpdater : SharedPreferenceUpdater() {
override fun onPreferenceChange(preference: Preference, newValue: Any?): Boolean {
try {
val context = preference.context
context.components.analytics.metrics.track(
Event.CustomizeHomePreferenceToggled(
preference.key,
newValue as Boolean,
context
)
)
} catch (e: IllegalArgumentException) {
// The event is not tracked
}
return super.onPreferenceChange(preference, newValue)
}
}
} }