diff --git a/app/metrics.yaml b/app/metrics.yaml index ebf33eb58..e61bdcc16 100644 --- a/app/metrics.yaml +++ b/app/metrics.yaml @@ -689,6 +689,38 @@ metrics: notification_emails: - fenix-core@mozilla.com expires: "2020-09-01" + tabs_open_count: + type: counter + lifetime: application + description: | + A counter that indicates how many NORMAL tabs a user has open. This + value will only be set if the user has at least *one* open tab. If they + have 0, this ping will not get sent, resulting in a null value. To + disambiguate between a failed `tabs_open_count` ping and 0 open tabs, + please see `has_open_tabs`. + send_in_pings: + - metrics + bugs: + - https://github.com/mozilla-mobile/fenix/issues/11479 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/12024 + notification_emails: + - fenix-core@mozilla.com + expires: "2020-09-01" + has_open_tabs: + type: boolean + lifetime: application + description: | + A boolean that indicates if the user has any open NORMAL tabs. + send_in_pings: + - metrics + bugs: + - https://github.com/mozilla-mobile/fenix/issues/11479 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/12024 + notification_emails: + - fenix-core@mozilla.com + expires: "2020-09-01" preferences: show_search_suggestions: diff --git a/app/src/main/java/org/mozilla/fenix/browser/UriOpenedObserver.kt b/app/src/main/java/org/mozilla/fenix/browser/UriOpenedObserver.kt index fb48418a7..213bec6a9 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/UriOpenedObserver.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/UriOpenedObserver.kt @@ -12,9 +12,12 @@ import mozilla.components.browser.session.SessionManager import org.mozilla.fenix.components.metrics.MetricController import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.metrics +import org.mozilla.fenix.ext.settings import org.mozilla.fenix.search.telemetry.ads.AdsTelemetry +import org.mozilla.fenix.utils.Settings class UriOpenedObserver( + private val settings: Settings, private val owner: LifecycleOwner, private val sessionManager: SessionManager, metrics: MetricController, @@ -22,6 +25,7 @@ class UriOpenedObserver( ) : SessionManager.Observer { constructor(activity: FragmentActivity) : this( + activity.applicationContext.settings(), activity, activity.components.core.sessionManager, activity.metrics, @@ -41,20 +45,24 @@ class UriOpenedObserver( } override fun onAllSessionsRemoved() { + settings.setOpenTabsCount(sessionManager.sessions.filter { !it.private }.size) sessionManager.sessions.forEach { it.unregister(singleSessionObserver) } } override fun onSessionAdded(session: Session) { + settings.setOpenTabsCount(sessionManager.sessions.filter { !it.private }.size) session.register(singleSessionObserver, owner) } override fun onSessionRemoved(session: Session) { + settings.setOpenTabsCount(sessionManager.sessions.filter { !it.private }.size) session.unregister(singleSessionObserver) } override fun onSessionsRestored() { + settings.setOpenTabsCount(sessionManager.sessions.filter { !it.private }.size) sessionManager.sessions.forEach { it.register(singleSessionObserver, owner) } diff --git a/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt index e6627603b..6ad4107f0 100644 --- a/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt @@ -697,6 +697,12 @@ class GleanMetricsService(private val context: Context) : MetricsService { searchWidgetInstalled.set(context.settings().searchWidgetInstalled) + val openTabsCount = context.settings().openTabsCount + hasOpenTabs.set(openTabsCount > 0) + if (openTabsCount > 0) { + tabsOpenCount.add(openTabsCount) + } + val topSitesSize = context.settings().topSitesSize hasTopSites.set(topSitesSize > 0) if (topSitesSize > 0) { diff --git a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt index 727e8d0a1..8d741fac8 100644 --- a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt +++ b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt @@ -775,6 +775,19 @@ class Settings private constructor( default = 0 ) + fun setOpenTabsCount(count: Int) { + preferences.edit().putInt( + appContext.getPreferenceKey(R.string.pref_key_open_tabs_count), + count + ).apply() + } + + val openTabsCount: Int + get() = preferences.getInt( + appContext.getPreferenceKey(R.string.pref_key_open_tabs_count), + 0 + ) + private var savedLoginsSortingStrategyString by stringPreference( appContext.getPreferenceKey(R.string.pref_key_saved_logins_sorting_strategy), default = SavedLoginsFragment.SORTING_STRATEGY_ALPHABETICALLY diff --git a/app/src/main/res/values/preference_keys.xml b/app/src/main/res/values/preference_keys.xml index 2a5dd38f2..7e2c43baa 100644 --- a/app/src/main/res/values/preference_keys.xml +++ b/app/src/main/res/values/preference_keys.xml @@ -177,6 +177,8 @@ pref_key_debug_settings + pref_key_open_tabs_count + pref_key_search_count pref_key_search_widget_cfr_display_count pref_key_search_widget_cfr_dismiss_count diff --git a/app/src/test/java/org/mozilla/fenix/browser/TelemetrySessionObserverTest.kt b/app/src/test/java/org/mozilla/fenix/browser/TelemetrySessionObserverTest.kt index 9987ae88f..517d1cb24 100644 --- a/app/src/test/java/org/mozilla/fenix/browser/TelemetrySessionObserverTest.kt +++ b/app/src/test/java/org/mozilla/fenix/browser/TelemetrySessionObserverTest.kt @@ -16,9 +16,11 @@ import org.junit.Test import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.components.metrics.MetricController import org.mozilla.fenix.search.telemetry.ads.AdsTelemetry +import org.mozilla.fenix.utils.Settings class TelemetrySessionObserverTest { + private val settings: Settings = mockk(relaxed = true) private val owner: LifecycleOwner = mockk(relaxed = true) private val sessionManager: SessionManager = mockk(relaxed = true) private val metrics: MetricController = mockk(relaxed = true) @@ -29,7 +31,7 @@ class TelemetrySessionObserverTest { @Before fun setup() { singleSessionObserver = - UriOpenedObserver(owner, sessionManager, metrics, ads).singleSessionObserver + UriOpenedObserver(settings, owner, sessionManager, metrics, ads).singleSessionObserver } @Test diff --git a/app/src/test/java/org/mozilla/fenix/browser/UriOpenedObserverTest.kt b/app/src/test/java/org/mozilla/fenix/browser/UriOpenedObserverTest.kt index 43a7f8334..2b1224ba4 100644 --- a/app/src/test/java/org/mozilla/fenix/browser/UriOpenedObserverTest.kt +++ b/app/src/test/java/org/mozilla/fenix/browser/UriOpenedObserverTest.kt @@ -11,11 +11,13 @@ import mozilla.components.browser.session.Session import mozilla.components.browser.session.SessionManager import org.junit.Before import org.junit.Test -import org.mozilla.fenix.search.telemetry.ads.AdsTelemetry import org.mozilla.fenix.components.metrics.MetricController +import org.mozilla.fenix.search.telemetry.ads.AdsTelemetry +import org.mozilla.fenix.utils.Settings class UriOpenedObserverTest { + private val settings: Settings = mockk(relaxed = true) private val owner: LifecycleOwner = mockk(relaxed = true) private val sessionManager: SessionManager = mockk(relaxed = true) private val metrics: MetricController = mockk() @@ -24,7 +26,7 @@ class UriOpenedObserverTest { @Before fun setup() { - observer = UriOpenedObserver(owner, sessionManager, metrics, ads) + observer = UriOpenedObserver(settings, owner, sessionManager, metrics, ads) } @Test diff --git a/docs/metrics.md b/docs/metrics.md index 43ae931bc..aa17d6773 100644 --- a/docs/metrics.md +++ b/docs/metrics.md @@ -263,12 +263,14 @@ The following metrics are added to the ping: | metrics.adjust_network |[string](https://mozilla.github.io/glean/book/user/metrics/string.html) |A string containing the Adjust network 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.default_browser |[boolean](https://mozilla.github.io/glean/book/user/metrics/boolean.html) |Is Fenix the default browser? |[1](https://github.com/mozilla-mobile/fenix/pull/1067#issuecomment-474598673)||2020-09-01 | | metrics.default_moz_browser |[string](https://mozilla.github.io/glean/book/user/metrics/string.html) |The name of the default browser on device if and only if it's a Mozilla owned product |[1](https://github.com/mozilla-mobile/fenix/pull/1953/), [2](https://github.com/mozilla-mobile/fenix/pull/5216)||2020-09-01 | +| metrics.has_open_tabs |[boolean](https://mozilla.github.io/glean/book/user/metrics/boolean.html) |A boolean that indicates if the user has any open NORMAL tabs. |[1](https://github.com/mozilla-mobile/fenix/pull/12024)||2020-09-01 | | metrics.has_recent_pwas |[boolean](https://mozilla.github.io/glean/book/user/metrics/boolean.html) |A boolean that indicates if the user has recently used PWAs. See recently_used_pwa_count for the actual count. |[1](https://github.com/mozilla-mobile/fenix/pull/11982#pullrequestreview-437963817)||2020-12-01 | | metrics.has_top_sites |[boolean](https://mozilla.github.io/glean/book/user/metrics/boolean.html) |A boolean that indicates if the user has top sites |[1](https://github.com/mozilla-mobile/fenix/pull/9556)||2020-09-01 | | metrics.mozilla_products |[string_list](https://mozilla.github.io/glean/book/user/metrics/string_list.html) |A list of all the Mozilla products installed on device. We currently scan for: Firefox, Firefox Beta, Firefox Aurora, Firefox Nightly, Firefox Fdroid, Firefox Lite, Reference Browser, Reference Browser Debug, Fenix, Focus, and Lockwise. |[1](https://github.com/mozilla-mobile/fenix/pull/1953/), [2](https://github.com/mozilla-mobile/fenix/pull/5216)||2020-09-01 | | metrics.recently_used_pwa_count |[counter](https://mozilla.github.io/glean/book/user/metrics/counter.html) |A counter that indicates how many PWAs a user has recently used. Threshold for "recency" set in HomeActivity#PWA_RECENTLY_USED_THRESHOLD. Currently we are not told by the OS when a PWA is removed by the user, so we use the "recently used" heuristic to judge how many PWAs are still active, as a proxy for "installed". This value will only be set if the user has at least *one* recently used PWA. If they have 0, this metric will not be sent, resulting in a null value during analysis on the server-side. To disambiguate between a failed `recently_used_pwa_count` metric and 0 recent PWAs, please see `has_recent_pwas`. |[1](https://github.com/mozilla-mobile/fenix/pull/11982#pullrequestreview-437963817)||2020-12-01 | | metrics.search_count |[labeled_counter](https://mozilla.github.io/glean/book/user/metrics/labeled_counters.html) |The labels for this counter are `.`. If the search engine is bundled with Fenix `search-engine-name` will be the name of the search engine. If it's a custom search engine (defined: https://github.com/mozilla-mobile/fenix/issues/1607) the value will be `custom`. `source` will be: `action`, `suggestion`, `widget` or `shortcut` (depending on the source from which the search started). Also added the `other` option for the source but it should never enter on this case. |[1](https://github.com/mozilla-mobile/fenix/pull/1677), [2](https://github.com/mozilla-mobile/fenix/pull/5216), [3](https://github.com/mozilla-mobile/fenix/pull/7310)||2020-09-01 | | metrics.search_widget_installed |[boolean](https://mozilla.github.io/glean/book/user/metrics/boolean.html) |Whether or not the search widget is installed |[1](https://github.com/mozilla-mobile/fenix/pull/10958)||2020-09-01 | +| metrics.tabs_open_count |[counter](https://mozilla.github.io/glean/book/user/metrics/counter.html) |A counter that indicates how many NORMAL tabs a user has open. This value will only be set if the user has at least *one* open tab. If they have 0, this ping will not get sent, resulting in a null value. To disambiguate between a failed `tabs_open_count` ping and 0 open tabs, please see `has_open_tabs`. |[1](https://github.com/mozilla-mobile/fenix/pull/12024)||2020-09-01 | | metrics.toolbar_position |[string](https://mozilla.github.io/glean/book/user/metrics/string.html) |A string that indicates the new position of the toolbar TOP or BOTTOM |[1](https://github.com/mozilla-mobile/fenix/pull/6608)||2020-09-01 | | metrics.top_sites_count |[counter](https://mozilla.github.io/glean/book/user/metrics/counter.html) |A counter that indicates how many top sites a user has. This value will only be set if the user has at least *one* top site. If they have 0, this ping will not get sent, resulting in a null value. To disambiguate between a failed `top_sites_count` ping and 0 top sites, please see `has_top_sites`. |[1](https://github.com/mozilla-mobile/fenix/pull/9556)||2020-09-01 | | perf.awesomebar.bookmark_suggestions |[timing_distribution](https://mozilla.github.io/glean/book/user/metrics/timing_distribution.html) |Duration of a bookmarks awesomebar suggestion query. |[1](https://github.com/mozilla-mobile/fenix/pull/10276#pullrequestreview-411101979)||2020-09-15 |