Skip to content

Commit

Permalink
For mozilla-mobile#1301: Add uri_count to ping
Browse files Browse the repository at this point in the history
  • Loading branch information
colintheshots committed Apr 25, 2019
1 parent 4ae40b3 commit c93009a
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
42 changes: 42 additions & 0 deletions app/src/main/java/org/mozilla/fenix/HomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -194,6 +195,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"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit c93009a

Please sign in to comment.