From c334c77bbe309298ba7d47e2bc6518ad335254d3 Mon Sep 17 00:00:00 2001 From: Sawyer Blatz Date: Wed, 15 May 2019 14:26:21 -0700 Subject: [PATCH] For #976: Adds telemetry for library --- app/metrics.yaml | 38 +++++++++++++++++++ .../components/metrics/GleanMetricsService.kt | 11 ++++++ .../fenix/components/metrics/Metrics.kt | 7 ++++ .../mozilla/fenix/library/LibraryFragment.kt | 34 ++++++++++------- 4 files changed, 77 insertions(+), 13 deletions(-) diff --git a/app/metrics.yaml b/app/metrics.yaml index edba1e766..76ac476d5 100644 --- a/app/metrics.yaml +++ b/app/metrics.yaml @@ -679,4 +679,42 @@ qr_scanner: - https://github.com/mozilla-mobile/fenix/pull/2524#issuecomment-492739967 notification_emails: - fenix-core@mozilla.com + expires: "2020-03-01" + +library: + opened: + type: event + description: > + A user opened the library + bugs: + - 976 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/2538#issuecomment-492830242 + notification_emails: + - fenix-core@mozilla.com + expires: "2020-03-01" + closed: + type: event + description: > + A user closed the library + bugs: + - 976 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/2538#issuecomment-492830242 + notification_emails: + - fenix-core@mozilla.com + expires: "2020-03-01" + selected_item: + type: event + description: > + A user selected a library item + extra_keys: + item: + description: "The library item the user selected" + bugs: + - 976 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/2538#issuecomment-492830242 + notification_emails: + - fenix-core@mozilla.com expires: "2020-03-01" \ No newline at end of file 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 b54e550e8..7c21580db 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 @@ -24,6 +24,7 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.runBlocking import org.mozilla.fenix.GleanMetrics.QrScanner +import org.mozilla.fenix.GleanMetrics.Library private class EventWrapper>( private val recorder: ((Map?) -> Unit), @@ -172,6 +173,16 @@ private val Event.wrapper is Event.QRScannerNavigationDenied -> EventWrapper( { QrScanner.navigationDenied.record(it) } ) + is Event.LibraryOpened -> EventWrapper( + { Library.opened.record(it) } + ) + is Event.LibraryClosed -> EventWrapper( + { Library.closed.record(it) } + ) + is Event.LibrarySelectedItem -> EventWrapper( + { Library.selectedItem }, + { Library.selectedItemKeys.valueOf(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 3ab9d8d16..51f517233 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 @@ -78,6 +78,8 @@ sealed class Event { object QRScannerPromptDisplayed : Event() object QRScannerNavigationAllowed : Event() object QRScannerNavigationDenied : Event() + object LibraryOpened : Event() + object LibraryClosed : Event() data class PreferenceToggled(val preferenceKey: String, val enabled: Boolean, val context: Context) : Event() { private val switchPreferenceTelemetryAllowList = listOf( @@ -103,6 +105,11 @@ sealed class Event { } // Interaction Events + data class LibrarySelectedItem(val item: String) : Event() { + override val extras: Map? + get() = mapOf("source" to item) + } + data class SearchBarTapped(val source: Source) : Event() { enum class Source { HOME, BROWSER } override val extras: Map? diff --git a/app/src/main/java/org/mozilla/fenix/library/LibraryFragment.kt b/app/src/main/java/org/mozilla/fenix/library/LibraryFragment.kt index 75ad07f73..ea3283166 100644 --- a/app/src/main/java/org/mozilla/fenix/library/LibraryFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/library/LibraryFragment.kt @@ -20,8 +20,9 @@ import androidx.navigation.Navigation import kotlinx.android.synthetic.main.fragment_library.* import mozilla.appservices.places.BookmarkRoot import org.mozilla.fenix.R +import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.ext.getColorFromAttr -import org.mozilla.fenix.library.bookmarks.BookmarkFragmentArgs +import org.mozilla.fenix.ext.requireComponents class LibraryFragment : Fragment() { @@ -49,19 +50,21 @@ class LibraryFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - libraryHistory.setOnClickListener( - Navigation.createNavigateOnClickListener( - LibraryFragmentDirections.actionLibraryFragmentToHistoryFragment().actionId, - null - ) - ) + libraryHistory.setOnClickListener { + requireComponents.analytics.metrics + .track(Event.LibrarySelectedItem(view.context.getString(R.string.library_history))) + Navigation.findNavController(view) + .navigate(LibraryFragmentDirections.actionLibraryFragmentToHistoryFragment()) + } - libraryBookmarks.setOnClickListener( - Navigation.createNavigateOnClickListener( - LibraryFragmentDirections.actionLibraryFragmentToBookmarksFragment(BookmarkRoot.Mobile.id).actionId, - BookmarkFragmentArgs(BookmarkRoot.Mobile.id).toBundle() - ) - ) + libraryBookmarks.setOnClickListener { + requireComponents.analytics.metrics + .track(Event.LibrarySelectedItem(view.context.getString(R.string.library_bookmarks))) + Navigation.findNavController(view) + .navigate(LibraryFragmentDirections.actionLibraryFragmentToBookmarksFragment(BookmarkRoot.Mobile.id)) + } + + requireComponents.analytics.metrics.track(Event.LibraryOpened) } override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { @@ -78,6 +81,11 @@ class LibraryFragment : Fragment() { } } + override fun onDestroy() { + super.onDestroy() + requireComponents.analytics.metrics.track(Event.LibraryClosed) + } + private fun setToolbarColor() { val toolbar = (activity as AppCompatActivity).findViewById(R.id.navigationToolbar)