From c556e819bdedb351405b82e2550a60f8fde3ebdd Mon Sep 17 00:00:00 2001 From: ekager Date: Thu, 16 Jan 2020 09:50:27 -0800 Subject: [PATCH] For #5586 - Add telemetry for save logins setting --- app/metrics.yaml | 16 +++++++- .../components/metrics/GleanMetricsService.kt | 4 ++ .../fenix/components/metrics/Metrics.kt | 8 ++++ .../logins/SaveLoginSettingFragment.kt | 38 +++++++++++++++++-- docs/metrics.md | 3 +- 5 files changed, 63 insertions(+), 6 deletions(-) diff --git a/app/metrics.yaml b/app/metrics.yaml index ad5421f58..2d418d5f6 100644 --- a/app/metrics.yaml +++ b/app/metrics.yaml @@ -114,7 +114,7 @@ events: description: "The preference key for the boolean (true/false) preference the user toggled. We currently track: show_search_suggestions, remote_debugging, telemetry, tracking_protection, search_bookmarks, search_browsing_history, show_clipboard_suggestions, show_search_shortcuts, open_links_in_a_private_tab (bug in implementation https://github.com/mozilla-mobile/fenix/issues/7384), - pref_key_sync_logins, pref_key_sync_bookmarks, pref_key_sync_history + pref_key_sync_logins, pref_key_sync_bookmarks, pref_key_sync_history, and pref_key_show_search_suggestions_in_private" enabled: description: "Whether or not the preference is *now* enabled" @@ -1537,6 +1537,20 @@ logins: notification_emails: - fenix-core@mozilla.com expires: "2020-09-01" + save_logins_setting_changed: + type: event + description: > + A user changed their setting for asking to save logins + extra_keys: + setting: + description: "The new setting for saving logins the user selected. Either `ask_to_save` or `never_save`" + bugs: + - https://github.com/mozilla-mobile/fenix/issues/5586 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/7767 + notification_emails: + - fenix-core@mozilla.com + expires: "2020-09-01" download_notification: resume: 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 0030196b1..5e94fd3f9 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 @@ -452,6 +452,10 @@ private val Event.wrapper: EventWrapper<*>? is Event.CustomEngineDeleted -> EventWrapper( { UserSpecifiedSearchEngines.customEngineDeleted.record(it) } ) + is Event.SaveLoginsSettingChanged -> EventWrapper( + { Logins.saveLoginsSettingChanged.record(it) }, + { Logins.saveLoginsSettingChangedKeys.valueOf(it) } + ) // Don't record other events in Glean: is Event.AddBookmark -> null is Event.OpenedBookmark -> 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 159391602..f0d329afb 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 @@ -26,6 +26,7 @@ import org.mozilla.fenix.GleanMetrics.CrashReporter import org.mozilla.fenix.GleanMetrics.ErrorPage import org.mozilla.fenix.GleanMetrics.Events import org.mozilla.fenix.GleanMetrics.Library +import org.mozilla.fenix.GleanMetrics.Logins import org.mozilla.fenix.GleanMetrics.SearchShortcuts import org.mozilla.fenix.GleanMetrics.ToolbarSettings import org.mozilla.fenix.GleanMetrics.TrackingProtection @@ -189,6 +190,13 @@ sealed class Event { get() = hashMapOf(TrackingProtection.etpSettingChangedKeys.etpSetting to setting.name) } + data class SaveLoginsSettingChanged(val setting: Setting) : Event() { + enum class Setting { NEVER_SAVE, ASK_TO_SAVE } + + override val extras: Map? + get() = hashMapOf(Logins.saveLoginsSettingChangedKeys.setting to setting.name) + } + data class OpenedApp(val source: Source) : Event() { enum class Source { APP_ICON, LINK, CUSTOM_TAB } override val extras: Map? diff --git a/app/src/main/java/org/mozilla/fenix/settings/logins/SaveLoginSettingFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/logins/SaveLoginSettingFragment.kt index 5d2f6c94e..6fb6e29a3 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/logins/SaveLoginSettingFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/logins/SaveLoginSettingFragment.kt @@ -5,10 +5,14 @@ package org.mozilla.fenix.settings.logins import android.os.Bundle +import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import org.mozilla.fenix.R +import org.mozilla.fenix.components.metrics.Event +import org.mozilla.fenix.ext.metrics import org.mozilla.fenix.ext.showToolbar import org.mozilla.fenix.settings.RadioButtonPreference +import org.mozilla.fenix.settings.SharedPreferenceUpdater class SaveLoginSettingFragment : PreferenceFragmentCompat() { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { @@ -24,13 +28,39 @@ class SaveLoginSettingFragment : PreferenceFragmentCompat() { } private fun bindSave(): RadioButtonPreference { - val keyStrict = getString(R.string.pref_key_save_logins) - return requireNotNull(findPreference(keyStrict)) + val keySave = getString(R.string.pref_key_save_logins) + val preferenceSave = findPreference(keySave) + preferenceSave?.onPreferenceChangeListener = object : SharedPreferenceUpdater() { + override fun onPreferenceChange(preference: Preference, newValue: Any?): Boolean { + if (newValue == true) { + context?.metrics?.track( + Event.SaveLoginsSettingChanged( + Event.SaveLoginsSettingChanged.Setting.ASK_TO_SAVE + ) + ) + } + return super.onPreferenceChange(preference, newValue) + } + } + return requireNotNull(preferenceSave) } private fun bindNeverSave(): RadioButtonPreference { - val keyStandard = getString(R.string.pref_key_never_save_logins) - return requireNotNull(findPreference(keyStandard)) + val keyNeverSave = getString(R.string.pref_key_never_save_logins) + val preferenceNeverSave = findPreference(keyNeverSave) + preferenceNeverSave?.onPreferenceChangeListener = object : SharedPreferenceUpdater() { + override fun onPreferenceChange(preference: Preference, newValue: Any?): Boolean { + if (newValue == true) { + context?.metrics?.track( + Event.SaveLoginsSettingChanged( + Event.SaveLoginsSettingChanged.Setting.NEVER_SAVE + ) + ) + } + return super.onPreferenceChange(preference, newValue) + } + } + return requireNotNull(preferenceNeverSave) } private fun setupRadioGroups( diff --git a/docs/metrics.md b/docs/metrics.md index c5e7b13e1..87bf72cc7 100644 --- a/docs/metrics.md +++ b/docs/metrics.md @@ -84,7 +84,7 @@ The following metrics are added to the ping: | events.entered_url |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user entered a url |[1](https://github.com/mozilla-mobile/fenix/pull/1067#issuecomment-474598673)|
  • autocomplete: A boolean that tells us whether the URL was autofilled by an Autocomplete suggestion
