2019-03-12 21:09:04 +01:00
|
|
|
/* 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 android.content.Context
|
2019-03-18 22:32:03 +01:00
|
|
|
import mozilla.components.service.glean.EventMetricType
|
2019-03-12 21:09:04 +01:00
|
|
|
import mozilla.components.service.glean.Glean
|
2019-03-18 21:30:25 +01:00
|
|
|
import mozilla.components.support.utils.Browsers
|
2019-03-12 21:09:04 +01:00
|
|
|
import org.mozilla.fenix.BuildConfig
|
|
|
|
import org.mozilla.fenix.utils.Settings
|
2019-03-18 21:30:25 +01:00
|
|
|
import org.mozilla.fenix.debug.GleanMetrics.Metrics
|
2019-03-18 22:32:03 +01:00
|
|
|
import org.mozilla.fenix.debug.GleanMetrics.Events
|
2019-03-12 21:09:04 +01:00
|
|
|
|
2019-03-18 22:54:36 +01:00
|
|
|
private val Event.metricType: EventMetricType?
|
2019-03-19 04:49:17 +01:00
|
|
|
get() = when (this) {
|
2019-03-18 22:54:36 +01:00
|
|
|
is Event.OpenedApp -> Events.appOpened
|
|
|
|
is Event.SearchBarTapped -> Events.searchBarTapped
|
2019-03-19 00:09:27 +01:00
|
|
|
is Event.EnteredUrl -> Events.enteredUrl
|
|
|
|
is Event.PerformedSearch -> Events.performedSearch
|
2019-03-18 22:54:36 +01:00
|
|
|
else -> null
|
|
|
|
}
|
|
|
|
|
2019-03-12 21:09:04 +01:00
|
|
|
class GleanMetricsService(private val context: Context) : MetricsService {
|
|
|
|
override fun start() {
|
|
|
|
Glean.initialize(context)
|
|
|
|
Glean.setUploadEnabled(IsGleanEnabled)
|
2019-03-18 21:30:25 +01:00
|
|
|
|
|
|
|
Metrics.apply {
|
|
|
|
defaultBrowser.set(Browsers.all(context).isDefaultBrowser)
|
|
|
|
}
|
2019-03-12 21:09:04 +01:00
|
|
|
}
|
|
|
|
|
2019-03-18 22:32:03 +01:00
|
|
|
override fun track(event: Event) {
|
2019-03-18 22:54:36 +01:00
|
|
|
event.metricType?.record(event.extras)
|
2019-03-18 22:32:03 +01:00
|
|
|
}
|
2019-03-12 21:09:04 +01:00
|
|
|
|
2019-03-18 22:32:03 +01:00
|
|
|
override fun shouldTrack(event: Event): Boolean {
|
2019-03-18 22:54:36 +01:00
|
|
|
return Settings.getInstance(context).isTelemetryEnabled && event.metricType != null
|
2019-03-18 22:32:03 +01:00
|
|
|
}
|
2019-03-12 21:09:04 +01:00
|
|
|
|
|
|
|
companion object {
|
|
|
|
private const val IsGleanEnabled = BuildConfig.TELEMETRY
|
|
|
|
}
|
|
|
|
}
|