From 13198f56dfb033bc348e5a541cb94f6694342f10 Mon Sep 17 00:00:00 2001 From: Sawyer Blatz Date: Thu, 18 Jul 2019 16:05:42 -0700 Subject: [PATCH] For #969: Adds telemetry for collections (#3935) --- app/metrics.yaml | 111 ++++++++++++++++++ .../collections/CollectionCreationUIView.kt | 4 + .../collections/CreateCollectionFragment.kt | 12 ++ .../components/metrics/GleanMetricsService.kt | 24 +++- .../fenix/components/metrics/Metrics.kt | 23 ++++ .../org/mozilla/fenix/home/HomeFragment.kt | 5 + docs/metrics.md | 92 +++++++++++++++ 7 files changed, 270 insertions(+), 1 deletion(-) diff --git a/app/metrics.yaml b/app/metrics.yaml index 24e265be5..cc51af96b 100644 --- a/app/metrics.yaml +++ b/app/metrics.yaml @@ -940,4 +940,115 @@ reader_mode: - https://github.com/mozilla-mobile/fenix/pull/3941 notification_emails: - fenix-core@mozilla.com + expires: "2020-03-01" + +collections: + renamed: + type: event + description: > + A user renamed a collection + bugs: + - 969 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/3935 + notification_emails: + - fenix-core@mozilla.com + expires: "2020-03-01" + tab_restored: + type: event + description: > + A user restored a tab from collection tab list + bugs: + - 969 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/3935 + notification_emails: + - fenix-core@mozilla.com + expires: "2020-03-01" + all_tabs_restored: + type: event + description: > + A user tapped "open tabs" from collection menu + bugs: + - 969 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/3935 + notification_emails: + - fenix-core@mozilla.com + expires: "2020-03-01" + tab_removed: + type: event + description: > + A user tapped remove tab from collection tab list + bugs: + - 969 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/3935 + notification_emails: + - fenix-core@mozilla.com + expires: "2020-03-01" + shared: + type: event + description: > + A user tapped share collection + bugs: + - 969 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/3935 + notification_emails: + - fenix-core@mozilla.com + expires: "2020-03-01" + removed: + type: event + description: > + A user tapped delete collection from collection menu + bugs: + - 969 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/3935 + notification_emails: + - fenix-core@mozilla.com + expires: "2020-03-01" + saved: + type: event + description: > + A user saved a list of tabs to a new collection + extra_keys: + tabs_open: + description: "The number of tabs open in the current session" + tabs_selected: + description: "The number of tabs added to the collection" + bugs: + - 969 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/3935 + notification_emails: + - fenix-core@mozilla.com + expires: "2020-03-01" + tabs_added: + type: event + description: > + A user saved a list of tabs to an existing collection + extra_keys: + tabs_open: + description: "The number of tabs open in the current session" + tabs_selected: + description: "The number of tabs added to the collection" + bugs: + - 969 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/3935 + notification_emails: + - fenix-core@mozilla.com + expires: "2020-03-01" + tab_select_opened: + type: event + description: > + A user opened the select tabs screen (the first step of the collection creation flow) + bugs: + - 969 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/3935 + 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/collections/CollectionCreationUIView.kt b/app/src/main/java/org/mozilla/fenix/collections/CollectionCreationUIView.kt index be61d6403..fee2b97fd 100644 --- a/app/src/main/java/org/mozilla/fenix/collections/CollectionCreationUIView.kt +++ b/app/src/main/java/org/mozilla/fenix/collections/CollectionCreationUIView.kt @@ -29,6 +29,8 @@ import kotlinx.coroutines.Job import mozilla.components.support.ktx.android.view.hideKeyboard import mozilla.components.support.ktx.android.view.showKeyboard import org.mozilla.fenix.R +import org.mozilla.fenix.components.metrics.Event +import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.increaseTapArea import org.mozilla.fenix.ext.urlToTrimmedHost import org.mozilla.fenix.home.sessioncontrol.Tab @@ -124,6 +126,8 @@ class CollectionCreationUIView( when (it.saveCollectionStep) { is SaveCollectionStep.SelectTabs -> { + view.context.components.analytics.metrics.track(Event.CollectionTabSelectOpened) + view.tab_list.isClickable = true back_button.setOnClickListener { diff --git a/app/src/main/java/org/mozilla/fenix/collections/CreateCollectionFragment.kt b/app/src/main/java/org/mozilla/fenix/collections/CreateCollectionFragment.kt index 24b8e02cc..a171f5bea 100644 --- a/app/src/main/java/org/mozilla/fenix/collections/CreateCollectionFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/collections/CreateCollectionFragment.kt @@ -17,6 +17,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import org.mozilla.fenix.FenixViewModelProvider import org.mozilla.fenix.R +import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.requireComponents import org.mozilla.fenix.home.sessioncontrol.Tab @@ -122,6 +123,11 @@ class CreateCollectionFragment : DialogFragment() { viewLifecycleOwner.lifecycleScope.launch(Dispatchers.IO) { context.components.core.tabCollectionStorage.createCollection(it.name, sessionBundle) } + + context.components.analytics.metrics.track( + Event.CollectionSaved(context.components.core.sessionManager.size, sessionBundle.size) + ) + closeTabsIfNecessary(it.tabs) } } @@ -133,6 +139,11 @@ class CreateCollectionFragment : DialogFragment() { context.components.core.tabCollectionStorage .addTabsToCollection(it.collection, sessionBundle) } + + context.components.analytics.metrics.track( + Event.CollectionTabsAdded(context.components.core.sessionManager.size, sessionBundle.size) + ) + closeTabsIfNecessary(it.tabs) } } @@ -140,6 +151,7 @@ class CreateCollectionFragment : DialogFragment() { dismiss() viewLifecycleOwner.lifecycleScope.launch(Dispatchers.IO) { requireComponents.core.tabCollectionStorage.renameCollection(it.collection, it.name) + requireComponents.analytics.metrics.track(Event.CollectionRenamed) } } } 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 87c094d06..eea9ac348 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 @@ -29,9 +29,10 @@ import org.mozilla.fenix.GleanMetrics.Pings import org.mozilla.fenix.GleanMetrics.QrScanner 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.SyncAccount import org.mozilla.fenix.GleanMetrics.SyncAuth -import org.mozilla.fenix.ext.components private class EventWrapper>( private val recorder: ((Map?) -> Unit), @@ -243,6 +244,27 @@ private val Event.wrapper is Event.HistoryAllItemsRemoved -> EventWrapper( { History.removedAll.record(it) } ) + is Event.CollectionRenamed -> EventWrapper( + { Collections.renamed.record(it) } + ) + is Event.CollectionTabRestored -> EventWrapper( + { Collections.tabRestored.record(it) } + ) + is Event.CollectionAllTabsRestored -> EventWrapper( + { Collections.allTabsRestored.record(it) } + ) + is Event.CollectionTabRemoved -> EventWrapper( + { Collections.tabRemoved.record(it) } + ) + is Event.CollectionShared -> EventWrapper( + { Collections.shared.record(it) } + ) + is Event.CollectionRemoved -> EventWrapper( + { Collections.removed.record(it) } + ) + is Event.CollectionTabSelectOpened -> EventWrapper( + { Collections.tabSelectOpened.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 b25a4e103..71cf6397d 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 @@ -101,6 +101,13 @@ sealed class Event { object ReaderModeAvailable : Event() object ReaderModeOpened : Event() object ReaderModeAppearanceOpened : Event() + object CollectionRenamed : Event() + object CollectionTabRestored : Event() + object CollectionAllTabsRestored : Event() + object CollectionTabRemoved : Event() + object CollectionShared : Event() + object CollectionRemoved : Event() + object CollectionTabSelectOpened : Event() data class PreferenceToggled(val preferenceKey: String, val enabled: Boolean, val context: Context) : Event() { private val switchPreferenceTelemetryAllowList = listOf( @@ -124,6 +131,22 @@ sealed class Event { } // Interaction Events + data class CollectionSaved(val tabsOpenCount: Int, val tabsSelectedCount: Int) : Event() { + override val extras: Map? + get() = mapOf( + "tabs_open" to tabsOpenCount.toString(), + "tabs_selected" to tabsSelectedCount.toString() + ) + } + + data class CollectionTabsAdded(val tabsOpenCount: Int, val tabsSelectedCount: Int) : Event() { + override val extras: Map? + get() = mapOf( + "tabs_open" to tabsOpenCount.toString(), + "tabs_selected" to tabsSelectedCount.toString() + ) + } + data class LibrarySelectedItem(val item: String) : Event() { override val extras: Map? get() = mapOf("item" to item) diff --git a/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt b/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt index 608554e20..20e38546a 100644 --- a/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt @@ -460,6 +460,7 @@ class HomeFragment : Fragment(), AccountObserver { setPositiveButton(R.string.tab_collection_dialog_positive) { dialog: DialogInterface, _ -> viewLifecycleOwner.lifecycleScope.launch(Dispatchers.IO) { requireComponents.core.tabCollectionStorage.removeCollection(tabCollection) + requireComponents.analytics.metrics.track(Event.CollectionRemoved) }.invokeOnCompletion { dialog.dismiss() } @@ -516,6 +517,7 @@ class HomeFragment : Fragment(), AccountObserver { ) (activity as HomeActivity).openToBrowser(BrowserDirection.FromHome) } + requireComponents.analytics.metrics.track(Event.CollectionTabRestored) } is CollectionAction.OpenTabs -> { invokePendingDeleteJobs() @@ -540,15 +542,18 @@ class HomeFragment : Fragment(), AccountObserver { delay(ANIM_SCROLL_DELAY) sessionControlComponent.view.smoothScrollToPosition(0) } + requireComponents.analytics.metrics.track(Event.CollectionAllTabsRestored) } is CollectionAction.ShareTabs -> { val shareTabs = action.collection.tabs.map { ShareTab(it.url, it.title) } share(tabs = shareTabs) + requireComponents.analytics.metrics.track(Event.CollectionShared) } is CollectionAction.RemoveTab -> { viewLifecycleOwner.lifecycleScope.launch(Dispatchers.IO) { requireComponents.core.tabCollectionStorage.removeTabFromCollection(action.collection, action.tab) } + requireComponents.analytics.metrics.track(Event.CollectionTabRemoved) } } } diff --git a/docs/metrics.md b/docs/metrics.md index 2ee9632d2..221bbef49 100644 --- a/docs/metrics.md +++ b/docs/metrics.md @@ -800,6 +800,98 @@ tracking_protection +## collections + +
  
