Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
For #5312 - Add Telemetry for Tracking Protection
Browse files Browse the repository at this point in the history
  • Loading branch information
ekager committed Sep 18, 2019
1 parent a68fabd commit 95b675a
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 3 deletions.
71 changes: 71 additions & 0 deletions app/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,77 @@ private_browsing_mode:
- [email protected]
expires: "2020-03-01"

tracking_protection:
exception_added:
type: event
description: >
A user added a TP exception through the TP toggle in the panel.
bugs:
- 5312
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/TBD
notification_emails:
- [email protected]
expires: "2020-03-01"
panel_settings:
type: event
description: >
A user opened ETP settings from the panel.
bugs:
- 5312
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/TBD
notification_emails:
- [email protected]
expires: "2020-03-01"
etp_shield:
type: event
description: >
A user pressed the TP shield icon in toolbar.
bugs:
- 5312
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/TBD
notification_emails:
- [email protected]
expires: "2020-03-01"
etp_tracker_list:
type: event
description: >
A user pressed into tracker list display in panel.
bugs:
- 5312
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/TBD
notification_emails:
- [email protected]
expires: "2020-03-01"
etp_settings:
type: event
description: >
A user opened ETP settings through settings.
bugs:
- 5312
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/TBD
notification_emails:
- [email protected]
expires: "2020-03-01"
etp_setting_changed:
type: event
description: >
A user added a TP exception through the TP toggle in the panel.
extra_keys:
etp_setting:
description: "The new setting for ETP: strict, standard"
bugs:
- 5312
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/TBD
notification_emails:
- [email protected]
expires: "2020-03-01"

private_browsing_shortcut:
create_shortcut:
type: event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import org.mozilla.fenix.collections.CreateCollectionViewModel
import org.mozilla.fenix.components.FenixSnackbar
import org.mozilla.fenix.components.FindInPageIntegration
import org.mozilla.fenix.components.StoreProvider
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.toolbar.BrowserFragmentState
import org.mozilla.fenix.components.toolbar.BrowserFragmentStore
import org.mozilla.fenix.components.toolbar.BrowserToolbarController
Expand All @@ -70,6 +71,7 @@ import org.mozilla.fenix.components.toolbar.ToolbarIntegration
import org.mozilla.fenix.downloads.DownloadService
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.enterToImmersiveMode
import org.mozilla.fenix.ext.metrics
import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.isInExperiment
Expand Down Expand Up @@ -214,6 +216,7 @@ abstract class BaseBrowserFragment : Fragment(), BackHandler, SessionManager.Obs
}

