2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-15 18:12:54 +00:00
* For https://github.com/mozilla-mobile/fenix/issues/975: Adds telemetry for settings toggles

* For https://github.com/mozilla-mobile/fenix/issues/975: Uses failable constructor
This commit is contained in:
Sawyer Blatz 2019-04-26 08:42:20 -07:00 committed by GitHub
parent f91ab0b460
commit fb12b695e1
4 changed files with 60 additions and 0 deletions

View File

@ -38,6 +38,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- #1312 - Added a missing edit action for bookmark selections
- #974 - Added telemetry for bookmarks
- #113 - Added QR code scanner
- #975 - Added telemetry for preference switches
### Changed
- #1429 - Updated site permissions ui for MVP

View File

@ -580,3 +580,23 @@ custom_tab:
notification_emails:
- fenix-core@mozilla.com
expires: "2020-03-01"
preferences:
preference_toggled:
type: event
description: >
A user toggled a preference switch in settings
extra_keys:
preference_key:
description: "The preference key for the switch preference the user toggled. We currently track: leakcanary,
make_default_browser, show_search_suggestions, show_visited_sites_bookmarks, remote_debugging, telemetry,
tracking_protection"
enabled:
description: "Whether or not the preference is *now* enabled"
bugs:
- 975
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/1896
notification_emails:
- fenix-core@mozilla.com
expires: "2020-03-01"

View File

@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.components.metrics
import android.content.Context
import mozilla.components.browser.search.SearchEngine
import mozilla.components.support.base.Component
import mozilla.components.support.base.facts.Fact
@ -10,6 +11,8 @@ import mozilla.components.support.base.facts.FactProcessor
import mozilla.components.support.base.facts.Facts
import mozilla.components.support.base.log.logger.Logger
import org.mozilla.fenix.BuildConfig
import org.mozilla.fenix.R
import java.lang.IllegalArgumentException
sealed class Event {
@ -72,6 +75,29 @@ sealed class Event {
object CustomTabsMenuOpened : Event()
object UriOpened : Event()
data class PreferenceToggled(val preferenceKey: String, val enabled: Boolean, val context: Context) : Event() {
private val switchPreferenceTelemetryAllowList = listOf(
context.getString(R.string.pref_key_leakcanary),
context.getString(R.string.pref_key_make_default_browser),
context.getString(R.string.pref_key_show_search_suggestions),
context.getString(R.string.pref_key_show_visited_sites_bookmarks),
context.getString(R.string.pref_key_remote_debugging),
context.getString(R.string.pref_key_telemetry),
context.getString(R.string.pref_key_tracking_protection)
)
override val extras: Map<String, String>?
get() = mapOf(
"preferenceKey" to preferenceKey,
"enabled" to enabled.toString()
)
init {
// If the event is not in the allow list, we don't want to track it
if (!switchPreferenceTelemetryAllowList.contains(preferenceKey)) { throw IllegalArgumentException() }
}
}
// Interaction Events
data class SearchBarTapped(val source: Source) : Event() {
enum class Source { HOME, BROWSER }

View File

@ -48,6 +48,8 @@ import org.mozilla.fenix.R.string.pref_key_account
import org.mozilla.fenix.R.string.pref_key_account_category
import org.mozilla.fenix.R.string.pref_key_search_engine_settings
import org.mozilla.fenix.R.string.pref_key_tracking_protection_settings
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.utils.ItsNotBrokenSnack
@SuppressWarnings("TooManyFunctions")
@ -60,6 +62,17 @@ class SettingsFragment : PreferenceFragmentCompat(), CoroutineScope, AccountObse
super.onCreate(savedInstanceState)
job = Job()
updateSignInVisibility()
preferenceManager.sharedPreferences.registerOnSharedPreferenceChangeListener { sharedPreferences, key ->
try {
context?.let {
it.components.analytics.metrics.track(Event.PreferenceToggled
(key, sharedPreferences.getBoolean(key, false), it))
}
} catch (e: IllegalArgumentException) {
// The event is not tracked
}
}
}
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {