For #11479: Record open tabs count in metrics ping (#12024)

fennec/production
Sawyer Blatz 4 years ago committed by GitHub
parent c6415ce18f
commit 8a08cb941e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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:

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

@ -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) {

@ -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

@ -177,6 +177,8 @@
<string name="pref_key_debug_settings" translatable="false">pref_key_debug_settings</string>
<string name="pref_key_open_tabs_count" translatable="false">pref_key_open_tabs_count</string>
<string name="pref_key_search_count" translatable="false">pref_key_search_count</string>
<string name="pref_key_search_widget_cfr_display_count" translatable="false">pref_key_search_widget_cfr_display_count</string>
<string name="pref_key_search_widget_cfr_dismiss_count" translatable="false">pref_key_search_widget_cfr_dismiss_count</string>

@ -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

@ -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

@ -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 `<search-engine-name>.<source>`. 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 |

Loading…
Cancel
Save