1
0
Fork 0

For #4456: Adds total_uri_count to metrics core ping (#6003)

master
Sawyer Blatz 2019-10-30 11:02:33 -07:00 committed by liuche
parent fd22c43f9d
commit 8549b80272
8 changed files with 36 additions and 3 deletions

View File

@ -426,6 +426,20 @@ metrics:
notification_emails:
- fenix-core@mozilla.com
expires: "2020-03-01"
total_uri_count:
type: string
lifetime: application
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:
- https://github.com/mozilla-mobile/fenix/issue/4456
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/TODO
notification_emails:
- fenix-core@mozilla.com
expires: "2020-03-01"
search.default_engine:

View File

@ -64,6 +64,8 @@ open class FenixApplication : Application() {
registerRxExceptionHandling()
enableStrictMode()
applicationContext.settings().totalUriCount = 0
if (!isMainProcess()) {
// If this is not the main process then do not continue with the initialization here. Everything that
// follows only needs to be done in our app's main process and should not be done in other processes like

View File

@ -4,6 +4,7 @@
package org.mozilla.fenix.browser
import android.content.Context
import androidx.annotation.VisibleForTesting
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.LifecycleOwner
@ -13,14 +14,17 @@ import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.metrics.MetricController
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.metrics
import org.mozilla.fenix.ext.settings
class UriOpenedObserver(
private val context: Context,
private val owner: LifecycleOwner,
private val sessionManager: SessionManager,
private val metrics: MetricController
) : SessionManager.Observer {
constructor(activity: FragmentActivity) : this(
activity,
activity,
activity.components.core.sessionManager,
activity.metrics
@ -58,6 +62,7 @@ class UriOpenedObserver(
} else if (urlLoading != null && !session.private && temporaryFix.shouldSendEvent(session.url)) {
temporaryFix.eventSentFor = session.url
metrics.track(Event.UriOpened)
context.settings().totalUriCount += 1
}
}
}

View File

@ -470,6 +470,7 @@ class GleanMetricsService(private val context: Context) : MetricsService {
}
mozillaProducts.set(MozillaProductDetector.getInstalledMozillaProducts(context))
adjustCampaign.set(context.settings().adjustCampaignId)
totalUriCount.set(context.settings().totalUriCount.toString())
}
SearchDefaultEngine.apply {

View File

@ -312,6 +312,11 @@ class Settings private constructor(
default = 0
)
var totalUriCount by longPreference(
appContext.getPreferenceKey(R.string.pref_key_total_uri),
default = 0
)
fun addSearchWidgetInstalled(count: Int) {
val key = appContext.getPreferenceKey(R.string.pref_key_search_widget_installed)
val newValue = preferences.getInt(key, 0) + count

View File

@ -113,4 +113,6 @@
<string name="pref_key_reader_mode_notification" translatable="false">pref_key_reader_mode_notification</string>
<string name="pref_key_adjust_campaign" translatable="false">pref_key_adjust_campaign</string>
<string name="pref_key_testing_stage" translatable="false">pref_key_testing_stage</string>
<string name="pref_key_total_uri" translatable="false">pref_key_total_uri</string>
</resources>

View File

@ -4,6 +4,7 @@
package org.mozilla.fenix.browser
import android.content.Context
import androidx.lifecycle.LifecycleOwner
import io.mockk.every
import io.mockk.mockk
@ -17,12 +18,14 @@ import org.mozilla.fenix.components.metrics.MetricController
class UriOpenedObserverTest {
private lateinit var context: Context
private lateinit var owner: LifecycleOwner
private lateinit var sessionManager: SessionManager
private lateinit var metrics: MetricController
@Before
fun setup() {
context = mockk(relaxed = true)
owner = mockk(relaxed = true)
sessionManager = mockk(relaxed = true)
metrics = mockk(relaxed = true)
@ -30,13 +33,13 @@ class UriOpenedObserverTest {
@Test
fun `registers self as observer`() {
val observer = UriOpenedObserver(owner, sessionManager, metrics)
val observer = UriOpenedObserver(context, owner, sessionManager, metrics)
verify { sessionManager.register(observer, owner) }
}
@Test
fun `registers single session observer`() {
val observer = UriOpenedObserver(owner, sessionManager, metrics)
val observer = UriOpenedObserver(context, owner, sessionManager, metrics)
val session: Session = mockk(relaxed = true)
observer.onSessionAdded(session)
@ -48,7 +51,7 @@ class UriOpenedObserverTest {
@Test
fun `tracks that a url was loaded`() {
val observer = UriOpenedObserver(owner, sessionManager, metrics).singleSessionObserver
val observer = UriOpenedObserver(context, owner, sessionManager, metrics).singleSessionObserver
val session: Session = mockk(relaxed = true)
every { session.url } returns "https://mozilla.com"

File diff suppressed because one or more lines are too long