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

For #24210: Remove wrapper for metrics in the "events" category #24483

Merged
merged 15 commits into from
Apr 6, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ events:
description: |
The method used to open Fenix. Possible values are: `app_icon`,
`custom_tab` or `link`
type: string
bugs:
- https://github.com/mozilla-mobile/fenix/issues/968
- https://github.com/mozilla-mobile/fenix/issues/10616
Expand Down Expand Up @@ -46,6 +47,7 @@ events:
description: |
The view the user was on when they initiated the search (For example:
`Home` or `Browser`)
type: string
bugs:
- https://github.com/mozilla-mobile/fenix/issues/959
- https://github.com/mozilla-mobile/fenix/issues/19923
Expand Down Expand Up @@ -73,6 +75,7 @@ events:
description: |
A boolean that tells us whether the URL was autofilled by an
Autocomplete suggestion
type: boolean
bugs:
- https://github.com/mozilla-mobile/fenix/issues/959
- https://github.com/mozilla-mobile/fenix/issues/19923
Expand Down Expand Up @@ -142,6 +145,7 @@ events:
reader_mode_off, reader_mode_on, reload, remove_from_top_sites,
save_to_collection, set_default_browser, settings, share, stop,
sync_account, and sync_tabs.
type: string
bugs:
- https://github.com/mozilla-mobile/fenix/issues/1024
- https://github.com/mozilla-mobile/fenix/issues/19923
Expand Down Expand Up @@ -254,8 +258,10 @@ events:
pref_key_sync_logins, pref_key_sync_bookmarks, pref_key_sync_history,
pref_key_show_voice_search,
and pref_key_show_search_suggestions_in_private.
type: string
enabled:
description: "Whether or not the preference is *now* enabled"
type: boolean
bugs:
- https://github.com/mozilla-mobile/fenix/issues/975
- https://github.com/mozilla-mobile/fenix/issues/5094
Expand Down Expand Up @@ -317,6 +323,7 @@ events:
The mode the link was opened in. Either 'PRIVATE' or 'NORMAL'. N.B.:
this probe may be incorrectly implemented: see
https://github.com/mozilla-mobile/fenix/issues/14133
type: string
bugs:
- https://github.com/mozilla-mobile/fenix/issues/5737
- https://github.com/mozilla-mobile/fenix/issues/19923
Expand Down Expand Up @@ -425,6 +432,7 @@ events:
description: |
A string containing the name of the tab view the user tapped.
These items include: list or grid.
type: string
bugs:
- https://github.com/mozilla-mobile/fenix/issues/19956
data_reviews:
Expand Down
14 changes: 8 additions & 6 deletions app/src/main/java/org/mozilla/fenix/HomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ import mozilla.components.support.locale.LocaleAwareAppCompatActivity
import mozilla.components.support.utils.SafeIntent
import mozilla.components.support.utils.toSafeIntent
import mozilla.components.support.webextensions.WebExtensionPopupFeature
import mozilla.telemetry.glean.private.NoExtras
import org.mozilla.fenix.GleanMetrics.Events
import org.mozilla.fenix.GleanMetrics.Metrics
import org.mozilla.fenix.addons.AddonDetailsFragmentDirections
import org.mozilla.fenix.addons.AddonPermissionsDetailsFragmentDirections
Expand Down Expand Up @@ -171,7 +173,7 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
StartSearchIntentProcessor(components.analytics.metrics),
OpenBrowserIntentProcessor(this, ::getIntentSessionId),
OpenSpecificTabIntentProcessor(this),
DefaultBrowserIntentProcessor(this, components.analytics.metrics)
DefaultBrowserIntentProcessor(this)
)
}

Expand Down Expand Up @@ -258,7 +260,7 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
val safeIntent = intent?.toSafeIntent()
safeIntent
?.let(::getIntentSource)
?.also { components.analytics.metrics.track(Event.OpenedApp(it)) }
?.also { Events.appOpened.record(Events.AppOpenedExtra(it)) }
}
supportActionBar?.hide()

Expand Down Expand Up @@ -345,7 +347,7 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
}

if (settings().checkIfFenixIsDefaultBrowserOnAppResume()) {
metrics.track(Event.ChangedToDefaultBrowser)
Events.defaultBrowserChanged.record(NoExtras())
}

DefaultBrowserNotificationWorker.setDefaultBrowserNotificationIfNeeded(applicationContext)
Expand Down Expand Up @@ -667,10 +669,10 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
}

