1
0
Fork 0

For #1036 - Maps facts to events

master
Jeff Boek 2019-04-02 16:29:26 -07:00 committed by Colin Lee
parent c284b0e22e
commit c678b5d7c5
2 changed files with 34 additions and 1 deletions

View File

@ -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)

View File

@ -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 }