1
0
Fork 0

Fix search metrics (#4150)

* For #4082 - Changes lifecycles for metrics

* For #4082 - Replaces the SearchEngine name with the identifier for
countLabel
master
Jeff Boek 2019-07-18 14:35:34 -07:00 committed by GitHub
parent 9251597e84
commit e294521c92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 221 additions and 3 deletions

View File

@ -329,6 +329,7 @@ quick_action_sheet:
metrics: metrics:
default_browser: default_browser:
type: boolean type: boolean
lifetime: application
description: > description: >
Is Fenix the default browser? Is Fenix the default browser?
send_in_pings: send_in_pings:
@ -361,6 +362,7 @@ metrics:
expires: "2019-09-01" expires: "2019-09-01"
mozilla_products: mozilla_products:
type: string_list type: string_list
lifetime: application
description: > description: >
A list of all the Mozilla products installed on device. We currently scan for: Firefox, Firefox Beta, 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, Firefox Aurora, Firefox Nightly, Firefox Fdroid, Firefox Lite, Reference Browser, Reference Browser Debug,
@ -376,8 +378,9 @@ metrics:
expires: "2019-09-01" expires: "2019-09-01"
default_moz_browser: default_moz_browser:
type: string type: string
lifetime: application
description: > description: >
The name of the default browser on device if and only if it's a Mozilla owned product, otherwise empty string The name of the default browser on device if and only if it's a Mozilla owned product
send_in_pings: send_in_pings:
- metrics - metrics
bugs: bugs:
@ -391,6 +394,7 @@ metrics:
search.default_engine: search.default_engine:
code: code:
type: string type: string
lifetime: application
description: > description: >
If the search engine is pre-loaded with Fenix this value If the search engine is pre-loaded with Fenix this value
will be the search engine identifier. If it's a custom search engine will be the search engine identifier. If it's a custom search engine
@ -407,6 +411,7 @@ search.default_engine:
expires: "2019-09-01" expires: "2019-09-01"
name: name:
type: string type: string
lifetime: application
description: > description: >
If the search engine is pre-loaded with Fenix this value If the search engine is pre-loaded with Fenix this value
will be the search engine name. If it's a custom search engine will be the search engine name. If it's a custom search engine
@ -423,6 +428,7 @@ search.default_engine:
expires: "2019-09-01" expires: "2019-09-01"
submission_url: submission_url:
type: string type: string
lifetime: application
description: > description: >
If the search engine is pre-loaded with Fenix this value 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. will be he base URL we use to build the search query for the search engine.

View File

@ -270,7 +270,9 @@ class GleanMetricsService(private val context: Context) : MetricsService {
Metrics.apply { Metrics.apply {
defaultBrowser.set(Browsers.all(context).isDefaultBrowser) defaultBrowser.set(Browsers.all(context).isDefaultBrowser)
defaultMozBrowser.set(MozillaProductDetector.getMozillaBrowserDefault(context) ?: "") MozillaProductDetector.getMozillaBrowserDefault(context)?.also {
defaultMozBrowser.set(it)
}
mozillaProducts.set(MozillaProductDetector.getInstalledMozillaProducts(context)) mozillaProducts.set(MozillaProductDetector.getInstalledMozillaProducts(context))
} }

View File

@ -177,7 +177,7 @@ sealed class Event {
} }
val countLabel: String val countLabel: String
get() = "${source.searchEngine.name.toLowerCase(Locale.ROOT)}.$label" get() = "${source.searchEngine.identifier.toLowerCase(Locale.ROOT)}.$label"
val sourceLabel: String val sourceLabel: String
get() = "${source.descriptor}.$label" get() = "${source.descriptor}.$label"

View File

@ -0,0 +1,210 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.components.metrics
import mozilla.components.browser.search.SearchEngine
import mozilla.components.browser.search.SearchEngineManager
import mozilla.components.browser.search.provider.AssetsSearchEngineProvider
import mozilla.components.support.test.robolectric.testContext
import org.junit.Before
import org.mozilla.fenix.components.metrics.Event.PerformedSearch
import org.mozilla.fenix.components.metrics.Event.PerformedSearch.EngineSource
import org.mozilla.fenix.components.metrics.Event.PerformedSearch.EventSource
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.TestApplication
import org.mozilla.fenix.components.FenixLocaleSearchLocalizationProvider
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(application = TestApplication::class)
class PerformedSearchTest {
private lateinit var searchEngines: List<SearchEngine>
// Match against the Regex defined at
// https://github.com/mozilla-mobile/android-components/blob/master/components/service/glean/src/main/java/mozilla/components/service/glean/private/LabeledMetricType.kt#L43
// We're temporarily using it until better Glean testing APIs are available.
private val countLabelRegex = Regex("^[a-z_][a-z0-9_-]{0,29}(\\.[a-z0-9_-]{0,29})*$")
@Before
fun setUp() {
searchEngines = SearchEngineManager(listOf(provider)).getSearchEngines(testContext)
}
@Test
fun testThatCountLabelIsValid() {
val labels = searchEngines.map {
PerformedSearch(EventSource.Action(EngineSource.Shortcut(it))).eventSource.countLabel
}
labels.forEach {
assertTrue("$it does not match!", it.matches(countLabelRegex))
}
}
private val provider = AssetsSearchEngineProvider(
localizationProvider = FenixLocaleSearchLocalizationProvider(),
additionalIdentifiers = listOf(
"amazon-au",
"amazon-br",
"amazon-ca",
"amazon-co-uk",
"amazon-de",
"amazon-fr",
"amazon-in",
"amazon-it",
"amazon-jp",
"amazon-mx",
"amazon-nl",
"amazondotcom",
"azerdict",
"azet-sk",
"baidu",
"bing",
"bolcom-fy-NL",
"bolcom-nl",
"ceneje",
"coccoc",
"danawa-kr",
"daum-kr",
"ddg",
"diec2",
"drae",
"duckduckgo",
"elebila",
"faclair-beag",
"google-2018",
"google-b-1-m",
"google-b-m",
"google",
"gulesider-mobile-NO",
"heureka-cz",
"hotline-ua",
"leit-is",
"leo_ende_de",
"list-am",
"mapy-cz",
"mercadolibre-ar",
"mercadolibre-cl",
"mercadolibre-mx",
"naver-kr",
"odpiralni",
"pazaruvaj",
"pledarigrond",
"prisjakt-sv-SE",
"qwant",
"rediff",
"reta-vortaro",
"salidzinilv",
"seznam-cz",
"skroutz",
"slovnik-sk",
"sslv",
"sztaki-en-hu",
"taobao",
"tearma",
"twitter-ja",
"twitter",
"vatera",
"wikipedia-NN",
"wikipedia-NO",
"wikipedia-an",
"wikipedia-ar",
"wikipedia-as",
"wikipedia-ast",
"wikipedia-az",
"wikipedia-be",
"wikipedia-bg",
"wikipedia-bn",
"wikipedia-br",
"wikipedia-bs",
"wikipedia-ca",
"wikipedia-cy",
"wikipedia-cz",
"wikipedia-da",
"wikipedia-de",
"wikipedia-dsb",
"wikipedia-el",
"wikipedia-eo",
"wikipedia-es",
"wikipedia-et",
"wikipedia-eu",
"wikipedia-fa",
"wikipedia-fi",
"wikipedia-fr",
"wikipedia-fy-NL",
"wikipedia-ga-IE",
"wikipedia-gd",
"wikipedia-gl",
"wikipedia-gn",
"wikipedia-gu",
"wikipedia-he",
"wikipedia-hi",
"wikipedia-hr",
"wikipedia-hsb",
"wikipedia-hu",
"wikipedia-hy-AM",
"wikipedia-ia",
"wikipedia-id",
"wikipedia-is",
"wikipedia-it",
"wikipedia-ja",
"wikipedia-ka",
"wikipedia-kab",
"wikipedia-kk",
"wikipedia-km",
"wikipedia-kn",
"wikipedia-lij",
"wikipedia-lo",
"wikipedia-lt",
"wikipedia-ltg",
"wikipedia-lv",
"wikipedia-ml",
"wikipedia-mr",
"wikipedia-ms",
"wikipedia-my",
"wikipedia-ne",
"wikipedia-nl",
"wikipedia-oc",
"wikipedia-or",
"wikipedia-pa",
"wikipedia-pl",
"wikipedia-pt",
"wikipedia-rm",
"wikipedia-ro",
"wikipedia-ru",
"wikipedia-sk",
"wikipedia-sl",
"wikipedia-sq",
"wikipedia-sr",
"wikipedia-sv-SE",
"wikipedia-ta",
"wikipedia-te",
"wikipedia-th",
"wikipedia-tr",
"wikipedia-uk",
"wikipedia-ur",
"wikipedia-uz",
"wikipedia-vi",
"wikipedia-wo",
"wikipedia-zh-CN",
"wikipedia-zh-TW",
"wikipedia",
"wiktionary-kn",
"wiktionary-oc",
"wiktionary-or",
"wiktionary-ta",
"wiktionary-te",
"yahoo-jp",
"yandex-en",
"yandex-ru",
"yandex-tr",
"yandex.by",
"yandex"
)
)
}