For #1036 - Maps facts to events
parent
c284b0e22e
commit
c678b5d7c5
|
@ -374,7 +374,10 @@ class BrowserFragment : Fragment(), BackHandler {
|
|||
Navigation.findNavController(view!!).navigate(directions)
|
||||
(activity as HomeActivity).browsingModeManager.mode = BrowsingModeManager.Mode.Private
|
||||
}
|
||||
ToolbarMenu.Item.FindInPage -> FindInPageIntegration.launch?.invoke()
|
||||
ToolbarMenu.Item.FindInPage -> {
|
||||
FindInPageIntegration.launch?.invoke()
|
||||
requireComponents.analytics.metrics.track(Event.FindInPageOpened)
|
||||
}
|
||||
ToolbarMenu.Item.ReportIssue -> requireComponents.core.sessionManager
|
||||
.selectedSession?.url?.apply {
|
||||
val reportUrl = String.format(REPORT_SITE_ISSUE_URL, this)
|
||||
|
|
|
@ -3,6 +3,10 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
package org.mozilla.fenix.components.metrics
|
||||
|
||||
import mozilla.components.support.base.Component
|
||||
import mozilla.components.support.base.facts.Fact
|
||||
import mozilla.components.support.base.facts.FactProcessor
|
||||
import mozilla.components.support.base.facts.Facts
|
||||
import org.mozilla.fenix.BuildConfig
|
||||
|
||||
sealed class Event {
|
||||
|
@ -70,10 +74,26 @@ sealed class Event {
|
|||
get() = mapOf("engine" to engine)
|
||||
}
|
||||
|
||||
object FindInPageOpened: Event()
|
||||
object FindInPageClosed: Event()
|
||||
object FindInPageNext: Event()
|
||||
object FindInPagePrevious: Event()
|
||||
object FindInPageSearchCommitted: Event()
|
||||
|
||||
|
||||
open val extras: Map<String, String>?
|
||||
get() = null
|
||||
}
|
||||
|
||||
private fun Fact.toEvent(): Event? = when(Pair(component, item)){
|
||||
Pair(Component.FEATURE_FINDINPAGE, "previous") -> Event.FindInPagePrevious
|
||||
Pair(Component.FEATURE_FINDINPAGE, "next") -> Event.FindInPageNext
|
||||
Pair(Component.FEATURE_FINDINPAGE, "close") -> Event.FindInPageClosed
|
||||
Pair(Component.FEATURE_FINDINPAGE, "input") -> Event.FindInPageSearchCommitted
|
||||
else -> null
|
||||
}
|
||||
|
||||
|
||||
interface MetricsService {
|
||||
fun start()
|
||||
fun track(event: Event)
|
||||
|
@ -83,6 +103,16 @@ interface MetricsService {
|
|||
class Metrics(private val services: List<MetricsService>, private val isTelemetryEnabled: () -> Boolean) {
|
||||
private var initialized = false
|
||||
|
||||
init {
|
||||
Facts.registerProcessor(object : FactProcessor {
|
||||
override fun process(fact: Fact) {
|
||||
fact.toEvent()?.also {
|
||||
track(it)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun start() {
|
||||
if (BuildConfig.TELEMETRY && !isTelemetryEnabled.invoke() || initialized) { return }
|
||||
|
||||
|
|
Loading…
Reference in New Issue