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

For #6174 - Add telemetry for WebExtensions #8318

Merged
merged 1 commit into from Apr 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 50 additions & 0 deletions app/metrics.yaml
Expand Up @@ -1906,3 +1906,53 @@ installation:
notification_emails:
- fenix-core@mozilla.com
expires: "2020-09-01"

addons:
open_addons_in_settings:
type: event
description: >
A user accessed "Add-ons" from the Settings
bugs:
- https://github.com/mozilla-mobile/fenix/issues/6174
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/8318
notification_emails:
- fenix-core@mozilla.com
expires: "2020-09-01"
open_addon_in_toolbar_menu:
type: event
description: >
A user interacted with an installed add-on in the toolbar menu
bugs:
- https://github.com/mozilla-mobile/fenix/issues/6174
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/8318
notification_emails:
- fenix-core@mozilla.com
expires: "2020-09-01"
has_installed_addons:
type: boolean
description: >
Whether or not the user has installed add-ons on the device.
send_in_pings:
- metrics
bugs:
- https://github.com/mozilla-mobile/fenix/issues/6174
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/8318
notification_emails:
- fenix-core@mozilla.com
expires: "2020-09-01"
has_enabled_addons:
type: boolean
description: >
Whether or not the user has enabled add-ons on the device.
send_in_pings:
- metrics
bugs:
- https://github.com/mozilla-mobile/fenix/issues/6174
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/8318
notification_emails:
- fenix-core@mozilla.com
expires: "2020-09-01"
Expand Up @@ -9,6 +9,7 @@ import mozilla.components.service.glean.Glean
import mozilla.components.service.glean.private.NoExtraKeys
import mozilla.components.support.base.log.logger.Logger
import org.mozilla.fenix.GleanMetrics.AboutPage
import org.mozilla.fenix.GleanMetrics.Addons
import org.mozilla.fenix.GleanMetrics.AppTheme
import org.mozilla.fenix.GleanMetrics.BookmarksManagement
import org.mozilla.fenix.GleanMetrics.Collections
Expand Down Expand Up @@ -491,6 +492,12 @@ private val Event.wrapper: EventWrapper<*>?
{ AppTheme.darkThemeSelected.record(it) },
{ AppTheme.darkThemeSelectedKeys.valueOf(it) }
)
is Event.AddonsOpenInSettings -> EventWrapper<NoExtraKeys>(
{ Addons.openAddonsInSettings.record(it) }
)
is Event.AddonsOpenInToolbarMenu -> EventWrapper<NoExtraKeys>(
{ Addons.openAddonInToolbarMenu.record(it) }
)
// Don't record other events in Glean:
is Event.AddBookmark -> null
is Event.OpenedBookmark -> null
Expand Down
62 changes: 53 additions & 9 deletions app/src/main/java/org/mozilla/fenix/components/metrics/Metrics.kt
Expand Up @@ -6,6 +6,7 @@ package org.mozilla.fenix.components.metrics

