diff --git a/app/metrics.yaml b/app/metrics.yaml
index ebf33eb5884a..e61bdcc16a60 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 fb48418a74f9..213bec6a9c00 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 e6627603b446..6ad4107f05f3 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 727e8d0a121c..8d741fac8557 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 2a5dd38f2a7c..7e2c43baa56c 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_countpref_key_search_widget_cfr_display_countpref_key_search_widget_cfr_dismiss_count
diff --git a/docs/metrics.md b/docs/metrics.md
index 43ae931bca1b..aa17d6773f96 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 `.