+  
+      
+          
+          
+          
+          
+          
+          
+      
+      
+          
+          
+          
+          
+          
+          
+      
+      
+          
+          
+          
+          
+          
+          
+      
+      
+          
+          
+          
+          
+          
+          
+      
+      
+          
+          
+          
+          
+          
+          
+      
+      
+          
+          
+          
+          
+          
+          
+      
+      
+          
+          
+          
+          
+          
+          
+      
+      
+          
+          
+          
+          
+         
+          
+      
+      
+          
+          
+          
+          
+         
+          
+      
+      
+          
+          
+          
+          
+          
+          
+      
+
keytypedescriptiondata deviewextrasexpires
renamedeventA user renamed a collectionlink2020-03-01
tab_restoredeventA user restored a tab from collection tab listlink2020-03-01
all_tabs_restoredeventA user tapped "open tabs" from collection menulink2020-03-01
tab_removedeventA user tapped remove tab from collection tab listlink2020-03-01
sharedeventA user tapped share collectionlink2020-03-01
removedeventA user tapped delete collection from collection menulink2020-03-01
savedeventA user saved a list of tabs to a new collectionlinktabs_open: The number of tabs open in the current session +tabs_selected: The number of tabs added to the collection + 2020-03-01
tabs_addedeventA user saved a list of tabs to an existing collectionlinktabs_open: The number of tabs open in the current session +tabs_selected: The number of tabs added to the collection + 2020-03-01
tab_select_openedeventA user opened the select tabs screen (the first step of the collection creation flow)link2020-03-01
+
+ + ## Metrics Items that are added to the metrics ping