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 23, 2019
1 parent e9a645a commit 9d9ff95
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 4 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 tracking protection exception through the TP toggle in the panel.
bugs:
- 5312
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/5414#issuecomment-532847188
notification_emails:
- [email protected]
expires: "2020-03-01"
panel_settings:
type: event
description: >
A user opened tracking protection settings from the panel.
bugs:
- 5312
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/5414#issuecomment-532847188
notification_emails:
- [email protected]
expires: "2020-03-01"
etp_shield:
type: event
description: >
A user pressed the tracking protection shield icon in toolbar.
bugs:
- 5312
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/5414#issuecomment-532847188
notification_emails:
- [email protected]
expires: "2020-03-01"
etp_tracker_list:
type: event
description: >
A user pressed into a list of categorized trackers in tracking protection panel.
bugs:
- 5312
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/5414#issuecomment-532847188
notification_emails:
- [email protected]
expires: "2020-03-01"
etp_settings:
type: event
description: >
A user opened tracking protection settings through settings.
bugs:
- 5312
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/5414#issuecomment-532847188
notification_emails:
- [email protected]
expires: "2020-03-01"
etp_setting_changed:
type: event
description: >
A user added a tracking protection 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/5414#issuecomment-532847188
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.SearchWidget
import org.mozilla.fenix.GleanMetrics.SyncAccount
import org.mozilla.fenix.GleanMetrics.SyncAuth
import org.mozilla.fenix.GleanMetrics.Tab
import org.mozilla.fenix.GleanMetrics.TrackingProtection
import org.mozilla.fenix.ext.components

private class EventWrapper<T : Enum<T>>(
Expand Down Expand Up @@ -377,7 +378,25 @@ private val Event.wrapper: EventWrapper<*>?
is Event.TabMediaPause -> EventWrapper<NoExtraKeys>(
{ Tab.mediaPause.record(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 @@ -115,6 +116,11 @@ sealed class Event {
object PrivateBrowsingStaticShortcutPrivateTab : Event()
object TabMediaPlay : Event()
object TabMediaPause : Event()
object TrackingProtectionTrackerList : Event()
object TrackingProtectionIconPressed : Event()
object TrackingProtectionSettingsPanel : Event()
object TrackingProtectionSettings : Event()
object TrackingProtectionException : Event()

// Interaction events with extras

Expand All @@ -138,6 +144,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 @@ -8,11 +8,13 @@ import android.content.Context
import android.content.SharedPreferences
import mozilla.components.support.ktx.android.content.PreferencesHolder
import mozilla.components.support.ktx.android.content.stringPreference
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.metrics

/**
* Contains functionality to manage custom domains for allow-list.
*/
class ExceptionDomains(context: Context) : PreferencesHolder {
class ExceptionDomains(val context: Context) : PreferencesHolder {

override val preferences: SharedPreferences =
context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE)
Expand Down Expand Up @@ -70,6 +72,7 @@ class ExceptionDomains(context: Context) : PreferencesHolder {
if (domain in load()) {
remove(listOf(domain))
} else {
context.metrics.track(Event.TrackingProtectionException)
add(domain)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,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 org.mozilla.fenix.ext.tryGetHostFromUrl
Expand Down Expand Up @@ -145,6 +147,7 @@ class TrackingProtectionPanelDialogFragment : AppCompatDialogFragment(), BackHan
}

private fun openTrackingProtectionSettings() {
requireContext().metrics.track(Event.TrackingProtectionSettingsPanel)
nav(
R.id.trackingProtectionPanelDialogFragment,
TrackingProtectionPanelDialogFragmentDirections
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import kotlinx.android.synthetic.main.fragment_quick_settings_dialog_sheet.url
import kotlinx.android.synthetic.main.switch_with_description.view.*
import mozilla.components.support.ktx.android.net.hostWithoutCommonPrefixes
import org.mozilla.fenix.R
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.metrics
import org.mozilla.fenix.trackingprotection.TrackingProtectionCategory.CROSS_SITE_TRACKING_COOKIES
import org.mozilla.fenix.trackingprotection.TrackingProtectionCategory.CRYPTOMINERS
import org.mozilla.fenix.trackingprotection.TrackingProtectionCategory.FINGERPRINTERS
Expand Down Expand Up @@ -133,6 +135,7 @@ class TrackingProtectionPanelView(

override fun onClick(v: View) {
val category = getCategory(v) ?: return
v.context.metrics.track(Event.TrackingProtectionTrackerList)
interactor.openDetails(category, categoryBlocked = !isLoaded(v))
}

Expand Down
6 changes: 6 additions & 0 deletions docs/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ The following metrics are added to the ping:
| 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 |
| tab.media_pause |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user pressed the pause icon on a tab from the home screen |[1](https://github.com/mozilla-mobile/fenix/pull/5266)||2020-03-01 |
| tab.media_play |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user pressed the play icon on a tab from the home screen |[1](https://github.com/mozilla-mobile/fenix/pull/5266)||2020-03-01 |
| tracking_protection.etp_setting_changed |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user added a tracking protection exception through the TP toggle in the panel. |[1](https://github.com/mozilla-mobile/fenix/pull/5414#issuecomment-532847188)|<ul><li>etp_setting: The new setting for ETP: strict, standard</li></ul>|2020-03-01 |
| tracking_protection.etp_settings |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user opened tracking protection settings through settings. |[1](https://github.com/mozilla-mobile/fenix/pull/5414#issuecomment-532847188)||2020-03-01 |
| tracking_protection.etp_shield |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user pressed the tracking protection shield icon in toolbar. |[1](https://github.com/mozilla-mobile/fenix/pull/5414#issuecomment-532847188)||2020-03-01 |
| tracking_protection.etp_tracker_list |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user pressed into a list of categorized trackers in tracking protection panel. |[1](https://github.com/mozilla-mobile/fenix/pull/5414#issuecomment-532847188)||2020-03-01 |
| tracking_protection.exception_added |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user added a tracking protection exception through the TP toggle in the panel. |[1](https://github.com/mozilla-mobile/fenix/pull/5414#issuecomment-532847188)||2020-03-01 |
| tracking_protection.panel_settings |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user opened tracking protection settings from the panel. |[1](https://github.com/mozilla-mobile/fenix/pull/5414#issuecomment-532847188)||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 9d9ff95

Please sign in to comment.