From a2666c4f746790b433a84a355ae8ea1ea0f81104 Mon Sep 17 00:00:00 2001 From: Jeff Boek Date: Fri, 12 Apr 2019 13:25:16 -0700 Subject: [PATCH] For #800 - Adds metrics for the default search engine --- app/metrics.yaml | 50 +++++++++++++++++++ .../components/metrics/GleanMetricsService.kt | 14 ++++++ 2 files changed, 64 insertions(+) diff --git a/app/metrics.yaml b/app/metrics.yaml index b30830627..b1b5e1173 100644 --- a/app/metrics.yaml +++ b/app/metrics.yaml @@ -308,3 +308,53 @@ metrics: - fenix-core@mozilla.com expires: "2020-03-01" +search.default_engine: + code: + type: string + description: > + 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" + send_in_pings: + - metrics + bugs: + - 800 + data_reviews: + - https://github.com/mozilla-mobile/fenix/issues/1607 + notification_emails: + - fenix-core@mozilla.com + expires: "2019-09-01" + name: + type: string + description: > + 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" + send_in_pings: + - metrics + bugs: + - 800 + data_reviews: + - https://github.com/mozilla-mobile/fenix/issues/1607 + notification_emails: + - fenix-core@mozilla.com + expires: "2019-09-01" + submission_url: + type: string + description: > + 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" + send_in_pings: + - metrics + bugs: + - 800 + data_reviews: + - https://github.com/mozilla-mobile/fenix/issues/1607 + notification_emails: + - fenix-core@mozilla.com + expires: "2019-09-01" 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 493e43571..277d8587f 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 @@ -13,6 +13,8 @@ import org.mozilla.fenix.GleanMetrics.FindInPage import org.mozilla.fenix.GleanMetrics.ContextMenu import org.mozilla.fenix.GleanMetrics.QuickActionSheet import org.mozilla.fenix.GleanMetrics.Metrics +import org.mozilla.fenix.GleanMetrics.SearchDefaultEngine +import org.mozilla.fenix.ext.components private class EventWrapper>( private val recorder: ((Map?) -> Unit), @@ -119,6 +121,18 @@ class GleanMetricsService(private val context: Context) : MetricsService { defaultBrowser.set(Browsers.all(context).isDefaultBrowser) } + SearchDefaultEngine.apply { + val defaultEngine = context + .components + .search + .searchEngineManager + .defaultSearchEngine ?: return@apply + + code.set(defaultEngine.identifier) + name.set(defaultEngine.name) + submissionUrl.set(defaultEngine.buildSearchUrl("")) + } + initialized = true }