|2020-09-01 | | events.opened_link |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user opened a link with Fenix |[1](https://github.com/mozilla-mobile/fenix/pull/5975)|
  • mode: The mode the link was opened in. Either 'PRIVATE' or 'NORMAL'
|2020-09-01 | | events.performed_search |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user performed a search |[1](https://github.com/mozilla-mobile/fenix/pull/1067#issuecomment-474598673), [2](https://github.com/mozilla-mobile/fenix/pull/1677)|
  • source: A string that tells us how the user performed the search. Possible values are: * default.action * default.suggestion * shortcut.action * shortcut.suggestion
|2020-09-01 | -| events.preference_toggled |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user toggled a boolean preference in settings |[1](https://github.com/mozilla-mobile/fenix/pull/1896), [2](https://github.com/mozilla-mobile/fenix/pull/5704), [3](https://github.com/mozilla-mobile/fenix/pull/5886), [4](https://github.com/mozilla-mobile/fenix/pull/5975), [5](https://github.com/mozilla-mobile/fenix/pull/6352), [6](https://github.com/mozilla-mobile/fenix/pull/6601), [7](https://github.com/mozilla-mobile/fenix/pull/6746)|
  • enabled: Whether or not the preference is *now* enabled
  • preference_key: The preference key for the boolean (true/false) preference the user toggled. We currently track: show_search_suggestions, remote_debugging, telemetry, tracking_protection, search_bookmarks, search_browsing_history, show_clipboard_suggestions, show_search_shortcuts, open_links_in_a_private_tab (bug in implementation https://github.com/mozilla-mobile/fenix/issues/7384), pref_key_sync_logins, pref_key_sync_bookmarks, pref_key_sync_history and pref_key_show_search_suggestions_in_private
|2020-09-01 | +| events.preference_toggled |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user toggled a boolean preference in settings |[1](https://github.com/mozilla-mobile/fenix/pull/1896), [2](https://github.com/mozilla-mobile/fenix/pull/5704), [3](https://github.com/mozilla-mobile/fenix/pull/5886), [4](https://github.com/mozilla-mobile/fenix/pull/5975), [5](https://github.com/mozilla-mobile/fenix/pull/6352), [6](https://github.com/mozilla-mobile/fenix/pull/6601), [7](https://github.com/mozilla-mobile/fenix/pull/6746)|
  • enabled: Whether or not the preference is *now* enabled
  • preference_key: The preference key for the boolean (true/false) preference the user toggled. We currently track: show_search_suggestions, remote_debugging, telemetry, tracking_protection, search_bookmarks, search_browsing_history, show_clipboard_suggestions, show_search_shortcuts, open_links_in_a_private_tab (bug in implementation https://github.com/mozilla-mobile/fenix/issues/7384), pref_key_sync_logins, pref_key_sync_bookmarks, pref_key_sync_history, and pref_key_show_search_suggestions_in_private
|2020-09-01 | | events.search_bar_tapped |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user tapped the search bar |[1](https://github.com/mozilla-mobile/fenix/pull/1067#issuecomment-474598673)|
  • source: The view the user was on when they initiated the search (For example: `Home` or `Browser`)
|2020-09-01 | | events.whats_new_tapped |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user opened the "what's new" page button |[1](https://github.com/mozilla-mobile/fenix/pull/5090)||2020-09-01 | | find_in_page.closed |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user closed the find in page UI |[1](https://github.com/mozilla-mobile/fenix/pull/1344#issuecomment-479285010)||2020-09-01 | @@ -101,6 +101,7 @@ The following metrics are added to the ping: | logins.copy_login |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user copied a piece of a login in saved logins |[1](https://github.com/mozilla-mobile/fenix/pull/6352)||2020-09-01 | | logins.open_individual_login |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user accessed an individual login in saved logins |[1](https://github.com/mozilla-mobile/fenix/pull/6352)||2020-09-01 | | logins.open_logins |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user accessed Logins in Settings |[1](https://github.com/mozilla-mobile/fenix/pull/6352)||2020-09-01 | +| logins.save_logins_setting_changed |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user changed their setting for asking to save logins |[1](https://github.com/mozilla-mobile/fenix/pull/7767)|
  • setting: The new setting for saving logins the user selected. Either `ask_to_save` or `never_save`
|2020-09-01 | | logins.view_password_login |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user viewed a password in an individual saved login |[1](https://github.com/mozilla-mobile/fenix/pull/6352)||2020-09-01 | | media_notification.pause |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user pressed the pause icon on the media notification |[1](https://github.com/mozilla-mobile/fenix/pull/5520)||2020-09-01 | | media_notification.play |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user pressed the play icon on the media notification |[1](https://github.com/mozilla-mobile/fenix/pull/5520)||2020-09-01 |