mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-03 23:15:31 +00:00
[fenix] Merge pull request https://github.com/mozilla-mobile/fenix/pull/1785 from colintheshots/fix1301
For https://github.com/mozilla-mobile/fenix/issues/1301: Add uri_count to metrics ping
This commit is contained in:
parent
23b39e2bd1
commit
f91ab0b460
@ -123,6 +123,19 @@ events:
|
||||
notification_emails:
|
||||
- fenix-core@mozilla.com
|
||||
expires: "2020-03-01"
|
||||
total_uri_count:
|
||||
type: counter
|
||||
description: >
|
||||
A counter of URIs visited by the user in the current session, including page reloads. This does not include background page requests and URIs from embedded pages or private browsing.
|
||||
send_in_pings:
|
||||
- metrics
|
||||
bugs:
|
||||
- 1301
|
||||
data_reviews:
|
||||
- https://github.com/mozilla-mobile/fenix/pull/1785
|
||||
notification_emails:
|
||||
- fenix-core@mozilla.com
|
||||
expires: "2020-03-01"
|
||||
|
||||
crash_reporter:
|
||||
opened:
|
||||
|
@ -17,6 +17,7 @@ import androidx.navigation.ui.AppBarConfiguration
|
||||
import androidx.navigation.ui.NavigationUI
|
||||
import mozilla.components.browser.search.SearchEngine
|
||||
import mozilla.components.browser.session.Session
|
||||
import mozilla.components.browser.session.SessionManager
|
||||
import mozilla.components.concept.engine.EngineView
|
||||
import mozilla.components.feature.intent.IntentProcessor
|
||||
import mozilla.components.lib.crash.Crash
|
||||
@ -36,6 +37,7 @@ import org.mozilla.fenix.settings.SettingsFragmentDirections
|
||||
@SuppressWarnings("TooManyFunctions")
|
||||
open class HomeActivity : AppCompatActivity() {
|
||||
open val isCustomTab = false
|
||||
private var sessionObserver: SessionManager.Observer? = null
|
||||
|
||||
val themeManager = DefaultThemeManager().also {
|
||||
it.onThemeChange = { theme ->
|
||||
@ -85,6 +87,11 @@ open class HomeActivity : AppCompatActivity() {
|
||||
handleOpenedFromExternalSourceIfNecessary(intent)
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
sessionObserver?.let { components.core.sessionManager.unregister(it) }
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
override fun onNewIntent(intent: Intent?) {
|
||||
super.onNewIntent(intent)
|
||||
handleCrashIfNecessary(intent)
|
||||
@ -168,6 +175,8 @@ open class HomeActivity : AppCompatActivity() {
|
||||
BrowserDirection.FromHistory ->
|
||||
HistoryFragmentDirections.actionHistoryFragmentToBrowserFragment(externalSessionId)
|
||||
}
|
||||
if (sessionObserver == null)
|
||||
sessionObserver = subscribeToSessions()
|
||||
|
||||
navHost.navController.navigate(directions)
|
||||
}
|
||||
@ -197,6 +206,47 @@ open class HomeActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private val singleSessionObserver = object : Session.Observer {
|
||||
var urlLoading: String? = null
|
||||
|
||||
override fun onLoadingStateChanged(session: Session, loading: Boolean) {
|
||||
super.onLoadingStateChanged(session, loading)
|
||||
|
||||
if (loading) urlLoading = session.url
|
||||
else if (urlLoading != null && !session.private)
|
||||
components.analytics.metrics.track(Event.UriOpened)
|
||||
}
|
||||
}
|
||||
|
||||
private fun subscribeToSessions(): SessionManager.Observer {
|
||||
|
||||
return object : SessionManager.Observer {
|
||||
override fun onAllSessionsRemoved() {
|
||||
super.onAllSessionsRemoved()
|
||||
components.core.sessionManager.sessions.forEach {
|
||||
it.unregister(singleSessionObserver)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onSessionAdded(session: Session) {
|
||||
super.onSessionAdded(session)
|
||||
session.register(singleSessionObserver)
|
||||
}
|
||||
|
||||
override fun onSessionRemoved(session: Session) {
|
||||
super.onSessionRemoved(session)
|
||||
session.unregister(singleSessionObserver)
|
||||
}
|
||||
|
||||
override fun onSessionsRestored() {
|
||||
super.onSessionsRestored()
|
||||
components.core.sessionManager.sessions.forEach {
|
||||
it.register(singleSessionObserver)
|
||||
}
|
||||
}
|
||||
}.also { components.core.sessionManager.register(it) }
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val OPEN_TO_BROWSER = "open_to_browser"
|
||||
}
|
||||
|
@ -150,6 +150,9 @@ private val Event.wrapper
|
||||
is Event.CustomTabsClosed -> EventWrapper<NoExtraKeys>(
|
||||
{ CustomTab.closed.record(it) }
|
||||
)
|
||||
is Event.UriOpened -> EventWrapper<NoExtraKeys>(
|
||||
{ Events.totalUriCount.add(1) }
|
||||
)
|
||||
|
||||
// Don't track other events with Glean
|
||||
else -> null
|
||||
|
@ -70,6 +70,7 @@ sealed class Event {
|
||||
object CustomTabsClosed : Event()
|
||||
object CustomTabsActionTapped : Event()
|
||||
object CustomTabsMenuOpened : Event()
|
||||
object UriOpened : Event()
|
||||
|
||||
// Interaction Events
|
||||
data class SearchBarTapped(val source: Source) : Event() {
|
||||
|
Loading…
Reference in New Issue
Block a user