browserToolbarView.view.setOnTrackingProtectionClickedListener {
context.metrics.track(Event.TrackingProtectionIconPressed)
showTrackingProtectionPanel()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import org.mozilla.fenix.GleanMetrics.SearchShortcuts
import org.mozilla.fenix.GleanMetrics.SearchWidget
import org.mozilla.fenix.GleanMetrics.SyncAccount
import org.mozilla.fenix.GleanMetrics.SyncAuth
import org.mozilla.fenix.GleanMetrics.TrackingProtection
import org.mozilla.fenix.ext.components

private class EventWrapper<T : Enum<T>>(
Expand Down Expand Up @@ -371,7 +372,25 @@ private val Event.wrapper: EventWrapper<*>?
{ Events.whatsNewTapped.record(it) },
{ Events.whatsNewTappedKeys.valueOf(it) }
)

is Event.TrackingProtectionTrackerList -> EventWrapper<NoExtraKeys>(
{ TrackingProtection.etpTrackerList.record(it) }
)
is Event.TrackingProtectionIconPressed -> EventWrapper<NoExtraKeys>(
{ TrackingProtection.etpShield.record(it) }
)
is Event.TrackingProtectionSettingsPanel -> EventWrapper<NoExtraKeys>(
{ TrackingProtection.panelSettings.record(it) }
)
is Event.TrackingProtectionSettings -> EventWrapper<NoExtraKeys>(
{ TrackingProtection.etpSettings.record(it) }
)
is Event.TrackingProtectionException -> EventWrapper<NoExtraKeys>(
{ TrackingProtection.exceptionAdded.record(it) }
)
is Event.TrackingProtectionSettingChanged -> EventWrapper(
{ TrackingProtection.etpSettingChanged.record(it) },
{ TrackingProtection.etpSettingChangedKeys.valueOf(it) }
)
// Don't record other events in Glean:
is Event.AddBookmark -> null
is Event.OpenedBookmark -> null
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/org/mozilla/fenix/components/metrics/Metrics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import org.mozilla.fenix.GleanMetrics.ErrorPage
import org.mozilla.fenix.GleanMetrics.Events
import org.mozilla.fenix.GleanMetrics.Library
import org.mozilla.fenix.GleanMetrics.SearchShortcuts
import org.mozilla.fenix.GleanMetrics.TrackingProtection
import org.mozilla.fenix.R
import java.util.Locale

Expand Down Expand Up @@ -113,6 +114,11 @@ sealed class Event {
object PrivateBrowsingPinnedShortcutPrivateTab : Event()
object PrivateBrowsingStaticShortcutTab : Event()
object PrivateBrowsingStaticShortcutPrivateTab : Event()
object TrackingProtectionTrackerList : Event()
object TrackingProtectionIconPressed : Event()
object TrackingProtectionSettingsPanel : Event()
object TrackingProtectionSettings : Event()
object TrackingProtectionException : Event()

// Interaction events with extras

Expand All @@ -136,6 +142,12 @@ sealed class Event {
}
}

data class TrackingProtectionSettingChanged(val setting: Setting) : Event() {
enum class Setting { STRICT, STANDARD }
override val extras: Map<TrackingProtection.etpSettingChangedKeys, String>?
get() = hashMapOf(TrackingProtection.etpSettingChangedKeys.etpSetting to setting.name)
}

data class OpenedApp(val source: Source) : Event() {
enum class Source { APP_ICON, LINK, CUSTOM_TAB }
override val extras: Map<Events.appOpenedKeys, String>?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class SettingsFragment : PreferenceFragmentCompat(), AccountObserver {
navigateToSearchEngineSettings()
}
resources.getString(pref_key_tracking_protection_settings) -> {
requireContext().metrics.track(Event.TrackingProtectionSettings)
navigateToTrackingProtectionSettings()
}
resources.getString(pref_key_site_permissions) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.FeatureFlags
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.getPreferenceKey
import org.mozilla.fenix.ext.metrics
import org.mozilla.fenix.ext.nav
import org.mozilla.fenix.ext.settings

Expand Down Expand Up @@ -60,7 +62,7 @@ class TrackingProtectionFragment : PreferenceFragmentCompat() {
}

bindStrict()
bindRecommended()
bindStandard()
setupRadioGroups()

val trackingProtectionLearnMore =
Expand Down Expand Up @@ -88,7 +90,18 @@ class TrackingProtectionFragment : PreferenceFragmentCompat() {
private fun bindStrict() {
val keyStrict = getString(R.string.pref_key_tracking_protection_strict)
radioStrict = requireNotNull(findPreference(keyStrict))
radioStrict.onPreferenceChangeListener = SharedPreferenceUpdater()
radioStrict.isVisible = FeatureFlags.etpCategories
radioStrict.onPreferenceChangeListener = object : SharedPreferenceUpdater() {
override fun onPreferenceChange(preference: Preference, newValue: Any?): Boolean {
context?.metrics?.track(
Event.TrackingProtectionSettingChanged(
Event.TrackingProtectionSettingChanged.Setting.STRICT
)
)
return super.onPreferenceChange(preference, newValue)
}
}
radioStrict.onInfoClickListener {
nav(
R.id.trackingProtectionFragment,
Expand All @@ -101,10 +114,20 @@ class TrackingProtectionFragment : PreferenceFragmentCompat() {
}
}

private fun bindRecommended() {
private fun bindStandard() {
val keyStandard = getString(R.string.pref_key_tracking_protection_standard)
radioStandard = requireNotNull(findPreference(keyStandard))
radioStandard.isVisible = FeatureFlags.etpCategories
radioStandard.onPreferenceChangeListener = object : SharedPreferenceUpdater() {
override fun onPreferenceChange(preference: Preference, newValue: Any?): Boolean {
context?.metrics?.track(
Event.TrackingProtectionSettingChanged(
Event.TrackingProtectionSettingChanged.Setting.STANDARD
)
)
return super.onPreferenceChange(preference, newValue)
}
}
radioStandard.onInfoClickListener {
nav(
R.id.trackingProtectionFragment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ import mozilla.components.support.base.feature.BackHandler
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.components.StoreProvider
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.exceptions.ExceptionDomains
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.metrics
import org.mozilla.fenix.ext.nav
import org.mozilla.fenix.ext.requireComponents
import java.net.MalformedURLException
Expand Down Expand Up @@ -146,6 +148,7 @@ class TrackingProtectionPanelDialogFragment : AppCompatDialogFragment(), BackHan
}

private fun openTrackingProtectionSettings() {
requireContext().metrics.track(Event.TrackingProtectionSettingsPanel)
nav(
R.id.trackingProtectionPanelDialogFragment,
TrackingProtectionPanelDialogFragmentDirections
Expand All @@ -162,6 +165,7 @@ class TrackingProtectionPanelDialogFragment : AppCompatDialogFragment(), BackHan
}
lifecycleScope.launch {
if (!ExceptionDomains.load(it).contains(host)) {
requireContext().metrics.track(Event.TrackingProtectionException)
ExceptionDomains.add(it, host)
} else {
ExceptionDomains.remove(it, listOf(host))
Expand Down
6 changes: 6 additions & 0 deletions docs/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ The following metrics are added to the ping:
| sync_auth.sign_in |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user pressed the sign in button on the sync authentication page and was successfully signed in to FxA |[1](https://github.com/mozilla-mobile/fenix/pull/2745#issuecomment-494918532)||2020-03-01 |
| sync_auth.sign_out |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user pressed the sign out button on the sync account page and was successfully signed out of FxA |[1](https://github.com/mozilla-mobile/fenix/pull/2745#issuecomment-494918532)||2020-03-01 |
| sync_auth.sign_up |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |User registered a new Firefox Account, and was signed into it |[1](https://github.com/mozilla-mobile/fenix/pull/4931#issuecomment-529740300)||2020-03-01 |
| tracking_protection.etp_setting_changed |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user added a TP exception through the TP toggle in the panel. |[1](https://github.com/mozilla-mobile/fenix/pull/TBD)|<ul><li>strict: The new setting for ETP: etp_strict, etp_standard</li></ul>|2020-03-01 |
| tracking_protection.etp_settings |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user opened ETP settings through settings. |[1](https://github.com/mozilla-mobile/fenix/pull/TBD)||2020-03-01 |
| tracking_protection.etp_shield |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user pressed the TP shield icon in toolbar. |[1](https://github.com/mozilla-mobile/fenix/pull/TBD)||2020-03-01 |
| tracking_protection.etp_tracker_list |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user pressed into tracker list display in panel. |[1](https://github.com/mozilla-mobile/fenix/pull/TBD)||2020-03-01 |
| tracking_protection.exception_added |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user added a TP exception through the TP toggle in the panel. |[1](https://github.com/mozilla-mobile/fenix/pull/TBD)||2020-03-01 |
| tracking_protection.panel_settings |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user opened ETP settings from the panel. |[1](https://github.com/mozilla-mobile/fenix/pull/TBD)||2020-03-01 |

## metrics
This is a built-in ping that is assembled out of the box by the Glean SDK.
Expand Down

0 comments on commit 95b675a

Please sign in to comment.