import android.content.Context
import mozilla.components.browser.errorpages.ErrorType
import mozilla.components.browser.menu.facts.BrowserMenuFacts
import mozilla.components.browser.search.SearchEngine
import mozilla.components.browser.toolbar.facts.ToolbarFacts
import mozilla.components.feature.contextmenu.facts.ContextMenuFacts
Expand All @@ -19,7 +20,9 @@ import mozilla.components.support.base.facts.Fact
import mozilla.components.support.base.facts.FactProcessor
import mozilla.components.support.base.facts.Facts
import mozilla.components.support.base.log.logger.Logger
import mozilla.components.support.webextensions.facts.WebExtensionFacts
import org.mozilla.fenix.BuildConfig
import org.mozilla.fenix.GleanMetrics.Addons
import org.mozilla.fenix.GleanMetrics.AppTheme
import org.mozilla.fenix.GleanMetrics.Collections
import org.mozilla.fenix.GleanMetrics.ContextMenu
Expand Down Expand Up @@ -152,10 +155,16 @@ sealed class Event {
object PocketTopSiteClicked : Event()
object PocketTopSiteRemoved : Event()
object FennecToFenixMigrated : Event()
object AddonsOpenInSettings : Event()
object AddonsOpenInToolbarMenu : Event()

// Interaction events with extras

data class PreferenceToggled(val preferenceKey: String, val enabled: Boolean, val context: Context) : Event() {
data class PreferenceToggled(
val preferenceKey: String,
val enabled: Boolean,
val context: Context
) : Event() {
private val booleanPreferenceTelemetryAllowList = listOf(
context.getString(R.string.pref_key_show_search_suggestions),
context.getString(R.string.pref_key_remote_debugging),
Expand Down Expand Up @@ -186,18 +195,21 @@ sealed class Event {

data class ToolbarPositionChanged(val position: Position) : Event() {
enum class Position { TOP, BOTTOM }

override val extras: Map<ToolbarSettings.changedPositionKeys, String>?
get() = hashMapOf(ToolbarSettings.changedPositionKeys.position to position.name)
}

data class OpenedLink(val mode: Mode) : Event() {
enum class Mode { NORMAL, PRIVATE }

override val extras: Map<Events.openedLinkKeys, String>?
get() = hashMapOf(Events.openedLinkKeys.mode to mode.name)
}

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)
}
Expand All @@ -211,6 +223,7 @@ sealed class Event {

data class OpenedApp(val source: Source) : Event() {
enum class Source { APP_ICON, LINK, CUSTOM_TAB }

override val extras: Map<Events.appOpenedKeys, String>?
get() = hashMapOf(Events.appOpenedKeys.source to source.name)
}
Expand Down Expand Up @@ -248,6 +261,7 @@ sealed class Event {

data class SearchBarTapped(val source: Source) : Event() {
enum class Source { HOME, BROWSER }

override val extras: Map<Events.searchBarTappedKeys, String>?
get() = mapOf(Events.searchBarTappedKeys.source to source.name)
}
Expand All @@ -262,8 +276,11 @@ sealed class Event {
abstract val engine: SearchEngine
abstract val isCustom: Boolean

data class Default(override val engine: SearchEngine, override val isCustom: Boolean) : EngineSource()
data class Shortcut(override val engine: SearchEngine, override val isCustom: Boolean) : EngineSource()
data class Default(override val engine: SearchEngine, override val isCustom: Boolean) :
EngineSource()

data class Shortcut(override val engine: SearchEngine, override val isCustom: Boolean) :
EngineSource()

// https://github.com/mozilla-mobile/fenix/issues/1607
// Sanitize identifiers for custom search engines.
Expand All @@ -284,7 +301,9 @@ sealed class Event {
}

sealed class EventSource(open val engineSource: EngineSource) {
data class Suggestion(override val engineSource: EngineSource) : EventSource(engineSource)
data class Suggestion(override val engineSource: EngineSource) :
EventSource(engineSource)

data class Action(override val engineSource: EngineSource) : EventSource(engineSource)
data class Widget(override val engineSource: EngineSource) : EventSource(engineSource)
data class Shortcut(override val engineSource: EngineSource) : EventSource(engineSource)
Expand Down Expand Up @@ -322,6 +341,7 @@ sealed class Event {

data class DarkThemeSelected(val source: Source) : Event() {
enum class Source { SETTINGS, ONBOARDING }

override val extras: Map<AppTheme.darkThemeSelectedKeys, String>?
get() = mapOf(AppTheme.darkThemeSelectedKeys.source to source.name)
}
Expand All @@ -331,7 +351,8 @@ sealed class Event {
get() = mapOf(ContextMenu.itemTappedKeys.named to item)

companion object {
fun create(context_item: String) = allowList[context_item]?.let { ContextMenuItemTapped(it) }
fun create(context_item: String) =
allowList[context_item]?.let { ContextMenuItemTapped(it) }

private val allowList = mapOf(
"mozac.feature.contextmenu.open_in_new_tab" to "open_in_new_tab",
Expand Down Expand Up @@ -379,6 +400,7 @@ private fun Fact.toEvent(): Event? = when (Pair(component, item)) {
Component.BROWSER_TOOLBAR to ToolbarFacts.Items.MENU -> {
metadata?.get("customTab")?.let { Event.CustomTabsMenuOpened }
}
Component.BROWSER_MENU to BrowserMenuFacts.Items.WEB_EXTENSION_MENU_ITEM -> Event.AddonsOpenInToolbarMenu
Component.FEATURE_CUSTOMTABS to CustomTabsFacts.Items.CLOSE -> Event.CustomTabsClosed
Component.FEATURE_CUSTOMTABS to CustomTabsFacts.Items.ACTION_BUTTON -> Event.CustomTabsActionTapped

Expand Down Expand Up @@ -408,6 +430,21 @@ private fun Fact.toEvent(): Event? = when (Pair(component, item)) {
else -> null
}
}
Component.SUPPORT_WEBEXTENSIONS to WebExtensionFacts.Items.WEB_EXTENSIONS_INITIALIZED -> {
metadata?.get("installed")?.let { installedAddons ->
if (installedAddons is List<*>) {
Addons.hasInstalledAddons.set(installedAddons.size > 0)
}
}

metadata?.get("enabled")?.let { enabledAddons ->
if (enabledAddons is List<*>) {
Addons.hasEnabledAddons.set(enabledAddons.size > 0)
}
}

null
}
else -> null
}

Expand Down Expand Up @@ -439,7 +476,8 @@ interface MetricController {
ReleaseMetricController(
services,
isDataTelemetryEnabled,
isMarketingDataTelemetryEnabled)
isMarketingDataTelemetryEnabled
)
} else DebugMetricController()
}
}
Expand Down Expand Up @@ -479,7 +517,9 @@ private class ReleaseMetricController(
override fun start(type: MetricServiceType) {
val isEnabled = isTelemetryEnabled(type)
val isInitialized = isInitialized(type)
if (!isEnabled || isInitialized) { return }
if (!isEnabled || isInitialized) {
return
}

services
.filter { it.type == type }
Expand All @@ -491,7 +531,9 @@ private class ReleaseMetricController(
override fun stop(type: MetricServiceType) {
val isEnabled = isTelemetryEnabled(type)
val isInitialized = isInitialized(type)
if (isEnabled || !isInitialized) { return }
if (isEnabled || !isInitialized) {
return
}

services
.filter { it.type == type }
Expand All @@ -506,7 +548,9 @@ private class ReleaseMetricController(
.forEach {
val isEnabled = isTelemetryEnabled(it.type)
val isInitialized = isInitialized(it.type)
if (!isEnabled || !isInitialized) { return }
if (!isEnabled || !isInitialized) {
return
}

it.track(event)
}
Expand Down
Expand Up @@ -196,6 +196,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
SettingsFragmentDirections.actionSettingsFragmentToLocaleSettingsFragment()
}
resources.getString(R.string.pref_key_addons) -> {
requireContext().metrics.track(Event.AddonsOpenInSettings)
SettingsFragmentDirections.actionSettingsFragmentToAddonsFragment()
}
resources.getString(R.string.pref_key_make_default_browser) -> {
Expand Down
4 changes: 4 additions & 0 deletions docs/metrics.md
Expand Up @@ -54,6 +54,8 @@ The following metrics are added to the ping:
| about_page.privacy_notice_tapped |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user tapped on "Privacy notice" item from About page |[1](https://github.com/mozilla-mobile/fenix/pull/8047)||2020-09-01 |
| about_page.rights_tapped |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user tapped on "Know your rights" item from About page |[1](https://github.com/mozilla-mobile/fenix/pull/8047)||2020-09-01 |
| about_page.support_tapped |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user tapped on "Support" item from About page |[1](https://github.com/mozilla-mobile/fenix/pull/8047)||2020-09-01 |
| addons.open_addon_in_toolbar_menu |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user interacted with an installed add-on in the toolbar menu |[1](https://github.com/mozilla-mobile/fenix/pull/8318)||2020-09-01 |
| addons.open_addons_in_settings |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user accessed "Add-ons" from the Settings |[1](https://github.com/mozilla-mobile/fenix/pull/8318)||2020-09-01 |
| app_theme.dark_theme_selected |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user selected Dark Theme |[1](https://github.com/mozilla-mobile/fenix/pull/7968)|<ul><li>source: The source from where dark theme was selected. The source can be 'SETTINGS' or 'ONBOARDING'</li></ul>|2020-09-01 |
| bookmarks_management.copied |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user copied a bookmark. |[1](https://github.com/mozilla-mobile/fenix/pull/1708)||2020-09-01 |
| bookmarks_management.edited |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user edited the title and/or URL of an existing bookmark. |[1](https://github.com/mozilla-mobile/fenix/pull/1708)||2020-09-01 |
Expand Down Expand Up @@ -203,6 +205,8 @@ The following metrics are added to the ping:

| Name | Type | Description | Data reviews | Extras | Expiration |
| --- | --- | --- | --- | --- | --- |
| addons.has_enabled_addons |[boolean](https://mozilla.github.io/glean/book/user/metrics/boolean.html) |Whether or not the user has enabled add-ons on the device. |[1](https://github.com/mozilla-mobile/fenix/pull/8318)||2020-09-01 |
| addons.has_installed_addons |[boolean](https://mozilla.github.io/glean/book/user/metrics/boolean.html) |Whether or not the user has installed add-ons on the device. |[1](https://github.com/mozilla-mobile/fenix/pull/8318)||2020-09-01 |
| events.total_uri_count |[counter](https://mozilla.github.io/glean/book/user/metrics/counter.html) |A counter of URIs visited by the user in the current session, including page reloads. This does not include background page requests and URIs from embedded pages or private browsing. |[1](https://github.com/mozilla-mobile/fenix/pull/1785), [2](https://github.com/mozilla-mobile/fenix/pull/8314)||2020-09-01 |
| metrics.adjust_ad_group |[string](https://mozilla.github.io/glean/book/user/metrics/string.html) |A string containing the Adjust ad group ID from which the user installed Fenix. This will not send on the first session the user runs. If the install is organic, this will be empty. |[1](https://github.com/mozilla-mobile/fenix/pull/9253)||2020-09-01 |
| metrics.adjust_campaign |[string](https://mozilla.github.io/glean/book/user/metrics/string.html) |A string containing the Adjust campaign ID from which the user installed Fenix. This will not send on the first session the user runs. If the install is organic, this will be empty. |[1](https://github.com/mozilla-mobile/fenix/pull/5579)||2020-09-01 |
Expand Down