From 0b99b7fc126f0a67cb04393650822f19fc58f0df Mon Sep 17 00:00:00 2001 From: Sawyer Blatz Date: Fri, 5 Apr 2019 15:08:55 -0700 Subject: [PATCH] [fenix] Closes https://github.com/mozilla-mobile/fenix/issues/1195: Adds telemetry for quick action sheet (https://github.com/mozilla-mobile/fenix/pull/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 205b8d3556..c2f2b5d43c 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 2d260371f5..09af56de02 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 cb692b50c2..da0f2ed62b 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 7f87246ae1..6e9270c14f 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 b0e1f52e09..75b50652c9 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 e489f86fa0..bb354a9da6 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 11e5aa1006..5af750e697 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 267bf9ec29..7a7d26a334 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 }