From 64f32b9d95d72f70f9d63b234009060e61c0792e Mon Sep 17 00:00:00 2001 From: Roger Yang Date: Fri, 19 Feb 2021 10:37:07 -0500 Subject: [PATCH] Closes #17089: Add metric to track both normal and private URI opened (#17935) --- app/metrics.yaml | 19 +++++++++++++++++++ .../org/mozilla/fenix/TelemetryMiddleware.kt | 10 +++++++--- .../mozilla/fenix/components/metrics/Event.kt | 1 + .../components/metrics/GleanMetricsService.kt | 3 +++ .../mozilla/fenix/TelemetryMiddlewareTest.kt | 4 ++++ docs/metrics.md | 1 + 6 files changed, 35 insertions(+), 3 deletions(-) diff --git a/app/metrics.yaml b/app/metrics.yaml index 82175a8f7..7aed730d5 100644 --- a/app/metrics.yaml +++ b/app/metrics.yaml @@ -234,6 +234,25 @@ events: notification_emails: - fenix-core@mozilla.com expires: "2021-08-01" + normal_and_private_uri_count: + type: counter + description: | + A counter of URIs visited by the user in the current session, including + page reloads. This includes private browsing. This does not include + background page requests and URIs from embedded pages but may be + incremented without user interaction by website scripts that + programmatically redirect to a new location. + send_in_pings: + - metrics + bugs: + - https://github.com/mozilla-mobile/fenix/issues/17089 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/17935 + data_sensitivity: + - interaction + notification_emails: + - fenix-core@mozilla.com + expires: "2022-08-01" preference_toggled: type: event description: | diff --git a/app/src/main/java/org/mozilla/fenix/TelemetryMiddleware.kt b/app/src/main/java/org/mozilla/fenix/TelemetryMiddleware.kt index f16cae272..53a55bdfd 100644 --- a/app/src/main/java/org/mozilla/fenix/TelemetryMiddleware.kt +++ b/app/src/main/java/org/mozilla/fenix/TelemetryMiddleware.kt @@ -55,7 +55,7 @@ class TelemetryMiddleware( } } - @Suppress("TooGenericExceptionCaught", "ComplexMethod") + @Suppress("TooGenericExceptionCaught", "ComplexMethod", "NestedBlockDepth") override fun invoke( context: MiddlewareContext, next: (BrowserAction) -> Unit, @@ -66,8 +66,12 @@ class TelemetryMiddleware( is ContentAction.UpdateLoadingStateAction -> { context.state.findTab(action.sessionId)?.let { tab -> // Record UriOpened event when a non-private page finishes loading - if (tab.content.loading && !action.loading && !tab.content.private) { - metrics.track(Event.UriOpened) + if (tab.content.loading && !action.loading) { + if (!tab.content.private) { + metrics.track(Event.UriOpened) + } + + metrics.track(Event.NormalAndPrivateUriOpened) } } } diff --git a/app/src/main/java/org/mozilla/fenix/components/metrics/Event.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/Event.kt index 974e6b83a..c7e2431ea 100644 --- a/app/src/main/java/org/mozilla/fenix/components/metrics/Event.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/Event.kt @@ -52,6 +52,7 @@ sealed class Event { object CustomTabsActionTapped : Event() object CustomTabsMenuOpened : Event() object UriOpened : Event() + object NormalAndPrivateUriOpened : Event() object SyncAuthOpened : Event() object SyncAuthClosed : Event() object SyncAuthSignUp : Event() diff --git a/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt index 404ae9aff..d122d34a7 100644 --- a/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt @@ -237,6 +237,9 @@ private val Event.wrapper: EventWrapper<*>? is Event.UriOpened -> EventWrapper( { Events.totalUriCount.add(1) } ) + is Event.NormalAndPrivateUriOpened -> EventWrapper( + { Events.normalAndPrivateUriCount.add(1) } + ) is Event.ErrorPageVisited -> EventWrapper( { ErrorPage.visitedError.record(it) }, { ErrorPage.visitedErrorKeys.valueOf(it) } diff --git a/app/src/test/java/org/mozilla/fenix/TelemetryMiddlewareTest.kt b/app/src/test/java/org/mozilla/fenix/TelemetryMiddlewareTest.kt index 35c5421ea..3f086f68f 100644 --- a/app/src/test/java/org/mozilla/fenix/TelemetryMiddlewareTest.kt +++ b/app/src/test/java/org/mozilla/fenix/TelemetryMiddlewareTest.kt @@ -182,9 +182,11 @@ class TelemetryMiddlewareTest { store.dispatch(TabListAction.AddTabAction(tab)).joinBlocking() store.dispatch(ContentAction.UpdateLoadingStateAction(tab.id, true)).joinBlocking() verify(exactly = 0) { metrics.track(Event.UriOpened) } + verify(exactly = 0) { metrics.track(Event.NormalAndPrivateUriOpened) } store.dispatch(ContentAction.UpdateLoadingStateAction(tab.id, false)).joinBlocking() verify(exactly = 1) { metrics.track(Event.UriOpened) } + verify(exactly = 1) { metrics.track(Event.NormalAndPrivateUriOpened) } } @Test @@ -193,9 +195,11 @@ class TelemetryMiddlewareTest { store.dispatch(TabListAction.AddTabAction(tab)).joinBlocking() store.dispatch(ContentAction.UpdateLoadingStateAction(tab.id, true)).joinBlocking() verify(exactly = 0) { metrics.track(Event.UriOpened) } + verify(exactly = 0) { metrics.track(Event.NormalAndPrivateUriOpened) } store.dispatch(ContentAction.UpdateLoadingStateAction(tab.id, false)).joinBlocking() verify(exactly = 0) { metrics.track(Event.UriOpened) } + verify(exactly = 1) { metrics.track(Event.NormalAndPrivateUriOpened) } } @Test diff --git a/docs/metrics.md b/docs/metrics.md index 463f8fa6c..413204af1 100644 --- a/docs/metrics.md +++ b/docs/metrics.md @@ -283,6 +283,7 @@ The following metrics are added to the ping: | engine.kill_background_age |[timespan](https://mozilla.github.io/glean/book/user/metrics/timespan.html) |Measures the age of the engine session of a background tab at the time its content process got killed. |[1](https://github.com/mozilla-mobile/fenix/pull/17864)||2021-12-31 |1 | | engine.kill_foreground_age |[timespan](https://mozilla.github.io/glean/book/user/metrics/timespan.html) |Measures the age of the engine session of a foreground (selected) tab at the time its content process got killed. |[1](TBD)||2021-12-31 |1 | | engine.tab_kills |[labeled_counter](https://mozilla.github.io/glean/book/user/metrics/labeled_counters.html) |How often was the content process of a foreground (selected) or background tab killed. |[1](https://github.com/mozilla-mobile/fenix/pull/17864)|
  • foreground
  • background
