From da1e6e78fa8aec81def6a13b23d1b3138978c180 Mon Sep 17 00:00:00 2001 From: ekager Date: Tue, 31 Mar 2020 11:27:10 -0700 Subject: [PATCH] For #8125 - Send top sites count with metrics ping --- app/metrics.yaml | 14 ++++++++++++++ .../components/metrics/GleanMetricsService.kt | 1 + .../java/org/mozilla/fenix/home/HomeFragment.kt | 17 ++++------------- .../java/org/mozilla/fenix/utils/Settings.kt | 5 +++++ app/src/main/res/values/preference_keys.xml | 1 + docs/metrics.md | 1 + 6 files changed, 26 insertions(+), 13 deletions(-) diff --git a/app/metrics.yaml b/app/metrics.yaml index 7e1d90e13552..8b2112aa4d1c 100644 --- a/app/metrics.yaml +++ b/app/metrics.yaml @@ -295,6 +295,20 @@ metrics: notification_emails: - fenix-core@mozilla.com expires: "2020-09-01" + top_sites_count: + type: string + lifetime: application + description: > + A string that indicates how many top sites a user has + send_in_pings: + - metrics + bugs: + - https://github.com/mozilla-mobile/fenix/issues/8125 + data_reviews: + - tbd + notification_emails: + - fenix-core@mozilla.com + expires: "2020-09-01" search_count: type: labeled_counter description: > 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 7088a6f1537d..f84d23113e18 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 @@ -546,6 +546,7 @@ class GleanMetricsService(private val context: Context) : MetricsService { adjustAdGroup.set(context.settings().adjustAdGroup) adjustCreative.set(context.settings().adjustCreative) adjustNetwork.set(context.settings().adjustNetwork) + topSitesCount.set(context.settings().topSitesSize.toString()) toolbarPosition.set( if (context.settings().shouldUseBottomToolbar) { diff --git a/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt b/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt index 9de9f019e1d4..ccf716ff3183 100644 --- a/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt @@ -42,19 +42,8 @@ import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView.SCROLL_STATE_IDLE import com.google.android.material.appbar.AppBarLayout import com.google.android.material.snackbar.Snackbar -import kotlinx.android.synthetic.main.fragment_home.homeAppBar -import kotlinx.android.synthetic.main.fragment_home.privateBrowsingButton -import kotlinx.android.synthetic.main.fragment_home.search_engine_icon -import kotlinx.android.synthetic.main.fragment_home.toolbarLayout -import kotlinx.android.synthetic.main.fragment_home.view.add_tab_button -import kotlinx.android.synthetic.main.fragment_home.view.bottomBarShadow -import kotlinx.android.synthetic.main.fragment_home.view.bottom_bar -import kotlinx.android.synthetic.main.fragment_home.view.homeAppBar -import kotlinx.android.synthetic.main.fragment_home.view.menuButton -import kotlinx.android.synthetic.main.fragment_home.view.sessionControlRecyclerView -import kotlinx.android.synthetic.main.fragment_home.view.toolbar -import kotlinx.android.synthetic.main.fragment_home.view.toolbarLayout -import kotlinx.android.synthetic.main.fragment_home.view.toolbar_wrapper +import kotlinx.android.synthetic.main.fragment_home.* +import kotlinx.android.synthetic.main.fragment_home.view.* import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main @@ -689,6 +678,8 @@ class HomeFragment : Fragment() { private fun subscribeToTopSites(): Observer> { return Observer> { topSites -> requireComponents.core.topSiteStorage.cachedTopSites = topSites + context?.settings()?.preferences?.edit() + ?.putInt(getString(R.string.pref_key_top_sites_size), topSites.size)?.apply() homeFragmentStore.dispatch(HomeFragmentAction.TopSitesChange(topSites)) }.also { observer -> requireComponents.core.topSiteStorage.getTopSites().observe(this, observer) 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 5b4c5f4cf1fd..1b0478db7c4a 100644 --- a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt +++ b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt @@ -609,4 +609,9 @@ class Settings private constructor( appContext.getPreferenceKey(R.string.pref_key_override_sync_tokenserver), default = "" ) + + val topSitesSize by intPreference( + appContext.getPreferenceKey(R.string.pref_key_top_sites_size), + default = 0 + ) } diff --git a/app/src/main/res/values/preference_keys.xml b/app/src/main/res/values/preference_keys.xml index fd44fb5bf853..9a1683a67b12 100644 --- a/app/src/main/res/values/preference_keys.xml +++ b/app/src/main/res/values/preference_keys.xml @@ -156,4 +156,5 @@ pref_key_encryption_key_generated pref_key_pocket_top_site_added + pref_key_top_sites_size diff --git a/docs/metrics.md b/docs/metrics.md index 930a4a777d53..ab9b560ff613 100644 --- a/docs/metrics.md +++ b/docs/metrics.md @@ -213,6 +213,7 @@ The following metrics are added to the ping: | 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.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.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 |[string](https://mozilla.github.io/glean/book/user/metrics/string.html) |A string that indicates how many top sites a user has |[1](tbd)||2020-09-01 | | search.default_engine.code |[string](https://mozilla.github.io/glean/book/user/metrics/string.html) |If the search engine is pre-loaded with Fenix this value will be the search engine identifier. If it's a custom search engine (defined: https://github.com/mozilla-mobile/fenix/issues/1607) the value will be "custom" |[1](https://github.com/mozilla-mobile/fenix/pull/1606), [2](https://github.com/mozilla-mobile/fenix/pull/5216)||2020-09-01 | | search.default_engine.name |[string](https://mozilla.github.io/glean/book/user/metrics/string.html) |If the search engine is pre-loaded with Fenix this value will be the search engine name. If it's a custom search engine (defined: https://github.com/mozilla-mobile/fenix/issues/1607) the value will be "custom" |[1](https://github.com/mozilla-mobile/fenix/pull/1606), [2](https://github.com/mozilla-mobile/fenix/pull/5216)||2020-09-01 | | search.default_engine.submission_url |[string](https://mozilla.github.io/glean/book/user/metrics/string.html) |If the search engine is pre-loaded with Fenix this value will be he base URL we use to build the search query for the search engine. For example: https://mysearchengine.com/?query=%s. If it's a custom search engine (defined: https://github.com/mozilla-mobile/fenix/issues/1607) the value will be "custom" |[1](https://github.com/mozilla-mobile/fenix/pull/1606), [2](https://github.com/mozilla-mobile/fenix/pull/5216)||2020-09-01 |