1
0
Fork 0

For #976: Adds telemetry for library

master
Sawyer Blatz 2019-05-15 14:26:21 -07:00 committed by Jeff Boek
parent ba790c5dd3
commit c334c77bbe
4 changed files with 77 additions and 13 deletions

View File

@ -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"

View File

@ -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<T : Enum<T>>(
private val recorder: ((Map<T, String>?) -> Unit),
@ -172,6 +173,16 @@ private val Event.wrapper
is Event.QRScannerNavigationDenied -> EventWrapper<NoExtraKeys>(
{ QrScanner.navigationDenied.record(it) }
)
is Event.LibraryOpened -> EventWrapper<NoExtraKeys>(
{ Library.opened.record(it) }
)
is Event.LibraryClosed -> EventWrapper<NoExtraKeys>(
{ Library.closed.record(it) }
)
is Event.LibrarySelectedItem -> EventWrapper(
{ Library.selectedItem },
{ Library.selectedItemKeys.valueOf(it) }
)
// Don't track other events with Glean
else -> null

View File

@ -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<String, String>?
get() = mapOf("source" to item)
}
data class SearchBarTapped(val source: Source) : Event() {
enum class Source { HOME, BROWSER }
override val extras: Map<String, String>?

View File

@ -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<Toolbar>(R.id.navigationToolbar)