@VisibleForTesting(otherwise = PROTECTED)
internal open fun getIntentSource(intent: SafeIntent): Event.OpenedApp.Source? {
internal open fun getIntentSource(intent: SafeIntent): String? {
return when {
intent.isLauncherIntent -> Event.OpenedApp.Source.APP_ICON
intent.action == Intent.ACTION_VIEW -> Event.OpenedApp.Source.LINK
intent.isLauncherIntent -> "APP_ICON"
intent.action == Intent.ACTION_VIEW -> "LINK"
else -> null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import mozilla.components.feature.intent.ext.sanitize
import mozilla.components.feature.intent.processing.IntentProcessor
import mozilla.components.support.utils.EXTRA_ACTIVITY_REFERRER_CATEGORY
import mozilla.components.support.utils.EXTRA_ACTIVITY_REFERRER_PACKAGE
import org.mozilla.fenix.GleanMetrics.Events
import org.mozilla.fenix.HomeActivity.Companion.PRIVATE_BROWSING_MODE
import org.mozilla.fenix.components.IntentProcessorType
import org.mozilla.fenix.components.getType
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.perf.MarkersActivityLifecycleCallbacks
Expand Down Expand Up @@ -58,9 +58,9 @@ class IntentReceiverActivity : Activity() {
val private = settings().openLinksInAPrivateTab
intent.putExtra(PRIVATE_BROWSING_MODE, private)
if (private) {
components.analytics.metrics.track(Event.OpenedLink(Event.OpenedLink.Mode.PRIVATE))
Events.openedLink.record(Events.OpenedLinkExtra("PRIVATE"))
} else {
components.analytics.metrics.track(Event.OpenedLink(Event.OpenedLink.Mode.NORMAL))
Events.openedLink.record(Events.OpenedLinkExtra("NORMAL"))
}

addReferrerInformation(intent)
Expand Down Expand Up @@ -94,7 +94,7 @@ class IntentReceiverActivity : Activity() {
components.intentProcessors.privateIntentProcessor
)
} else {
components.analytics.metrics.track(Event.OpenedLink(Event.OpenedLink.Mode.NORMAL))
Events.openedLink.record(Events.OpenedLinkExtra("NORMAL"))
listOf(
components.intentProcessors.customTabIntentProcessor,
components.intentProcessors.intentProcessor
Expand Down
95 changes: 0 additions & 95 deletions app/src/main/java/org/mozilla/fenix/components/metrics/Event.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

package org.mozilla.fenix.components.metrics

import android.content.Context
import mozilla.components.browser.state.search.SearchEngine
import mozilla.components.feature.top.sites.TopSite
import org.mozilla.fenix.GleanMetrics.Addons
Expand All @@ -17,7 +16,6 @@ import org.mozilla.fenix.GleanMetrics.Logins
import org.mozilla.fenix.GleanMetrics.Pocket
import org.mozilla.fenix.GleanMetrics.SearchTerms
import org.mozilla.fenix.GleanMetrics.TopSites
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.name
import java.util.Locale

Expand All @@ -32,7 +30,6 @@ sealed class Event {
object CustomTabsClosed : Event()
object CustomTabsActionTapped : Event()
object CustomTabsMenuOpened : Event()
object NormalAndPrivateUriOpened : Event()
object HistoryOpened : Event()
object HistoryItemShared : Event()
object HistoryItemOpened : Event()
Expand Down Expand Up @@ -87,7 +84,6 @@ sealed class Event {
object EditLogin : Event()
object EditLoginSave : Event()
object ViewLoginPassword : Event()
object WhatsNewTapped : Event()
object PocketTopSiteClicked : Event()
object PocketTopSiteRemoved : Event()
object PocketHomeRecsShown : Event()
Expand Down Expand Up @@ -122,19 +118,12 @@ sealed class Event {
object AddonsOpenInSettings : Event()
object VoiceSearchTapped : Event()
object SearchWidgetInstalled : Event()
object ChangedToDefaultBrowser : Event()
object DefaultBrowserNotifTapped : Event()

object ProgressiveWebAppOpenFromHomescreenTap : Event()
object ProgressiveWebAppInstallAsShortcut : Event()

object TabSettingsOpened : Event()

object CopyUrlUsed : Event()

object SyncedTabOpened : Event()

object RecentlyClosedTabsOpenedOld : Event()
object HaveOpenTabs : Event()
object HaveNoOpenTabs : Event()

Expand All @@ -152,7 +141,6 @@ sealed class Event {
object OpenedTabSuggestionClicked : Event()

// Set default browser experiment metrics
object ToolbarMenuShown : Event()
object SetDefaultBrowserToolbarMenuClicked : Event()

// Home menu interaction
Expand All @@ -161,9 +149,6 @@ sealed class Event {
object HomeScreenViewCount : Event()
object HomeScreenCustomizedHomeClicked : Event()

// Browser Toolbar
object BrowserToolbarHomeButtonClicked : Event()

// Start on Home
object StartOnHomeEnterHomeScreen : Event()
object StartOnHomeOpenTabsTray : Event()
Expand Down Expand Up @@ -226,40 +211,6 @@ sealed class Event {
enum class Source { NEWTAB }
}

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),
context.getString(R.string.pref_key_telemetry),
context.getString(R.string.pref_key_tracking_protection),
context.getString(R.string.pref_key_search_bookmarks),
context.getString(R.string.pref_key_search_browsing_history),
context.getString(R.string.pref_key_show_clipboard_suggestions),
context.getString(R.string.pref_key_show_search_engine_shortcuts),
context.getString(R.string.pref_key_open_links_in_a_private_tab),
context.getString(R.string.pref_key_sync_logins),
context.getString(R.string.pref_key_sync_bookmarks),
context.getString(R.string.pref_key_sync_history),
context.getString(R.string.pref_key_show_voice_search),
context.getString(R.string.pref_key_show_search_suggestions_in_private)
)

override val extras: Map<Events.preferenceToggledKeys, String>?
get() = mapOf(
Events.preferenceToggledKeys.preferenceKey to preferenceKey,
Events.preferenceToggledKeys.enabled to enabled.toString()
)

init {
// If the event is not in the allow list, we don't want to track it
require(booleanPreferenceTelemetryAllowList.contains(preferenceKey))
}
}

data class AddonsOpenInToolbarMenu(val addonId: String) : Event() {
override val extras: Map<Addons.openAddonInToolbarMenuKeys, String>?
get() = hashMapOf(Addons.openAddonInToolbarMenuKeys.addonId to addonId)
Expand All @@ -270,39 +221,13 @@ sealed class Event {
get() = hashMapOf(Addons.openAddonSettingKeys.addonId to addonId)
}

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 SaveLoginsSettingChanged(val setting: Setting) : Event() {
enum class Setting { NEVER_SAVE, ASK_TO_SAVE }

override val extras: Map<Logins.saveLoginsSettingChangedKeys, String>?
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<Events.appOpenedKeys, String>?
get() = hashMapOf(Events.appOpenedKeys.source to source.name)
}

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)
}

data class EnteredUrl(val autoCompleted: Boolean) : Event() {
override val extras: Map<Events.enteredUrlKeys, String>?
get() = mapOf(Events.enteredUrlKeys.autocomplete to autoCompleted.toString())
}

data class PerformedSearch(val eventSource: EventSource) : Event() {
sealed class EngineSource {
abstract val engine: SearchEngine
Expand Down Expand Up @@ -412,19 +337,6 @@ sealed class Event {

data class AddonInstalled(val addonId: String) : Event()

data class BrowserMenuItemTapped(val item: Item) : Event() {
enum class Item {
SETTINGS, HELP, DESKTOP_VIEW_ON, DESKTOP_VIEW_OFF, FIND_IN_PAGE, NEW_TAB,
NEW_PRIVATE_TAB, SHARE, BACK, FORWARD, RELOAD, STOP, OPEN_IN_FENIX,
SAVE_TO_COLLECTION, ADD_TO_TOP_SITES, REMOVE_FROM_TOP_SITES, ADD_TO_HOMESCREEN, QUIT, READER_MODE_ON,
READER_MODE_OFF, OPEN_IN_APP, BOOKMARK, READER_MODE_APPEARANCE, ADDONS_MANAGER,
BOOKMARKS, HISTORY, SYNC_TABS, DOWNLOADS, SET_DEFAULT_BROWSER, SYNC_ACCOUNT
}

override val extras: Map<Events.browserMenuActionKeys, String>?
get() = mapOf(Events.browserMenuActionKeys.item to item.toString().lowercase(Locale.ROOT))
}

object AutoPlaySettingVisited : Event()

data class AutoPlaySettingChanged(val setting: AutoplaySetting) : Event() {
Expand All @@ -436,13 +348,6 @@ sealed class Event {
get() = mapOf(Autoplay.settingChangedKeys.autoplaySetting to setting.toString().lowercase(Locale.ROOT))
}

data class TabViewSettingChanged(val type: Type) : Event() {
enum class Type { LIST, GRID }

override val extras: Map<Events.tabViewChangedKeys, String>?
get() = mapOf(Events.tabViewChangedKeys.type to type.toString().lowercase(Locale.ROOT))
}

data class SearchTermGroupCount(val count: Int) : Event() {
override val extras: Map<SearchTerms.numberOfSearchTermGroupKeys, String>
get() = hashMapOf(SearchTerms.numberOfSearchTermGroupKeys.count to count.toString())
Expand Down
Loading