|2021-12-31 |1 | +| events.normal_and_private_uri_count |[counter](https://mozilla.github.io/glean/book/user/metrics/counter.html) |A counter of URIs visited by the user in the current session, including page reloads. This includes private browsing. This does not include background page requests and URIs from embedded pages but may be incremented without user interaction by website scripts that programmatically redirect to a new location. |[1](https://github.com/mozilla-mobile/fenix/pull/17935)||2022-08-01 |2 | | events.total_uri_count |[counter](https://mozilla.github.io/glean/book/user/metrics/counter.html) |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 but may be incremented without user interaction by website scripts that programmatically redirect to a new location. |[1](https://github.com/mozilla-mobile/fenix/pull/1785), [2](https://github.com/mozilla-mobile/fenix/pull/8314), [3](https://github.com/mozilla-mobile/fenix/pull/15713#issuecomment-703972068)||2021-08-01 |2 | | metrics.adjust_ad_group |[string](https://mozilla.github.io/glean/book/user/metrics/string.html) |A string containing the Adjust ad group ID from which the user installed Fenix. This will not send on the first session the user runs. If the install is organic, this will be empty. |[1](https://github.com/mozilla-mobile/fenix/pull/9253), [2](https://github.com/mozilla-mobile/fenix/pull/15713#issuecomment-703972068)||2021-08-01 |2 | | metrics.adjust_campaign |[string](https://mozilla.github.io/glean/book/user/metrics/string.html) |A string containing the Adjust campaign ID from which the user installed Fenix. This will not send on the first session the user runs. If the install is organic, this will be empty. |[1](https://github.com/mozilla-mobile/fenix/pull/5579), [2](https://github.com/mozilla-mobile/fenix/pull/15713#issuecomment-703972068)||2021-08-01 |1 |