From d5b33aec439e1bf2f0b107fedc4f04fa6fdeea21 Mon Sep 17 00:00:00 2001 From: Mugurell Date: Tue, 15 Dec 2020 08:39:22 +0200 Subject: [PATCH] For #11578 - Add telemetry for how many times we download something (#16730) --- app/metrics.yaml | 15 +++++++++++++++ .../java/org/mozilla/fenix/TelemetryMiddleware.kt | 6 +++++- .../org/mozilla/fenix/components/metrics/Event.kt | 1 + .../components/metrics/GleanMetricsService.kt | 4 ++++ .../org/mozilla/fenix/TelemetryMiddlewareTest.kt | 9 +++++++++ docs/metrics.md | 1 + 6 files changed, 35 insertions(+), 1 deletion(-) diff --git a/app/metrics.yaml b/app/metrics.yaml index 8bdbdc044e88..da7069b0bee4 100644 --- a/app/metrics.yaml +++ b/app/metrics.yaml @@ -3109,6 +3109,21 @@ download_notification: - fenix-core@mozilla.com expires: "2021-04-01" +downloads_misc: + download_added: + type: event + description: + A counter for how many times something is downloaded in the app. + send_in_pings: + - metrics + bugs: + - https://github.com/mozilla-mobile/fenix/issues/11578 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/16730 + notification_emails: + - fenix-core@mozilla.com + expires: "2021-04-01" + user_specified_search_engines: custom_engine_added: type: event diff --git a/app/src/main/java/org/mozilla/fenix/TelemetryMiddleware.kt b/app/src/main/java/org/mozilla/fenix/TelemetryMiddleware.kt index 88904292f781..c5c64df0a906 100644 --- a/app/src/main/java/org/mozilla/fenix/TelemetryMiddleware.kt +++ b/app/src/main/java/org/mozilla/fenix/TelemetryMiddleware.kt @@ -7,6 +7,7 @@ package org.mozilla.fenix import androidx.annotation.VisibleForTesting import mozilla.components.browser.state.action.BrowserAction import mozilla.components.browser.state.action.ContentAction +import mozilla.components.browser.state.action.DownloadAction import mozilla.components.browser.state.action.TabListAction import mozilla.components.browser.state.selector.findTab import mozilla.components.browser.state.selector.normalTabs @@ -48,7 +49,7 @@ class TelemetryMiddleware( } } - @Suppress("TooGenericExceptionCaught") + @Suppress("TooGenericExceptionCaught", "ComplexMethod") override fun invoke( context: MiddlewareContext, next: (BrowserAction) -> Unit, @@ -86,6 +87,9 @@ class TelemetryMiddleware( } } } + is DownloadAction.AddDownloadAction -> { + metrics.track(Event.DownloadAdded) + } } next(action) 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 87d10a519ac6..5b13db5f12ba 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 @@ -113,6 +113,7 @@ sealed class Event { object NotificationDownloadPause : Event() object NotificationDownloadResume : Event() object NotificationDownloadTryAgain : Event() + object DownloadAdded : Event() object NotificationMediaPlay : Event() object NotificationMediaPause : Event() object TopSiteOpenDefault : 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 2e84ba7ec28e..78eece3269fd 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 @@ -25,6 +25,7 @@ import org.mozilla.fenix.GleanMetrics.ContextualHintTrackingProtection import org.mozilla.fenix.GleanMetrics.CrashReporter import org.mozilla.fenix.GleanMetrics.CustomTab import org.mozilla.fenix.GleanMetrics.DownloadNotification +import org.mozilla.fenix.GleanMetrics.DownloadsMisc import org.mozilla.fenix.GleanMetrics.ErrorPage import org.mozilla.fenix.GleanMetrics.Events import org.mozilla.fenix.GleanMetrics.FindInPage @@ -423,6 +424,9 @@ private val Event.wrapper: EventWrapper<*>? is Event.NotificationDownloadTryAgain -> EventWrapper( { DownloadNotification.tryAgain.record(it) } ) + is Event.DownloadAdded -> EventWrapper( + { DownloadsMisc.downloadAdded.record(it) } + ) is Event.NotificationMediaPlay -> EventWrapper( { MediaNotification.play.record(it) } ) diff --git a/app/src/test/java/org/mozilla/fenix/TelemetryMiddlewareTest.kt b/app/src/test/java/org/mozilla/fenix/TelemetryMiddlewareTest.kt index 10fe132097c0..37fb3c1affd7 100644 --- a/app/src/test/java/org/mozilla/fenix/TelemetryMiddlewareTest.kt +++ b/app/src/test/java/org/mozilla/fenix/TelemetryMiddlewareTest.kt @@ -7,11 +7,13 @@ package org.mozilla.fenix import io.mockk.mockk import io.mockk.verify import mozilla.components.browser.state.action.ContentAction +import mozilla.components.browser.state.action.DownloadAction import mozilla.components.browser.state.action.TabListAction import mozilla.components.browser.state.state.LoadRequestState import mozilla.components.browser.state.state.createTab import mozilla.components.browser.state.store.BrowserStore import mozilla.components.support.test.ext.joinBlocking +import mozilla.components.support.test.mock import mozilla.components.support.test.robolectric.testContext import org.junit.Assert.assertEquals import org.junit.Assert.assertNotNull @@ -216,4 +218,11 @@ class TelemetryMiddlewareTest { store.dispatch(ContentAction.UpdateUrlAction(tab.id, "https://mozilla.org")).joinBlocking() assertNull(telemetryMiddleware.redirectChains[tab.id]) } + + @Test + fun `WHEN a download is added THEN the downloads count is updated`() { + store.dispatch(DownloadAction.AddDownloadAction(mock())).joinBlocking() + + verify { metrics.track(Event.DownloadAdded) } + } } diff --git a/docs/metrics.md b/docs/metrics.md index 32a2c7b917ca..ba1adfcd97f9 100644 --- a/docs/metrics.md +++ b/docs/metrics.md @@ -261,6 +261,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 ‘’. |[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 ‘’. |[1](https://github.com/mozilla-mobile/fenix/pull/10112), [2](https://github.com/mozilla-mobile/fenix/pull/15713#issuecomment-703972068)||2021-08-01 |2 | +| downloads_misc.download_added |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A counter for how many times something is downloaded in the app. |[1](https://github.com/mozilla-mobile/fenix/pull/16730)||2021-04-01 | | | 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 |