Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
Closes #17089: Add metric to track both normal and private URI opened
Browse files Browse the repository at this point in the history
  • Loading branch information
rocketsroger committed Feb 9, 2021
1 parent a98b408 commit 68929a2
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 3 deletions.
19 changes: 19 additions & 0 deletions app/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
10 changes: 7 additions & 3 deletions app/src/main/java/org/mozilla/fenix/TelemetryMiddleware.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class TelemetryMiddleware(
}
}

@Suppress("TooGenericExceptionCaught", "ComplexMethod")
@Suppress("TooGenericExceptionCaught", "ComplexMethod", "NestedBlockDepth")
override fun invoke(
context: MiddlewareContext<BrowserState, BrowserAction>,
next: (BrowserAction) -> Unit,
Expand All @@ -60,8 +60,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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ private val Event.wrapper: EventWrapper<*>?
is Event.UriOpened -> EventWrapper<NoExtraKeys>(
{ Events.totalUriCount.add(1) }
)
is Event.NormalAndPrivateUriOpened -> EventWrapper<NoExtraKeys>(
{ Events.normalAndPrivateUriCount.add(1) }
)
is Event.ErrorPageVisited -> EventWrapper(
{ ErrorPage.visitedError.record(it) },
{ ErrorPage.visitedErrorKeys.valueOf(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,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
Expand All @@ -169,9 +171,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
Expand Down
1 change: 1 addition & 0 deletions docs/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ The following metrics are added to the ping:
| browser.search.ad_clicks |[labeled_counter](https://mozilla.github.io/glean/book/user/metrics/labeled_counters.html) |Records clicks of adverts on SERP pages. The key format is ‘<provider-name>’. |[1](https://github.com/mozilla-mobile/fenix/pull/10112), [2](https://github.com/mozilla-mobile/fenix/pull/15713#issuecomment-703972068)||2021-08-01 |2 |
| browser.search.in_content |[labeled_counter](https://mozilla.github.io/glean/book/user/metrics/labeled_counters.html) |Records the type of interaction a user has on SERP pages. |[1](https://github.com/mozilla-mobile/fenix/pull/10167), [2](https://github.com/mozilla-mobile/fenix/pull/15713#issuecomment-703972068)||2021-08-01 |2 |
| browser.search.with_ads |[labeled_counter](https://mozilla.github.io/glean/book/user/metrics/labeled_counters.html) |Records counts of SERP pages with adverts displayed. The key format is ‘<provider-name>’. |[1](https://github.com/mozilla-mobile/fenix/pull/10112), [2](https://github.com/mozilla-mobile/fenix/pull/15713#issuecomment-703972068)||2021-08-01 |2 |
| 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/issues/17089)||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 |
Expand Down

0 comments on commit 68929a2

Please sign in to comment.