From 5fc1e9227f7f3de8e2e0eb86446c479bf8b924f9 Mon Sep 17 00:00:00 2001 From: Sawyer Blatz Date: Fri, 5 Apr 2019 15:08:55 -0700 Subject: [PATCH] Closes #1195: Adds telemetry for quick action sheet (#1362) --- CHANGELOG.md | 1 + app/metrics.yaml | 68 +++++++++++++++++++ .../mozilla/fenix/browser/BrowserFragment.kt | 11 +++ .../components/metrics/GleanMetricsService.kt | 19 ++++++ .../fenix/components/metrics/Metrics.kt | 12 +++- .../quickactionsheet/QuickActionComponent.kt | 2 + .../quickactionsheet/QuickActionSheet.kt | 19 ------ .../quickactionsheet/QuickActionUIView.kt | 37 ++++++++++ 8 files changed, 147 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 205b8d355..c2f2b5d43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,5 +13,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - #1036 - Adds telemetry for Find in Page - #1049 - Add style for progress bar with gradient drawable - #1165 - Added doorhanger to the toolbar +- #1195 - Adds telemetry for quick action sheet ### Changed ### Removed \ No newline at end of file diff --git a/app/metrics.yaml b/app/metrics.yaml index 2d260371f..09af56de0 100644 --- a/app/metrics.yaml +++ b/app/metrics.yaml @@ -223,6 +223,74 @@ find_in_page: - telemetry-client-dev@mozilla.com expires: "2020-03-01" +quick_action_sheet: + opened: + type: event + description: > + A user opened the quick action sheet UI + bugs: + - 1195 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/1362#issuecomment-479668466 + notification_emails: + - telemetry-client-dev@mozilla.com + expires: "2020-03-01" + closed: + type: event + description: > + A user closed the quick action sheet UI + bugs: + - 1195 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/1362#issuecomment-479668466 + notification_emails: + - telemetry-client-dev@mozilla.com + expires: "2020-03-01" + share_tapped: + type: event + description: > + A user tapped the share button + bugs: + - 1195 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/1362#issuecomment-479668466 + notification_emails: + - telemetry-client-dev@mozilla.com + expires: "2020-03-01" + bookmark_tapped: + type: event + description: > + A user tapped the bookmark button + bugs: + - 1195 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/1362#issuecomment-479668466 + notification_emails: + - telemetry-client-dev@mozilla.com + expires: "2020-03-01" + download_tapped: + type: event + description: > + A user tapped the download button + bugs: + - 1195 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/1362#issuecomment-479668466 + notification_emails: + - telemetry-client-dev@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: + - telemetry-client-dev@mozilla.com + expires: "2020-03-01" + metrics: default_browser: type: boolean diff --git a/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt b/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt index cb692b50c..da0f2ed62 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt @@ -274,6 +274,7 @@ class BrowserFragment : Fragment(), BackHandler { (activity as AppCompatActivity).supportActionBar?.hide() } + @Suppress("ComplexMethod") override fun onStart() { super.onStart() getAutoDisposeObservable() @@ -302,14 +303,23 @@ class BrowserFragment : Fragment(), BackHandler { getAutoDisposeObservable() .subscribe { when (it) { + is QuickActionAction.Opened -> { + requireComponents.analytics.metrics.track(Event.QuickActionSheetOpened) + } + is QuickActionAction.Closed -> { + requireComponents.analytics.metrics.track(Event.QuickActionSheetClosed) + } is QuickActionAction.SharePressed -> { + requireComponents.analytics.metrics.track(Event.QuickActionSheetShareTapped) requireComponents.core.sessionManager .selectedSession?.url?.apply { requireContext().share(this) } } is QuickActionAction.DownloadsPressed -> { + requireComponents.analytics.metrics.track(Event.QuickActionSheetDownloadTapped) ItsNotBrokenSnack(context!!).showSnackbar(issueNumber = "348") } is QuickActionAction.BookmarkPressed -> { + requireComponents.analytics.metrics.track(Event.QuickActionSheetBookmarkTapped) val session = requireComponents.core.sessionManager.selectedSession CoroutineScope(IO).launch { requireComponents.core.bookmarksStorage @@ -334,6 +344,7 @@ class BrowserFragment : Fragment(), BackHandler { } } is QuickActionAction.ReadPressed -> { + requireComponents.analytics.metrics.track(Event.QuickActionSheetReadTapped) ItsNotBrokenSnack(context!!).showSnackbar(issueNumber = "908") } } 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 7f87246ae..6e9270c14 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 @@ -12,6 +12,7 @@ import org.mozilla.fenix.GleanMetrics.CrashReporter import org.mozilla.fenix.GleanMetrics.Events import org.mozilla.fenix.GleanMetrics.FindInPage import org.mozilla.fenix.GleanMetrics.ContextMenu +import org.mozilla.fenix.GleanMetrics.QuickActionSheet import org.mozilla.fenix.GleanMetrics.Metrics import org.mozilla.fenix.utils.Settings @@ -84,6 +85,24 @@ private val Event.wrapper { Events.browserMenuAction }, { Events.browserMenuActionKeys.valueOf(it) } ) + is Event.QuickActionSheetOpened -> EventWrapper( + { QuickActionSheet.opened.record(it) } + ) + is Event.QuickActionSheetClosed -> EventWrapper( + { QuickActionSheet.closed.record(it) } + ) + is Event.QuickActionSheetShareTapped -> EventWrapper( + { QuickActionSheet.shareTapped.record(it) } + ) + is Event.QuickActionSheetBookmarkTapped -> EventWrapper( + { QuickActionSheet.bookmarkTapped.record(it) } + ) + is Event.QuickActionSheetDownloadTapped -> EventWrapper( + { QuickActionSheet.downloadTapped.record(it) } + ) + is Event.QuickActionSheetReadTapped -> EventWrapper( + { QuickActionSheet.readTapped.record(it) } + ) // Don't track other events with Glean else -> null 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 b0e1f52e0..75b50652c 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 @@ -10,9 +10,6 @@ import mozilla.components.support.base.facts.Facts import org.mozilla.fenix.BuildConfig sealed class Event { - object AddBookmark : Event() - object RemoveBookmark : Event() - object OpenedBookmark : Event() data class OpenedApp(val source: Source) : Event() { enum class Source { APP_ICON, LINK, CUSTOM_TAB } @@ -49,6 +46,15 @@ sealed class Event { object DarkModeEnabled : Event() object SearchShortcutMenuOpened : Event() object SearchShortcutMenuClosed : Event() + object AddBookmark : Event() + object RemoveBookmark : Event() + object OpenedBookmark : Event() + object QuickActionSheetOpened : Event() + object QuickActionSheetClosed : Event() + object QuickActionSheetShareTapped : Event() + object QuickActionSheetBookmarkTapped : Event() + object QuickActionSheetDownloadTapped : Event() + object QuickActionSheetReadTapped : Event() // Interaction Events data class SearchBarTapped(val source: Source) : Event() { diff --git a/app/src/main/java/org/mozilla/fenix/quickactionsheet/QuickActionComponent.kt b/app/src/main/java/org/mozilla/fenix/quickactionsheet/QuickActionComponent.kt index e489f86fa..bb354a9da 100644 --- a/app/src/main/java/org/mozilla/fenix/quickactionsheet/QuickActionComponent.kt +++ b/app/src/main/java/org/mozilla/fenix/quickactionsheet/QuickActionComponent.kt @@ -41,6 +41,8 @@ class QuickActionComponent( data class QuickActionState(val readable: Boolean) : ViewState sealed class QuickActionAction : Action { + object Opened : QuickActionAction() + object Closed : QuickActionAction() object SharePressed : QuickActionAction() object DownloadsPressed : QuickActionAction() object BookmarkPressed : QuickActionAction() diff --git a/app/src/main/java/org/mozilla/fenix/quickactionsheet/QuickActionSheet.kt b/app/src/main/java/org/mozilla/fenix/quickactionsheet/QuickActionSheet.kt index 11e5aa100..5af750e69 100644 --- a/app/src/main/java/org/mozilla/fenix/quickactionsheet/QuickActionSheet.kt +++ b/app/src/main/java/org/mozilla/fenix/quickactionsheet/QuickActionSheet.kt @@ -48,17 +48,6 @@ class QuickActionSheet @JvmOverloads constructor( handle.setAccessibilityDelegate(HandleAccessibilityDelegate(quickActionSheetBehavior)) - quickActionSheetBehavior.setBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() { - override fun onStateChanged(v: View, state: Int) { - updateImportantForAccessibility(state) - } - - override fun onSlide(p0: View, p1: Float) { - } - }) - - updateImportantForAccessibility(quickActionSheetBehavior.state) - val settings = Settings.getInstance(context) if (settings.shouldAutoBounceQuickActionSheet) { settings.incrementAutomaticBounceQuickActionSheetCount() @@ -66,14 +55,6 @@ class QuickActionSheet @JvmOverloads constructor( } } - private fun updateImportantForAccessibility(state: Int) { - findViewById(R.id.quick_action_buttons_layout).importantForAccessibility = - if (state == BottomSheetBehavior.STATE_COLLAPSED || state == BottomSheetBehavior.STATE_HIDDEN) - View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS - else - View.IMPORTANT_FOR_ACCESSIBILITY_AUTO - } - private fun bounceSheet( quickActionSheetBehavior: QuickActionSheetBehavior, duration: Long = bounceAnimationLength diff --git a/app/src/main/java/org/mozilla/fenix/quickactionsheet/QuickActionUIView.kt b/app/src/main/java/org/mozilla/fenix/quickactionsheet/QuickActionUIView.kt index 267bf9ec2..7a7d26a33 100644 --- a/app/src/main/java/org/mozilla/fenix/quickactionsheet/QuickActionUIView.kt +++ b/app/src/main/java/org/mozilla/fenix/quickactionsheet/QuickActionUIView.kt @@ -7,6 +7,7 @@ package org.mozilla.fenix.quickactionsheet import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.LinearLayout import androidx.core.widget.NestedScrollView import com.google.android.material.bottomsheet.BottomSheetBehavior import io.reactivex.Observable @@ -15,6 +16,8 @@ import io.reactivex.functions.Consumer import kotlinx.android.synthetic.main.fragment_browser.* import kotlinx.android.synthetic.main.layout_quick_action_sheet.view.* import org.mozilla.fenix.R +import org.mozilla.fenix.components.metrics.Event +import org.mozilla.fenix.ext.components import org.mozilla.fenix.mvi.UIView class QuickActionUIView( @@ -31,6 +34,23 @@ class QuickActionUIView( val quickActionSheetBehavior = BottomSheetBehavior.from(nestedScrollQuickAction as View) as QuickActionSheetBehavior + quickActionSheetBehavior.setBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() { + override fun onStateChanged(v: View, state: Int) { + updateImportantForAccessibility(state) + + if (state == BottomSheetBehavior.STATE_EXPANDED) { + actionEmitter.onNext(QuickActionAction.Opened) + } else if (state == BottomSheetBehavior.STATE_COLLAPSED) { + actionEmitter.onNext(QuickActionAction.Closed) + } + } + + override fun onSlide(p0: View, p1: Float) { + } + }) + + updateImportantForAccessibility(quickActionSheetBehavior.state) + view.quick_action_share.setOnClickListener { actionEmitter.onNext(QuickActionAction.SharePressed) quickActionSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED @@ -49,6 +69,23 @@ class QuickActionUIView( } } + private fun updateImportantForAccessibility(state: Int) { + view.findViewById(R.id.quick_action_buttons_layout).importantForAccessibility = + if (state == BottomSheetBehavior.STATE_COLLAPSED || state == BottomSheetBehavior.STATE_HIDDEN) + View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS + else + View.IMPORTANT_FOR_ACCESSIBILITY_AUTO + } + + private fun sendTelemetryEvent(state: Int) { + when (state) { + BottomSheetBehavior.STATE_EXPANDED -> + view.context.components.analytics.metrics.track(Event.QuickActionSheetOpened) + BottomSheetBehavior.STATE_COLLAPSED -> + view.context.components.analytics.metrics.track(Event.QuickActionSheetClosed) + } + } + override fun updateView() = Consumer { view.quick_action_read.visibility = if (it.readable) View.VISIBLE else View.GONE }