From 97f7d5ba87aac5c3944bad9d6e52d6b23a148e3d Mon Sep 17 00:00:00 2001 From: Sawyer Blatz Date: Wed, 31 Jul 2019 17:58:37 -0700 Subject: [PATCH] For #2267: Fixes telemetry for reader view (#4328) --- app/metrics.yaml | 22 +++++++++---------- .../components/metrics/GleanMetricsService.kt | 10 ++++++--- .../fenix/components/metrics/Metrics.kt | 2 +- .../components/toolbar/BrowserInteractor.kt | 6 +++-- .../toolbar/BrowserInteractorTest.kt | 17 +++++++++----- docs/metrics.md | 16 +++++++------- 6 files changed, 43 insertions(+), 30 deletions(-) diff --git a/app/metrics.yaml b/app/metrics.yaml index 7de5f49af79d..d5e900ce1d74 100644 --- a/app/metrics.yaml +++ b/app/metrics.yaml @@ -314,17 +314,6 @@ quick_action_sheet: notification_emails: - fenix-core@mozilla.com expires: "2020-03-01" - read_tapped: - type: event - description: > - A user tapped the read button - bugs: - - 1195 - data_reviews: - - https://github.com/mozilla-mobile/fenix/pull/1362#issuecomment-479668466 - notification_emails: - - fenix-core@mozilla.com - expires: "2020-03-01" metrics: default_browser: @@ -930,6 +919,17 @@ reader_mode: notification_emails: - fenix-core@mozilla.com expires: "2020-03-01" + closed: + type: event + description: > + A user closed reader mode + bugs: + - 2267 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/4328 + notification_emails: + - fenix-core@mozilla.com + expires: "2020-03-01" appearance: type: event description: > 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 e00e96ee6a42..107a11f63326 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 @@ -31,6 +31,7 @@ import org.mozilla.fenix.GleanMetrics.QuickActionSheet import org.mozilla.fenix.GleanMetrics.SearchDefaultEngine import org.mozilla.fenix.ext.components import org.mozilla.fenix.GleanMetrics.Collections +import org.mozilla.fenix.GleanMetrics.ReaderMode import org.mozilla.fenix.GleanMetrics.SyncAccount import org.mozilla.fenix.GleanMetrics.SyncAuth @@ -121,9 +122,6 @@ private val Event.wrapper is Event.QuickActionSheetDownloadTapped -> EventWrapper( { QuickActionSheet.downloadTapped.record(it) } ) - is Event.QuickActionSheetReadTapped -> EventWrapper( - { QuickActionSheet.readTapped.record(it) } - ) is Event.OpenedBookmarkInNewTab -> EventWrapper( { BookmarksManagement.openInNewTab.record(it) } ) @@ -265,6 +263,12 @@ private val Event.wrapper is Event.CollectionTabSelectOpened -> EventWrapper( { Collections.tabSelectOpened.record(it) } ) + is Event.ReaderModeOpened -> EventWrapper( + { ReaderMode.opened.record(it) } + ) + is Event.ReaderModeAppearanceOpened -> EventWrapper( + { ReaderMode.appearance.record(it) } + ) is Event.CollectionTabLongPressed -> EventWrapper( { Collections.longPress.record(it) } ) diff --git a/app/src/main/java/org/mozilla/fenix/components/metrics/Metrics.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/Metrics.kt index 50ffbbe08485..d255a9288d80 100644 --- a/app/src/main/java/org/mozilla/fenix/components/metrics/Metrics.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/Metrics.kt @@ -73,7 +73,6 @@ sealed class Event { object QuickActionSheetShareTapped : Event() object QuickActionSheetBookmarkTapped : Event() object QuickActionSheetDownloadTapped : Event() - object QuickActionSheetReadTapped : Event() object CustomTabsClosed : Event() object CustomTabsActionTapped : Event() object CustomTabsMenuOpened : Event() @@ -100,6 +99,7 @@ sealed class Event { object HistoryAllItemsRemoved : Event() object ReaderModeAvailable : Event() object ReaderModeOpened : Event() + object ReaderModeClosed : Event() object ReaderModeAppearanceOpened : Event() object CollectionRenamed : Event() object CollectionTabRestored : Event() diff --git a/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserInteractor.kt b/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserInteractor.kt index 3795704d3054..6ea427d4c2f3 100644 --- a/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserInteractor.kt +++ b/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserInteractor.kt @@ -50,11 +50,13 @@ class BrowserInteractor( } override fun onQuickActionSheetReadPressed() { - context.metrics.track(Event.QuickActionSheetReadTapped) val enabled = currentSession.readerMode + if (enabled) { + context.metrics.track(Event.QuickActionSheetClosed) readerModeController.hideReaderView() } else { + context.metrics.track(Event.QuickActionSheetOpened) readerModeController.showReaderView() } store.dispatch(QuickActionSheetAction.ReaderActiveStateChange(!enabled)) @@ -65,7 +67,7 @@ class BrowserInteractor( } override fun onQuickActionSheetAppearancePressed() { - // TODO telemetry: https://github.com/mozilla-mobile/fenix/issues/2267 + context.metrics.track(Event.ReaderModeAppearanceOpened) readerModeController.showControls() } } diff --git a/app/src/test/java/org/mozilla/fenix/components/toolbar/BrowserInteractorTest.kt b/app/src/test/java/org/mozilla/fenix/components/toolbar/BrowserInteractorTest.kt index 0f582e1ce3bd..34fa2b020961 100644 --- a/app/src/test/java/org/mozilla/fenix/components/toolbar/BrowserInteractorTest.kt +++ b/app/src/test/java/org/mozilla/fenix/components/toolbar/BrowserInteractorTest.kt @@ -181,11 +181,11 @@ class BrowserInteractorTest { every { context.metrics } returns metrics every { context.components.core.sessionManager.selectedSession } returns session every { session.readerMode } returns false - every { metrics.track(Event.QuickActionSheetReadTapped) } just Runs + every { metrics.track(Event.QuickActionSheetOpened) } just Runs interactor.onQuickActionSheetReadPressed() - verify { metrics.track(Event.QuickActionSheetReadTapped) } + verify { metrics.track(Event.QuickActionSheetOpened) } verify { readerModeController.showReaderView() } } @@ -209,11 +209,11 @@ class BrowserInteractorTest { every { context.metrics } returns metrics every { context.components.core.sessionManager.selectedSession } returns session every { session.readerMode } returns true - every { metrics.track(Event.QuickActionSheetReadTapped) } just Runs + every { metrics.track(Event.QuickActionSheetClosed) } just Runs interactor.onQuickActionSheetReadPressed() - verify { metrics.track(Event.QuickActionSheetReadTapped) } + verify { metrics.track(Event.QuickActionSheetClosed) } verify { readerModeController.hideReaderView() } } @@ -240,8 +240,12 @@ class BrowserInteractorTest { @Test fun onQuickActionSheetAppearancePressed() { val context: Context = mockk() + val metrics: MetricController = mockk() val readerModeController: ReaderModeController = mockk(relaxed = true) + every { context.metrics } returns metrics + every { metrics.track(Event.ReaderModeAppearanceOpened) } just Runs + val interactor = BrowserInteractor( context, mockk(), @@ -253,6 +257,9 @@ class BrowserInteractorTest { interactor.onQuickActionSheetAppearancePressed() - verify { readerModeController.showControls() } + verify { + metrics.track(Event.ReaderModeAppearanceOpened) + readerModeController.showControls() + } } } \ No newline at end of file diff --git a/docs/metrics.md b/docs/metrics.md index 4d834118614e..d3f6aca19e83 100644 --- a/docs/metrics.md +++ b/docs/metrics.md @@ -314,14 +314,6 @@ tracking_protection 2020-03-01 - - read_tapped - event - A user tapped the read button - link - - 2020-03-01 - @@ -789,6 +781,14 @@ tracking_protection 2020-03-01 + + opened + event + A user closed reader mode + link + + 2020-03-01 + appearance event