From 32f8e06e987e2c7ebbd7858769d7dd293ab2d95e Mon Sep 17 00:00:00 2001 From: Jeff Boek Date: Mon, 18 Mar 2019 16:09:27 -0700 Subject: [PATCH] For #959 - Adds search related telemetry --- app/metrics.yaml | 26 +++++++ .../components/metrics/GleanMetricsService.kt | 2 + .../metrics/LeanplumMetricsService.kt | 70 ++++++++++--------- .../fenix/components/metrics/Metrics.kt | 10 +++ .../mozilla/fenix/search/SearchFragment.kt | 12 ++++ 5 files changed, 86 insertions(+), 34 deletions(-) diff --git a/app/metrics.yaml b/app/metrics.yaml index df3388595..e37db8934 100644 --- a/app/metrics.yaml +++ b/app/metrics.yaml @@ -31,6 +31,32 @@ events: notification_emails: - telemetry-client-dev@mozilla.com expires: never + entered_url: + type: event + description: > + A user entered a url + extra_keys: + autocomplete: "The url was filled by the autocomplete" + bugs: + - 123456789 + data_reviews: + - N/A + notification_emails: + - telemetry-client-dev@mozilla.com + expires: never + performed_search: + type: event + description: > + A user performed a search + extra_keys: + search_suggestion: "The search was initiated from a search suggestion" + bugs: + - 123456789 + data_reviews: + - N/A + notification_emails: + - telemetry-client-dev@mozilla.com + expires: never metrics: default_browser: 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 ab7e1f836..770a8e281 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 @@ -16,6 +16,8 @@ private val Event.metricType: EventMetricType? get() = when(this) { is Event.OpenedApp -> Events.appOpened is Event.SearchBarTapped -> Events.searchBarTapped + is Event.EnteredUrl -> Events.enteredUrl + is Event.PerformedSearch -> Events.performedSearch else -> null } diff --git a/app/src/main/java/org/mozilla/fenix/components/metrics/LeanplumMetricsService.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/LeanplumMetricsService.kt index 5e520f124..3d0bcccbc 100644 --- a/app/src/main/java/org/mozilla/fenix/components/metrics/LeanplumMetricsService.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/LeanplumMetricsService.kt @@ -13,41 +13,43 @@ import org.mozilla.fenix.utils.Settings private val Event.name: String? get() = when (this) { - is Event.AddBookmark -> "E_Add_Bookmark" - is Event.RemoveBookmark -> "E_Remove_Bookmark" - is Event.OpenedBookmark -> "E_Opened_Bookmark" - is Event.OpenedApp -> "E_Opened_App" - is Event.OpenedAppFirstRun -> "E_Opened_App_FirstRun" - is Event.InteractWithSearchURLArea -> "E_Interact_With_Search_URL_Area" - is Event.SavedLoginandPassword -> "E_Saved_Login_and_Password" - is Event.FXANewSignup -> "E_FXA_New_Signup" - is Event.UserSignedInToFxA -> "E_User_Signed_In_To_FxA" - is Event.UserDownloadedFocus -> "E_User_Downloaded_Focus" - is Event.UserDownloadedLockbox -> "E_User_Downloaded_Lockbox" - is Event.UserDownloadedFennec -> "E_User_Downloaded_Fennec" - is Event.TrackingProtectionSettingsChanged -> "E_Tracking_Protection_Settings_Changed" - is Event.FXASyncedNewDevice -> "E_FXA_Synced_New_Device" - is Event.DismissedOnboarding -> "E_Dismissed_Onboarding" - is Event.Uninstall -> "E_Uninstall" - is Event.OpenNewNormalTab -> "E_Open_New_Normal_Tab" - is Event.OpenNewPrivateTab -> "E_Open_New_Private_Tab" - is Event.ShareStarted -> "E_Share_Started" - is Event.ShareCanceled -> "E_Share_Canceled" - is Event.ShareCompleted -> "E_Share_Completed" - is Event.ClosePrivateTabs -> "E_Close_Private_Tabs" - is Event.ClearedPrivateData -> "E_Cleared_Private_Data" - is Event.OpenedLoginManager -> "E_Opened_Login_Manager" - is Event.OpenedMailtoLink -> "E_Opened_Mailto_Link" - is Event.DownloadMediaSavedImage -> "E_Download_Media_Saved_Image" - is Event.UserUsedReaderView -> "E_User_Used_Reader_View" - is Event.UserDownloadedPocket -> "E_User_Downloaded_Pocket" - is Event.UserDownloadedSend -> "E_User_Downloaded_Send" - is Event.OpenedPocketStory -> "E_Opened_Pocket_Story" - is Event.DarkModeEnabled -> "E_Dark_Mode_Enabled" + is Event.AddBookmark -> "E_Add_Bookmark" + is Event.RemoveBookmark -> "E_Remove_Bookmark" + is Event.OpenedBookmark -> "E_Opened_Bookmark" + is Event.OpenedApp -> "E_Opened_App" + is Event.OpenedAppFirstRun -> "E_Opened_App_FirstRun" + is Event.InteractWithSearchURLArea -> "E_Interact_With_Search_URL_Area" + is Event.SavedLoginandPassword -> "E_Saved_Login_and_Password" + is Event.FXANewSignup -> "E_FXA_New_Signup" + is Event.UserSignedInToFxA -> "E_User_Signed_In_To_FxA" + is Event.UserDownloadedFocus -> "E_User_Downloaded_Focus" + is Event.UserDownloadedLockbox -> "E_User_Downloaded_Lockbox" + is Event.UserDownloadedFennec -> "E_User_Downloaded_Fennec" + is Event.TrackingProtectionSettingsChanged -> "E_Tracking_Protection_Settings_Changed" + is Event.FXASyncedNewDevice -> "E_FXA_Synced_New_Device" + is Event.DismissedOnboarding -> "E_Dismissed_Onboarding" + is Event.Uninstall -> "E_Uninstall" + is Event.OpenNewNormalTab -> "E_Open_New_Normal_Tab" + is Event.OpenNewPrivateTab -> "E_Open_New_Private_Tab" + is Event.ShareStarted -> "E_Share_Started" + is Event.ShareCanceled -> "E_Share_Canceled" + is Event.ShareCompleted -> "E_Share_Completed" + is Event.ClosePrivateTabs -> "E_Close_Private_Tabs" + is Event.ClearedPrivateData -> "E_Cleared_Private_Data" + is Event.OpenedLoginManager -> "E_Opened_Login_Manager" + is Event.OpenedMailtoLink -> "E_Opened_Mailto_Link" + is Event.DownloadMediaSavedImage -> "E_Download_Media_Saved_Image" + is Event.UserUsedReaderView -> "E_User_Used_Reader_View" + is Event.UserDownloadedPocket -> "E_User_Downloaded_Pocket" + is Event.UserDownloadedSend -> "E_User_Downloaded_Send" + is Event.OpenedPocketStory -> "E_Opened_Pocket_Story" + is Event.DarkModeEnabled -> "E_Dark_Mode_Enabled" - // Do not track these events in Leanplum - is Event.SearchBarTapped -> "" -} + // Do not track these events in Leanplum + is Event.SearchBarTapped -> "" + is Event.EnteredUrl -> "" + is Event.PerformedSearch -> "" + } class LeanplumMetricsService(private val application: Application) : MetricsService { data class Token(val id: String, val token: String) { 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 1582bfa8d..deb995f1f 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 @@ -52,6 +52,16 @@ sealed class Event { get() = mapOf("source" to source.name) } + data class EnteredUrl(val autoCompleted: Boolean) : Event() { + override val extras: Map? + get() = mapOf("autocomplete" to autoCompleted.toString()) + } + + data class PerformedSearch(val fromSearchSuggestion: Boolean) : Event() { + override val extras: Map? + get() = mapOf("search_suggestion" to fromSearchSuggestion.toString()) + } + open val extras: Map? get() = null } diff --git a/app/src/main/java/org/mozilla/fenix/search/SearchFragment.kt b/app/src/main/java/org/mozilla/fenix/search/SearchFragment.kt index 0f1ab6409..9a25a9118 100644 --- a/app/src/main/java/org/mozilla/fenix/search/SearchFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/search/SearchFragment.kt @@ -14,10 +14,12 @@ import androidx.fragment.app.Fragment import kotlinx.android.synthetic.main.fragment_search.view.* import mozilla.components.feature.search.SearchUseCases import mozilla.components.feature.session.SessionUseCases +import mozilla.components.support.ktx.kotlin.isUrl import org.mozilla.fenix.BrowserDirection import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.utils.ItsNotBrokenSnack import org.mozilla.fenix.R +import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.components.toolbar.SearchAction import org.mozilla.fenix.components.toolbar.SearchState import org.mozilla.fenix.components.toolbar.ToolbarComponent @@ -92,6 +94,14 @@ class SearchFragment : Fragment() { if (it.url.isNotBlank()) { (activity as HomeActivity).openToBrowserAndLoad(it.url, it.session, BrowserDirection.FromSearch) + + val event = if (it.url.isUrl()) { + Event.EnteredUrl(false) + } else { + Event.PerformedSearch(false) + } + + requireComponents.analytics.metrics.track(event) } } is SearchAction.TextChanged -> { @@ -109,11 +119,13 @@ class SearchFragment : Fragment() { is AwesomeBarAction.URLTapped -> { getSessionUseCase(requireContext(), sessionId == null).invoke(it.url) (activity as HomeActivity).openToBrowser(sessionId, BrowserDirection.FromSearch) + requireComponents.analytics.metrics.track(Event.EnteredUrl(false)) } is AwesomeBarAction.SearchTermsTapped -> { getSearchUseCase(requireContext(), sessionId == null) .invoke(it.searchTerms, it.engine) (activity as HomeActivity).openToBrowser(sessionId, BrowserDirection.FromSearch) + requireComponents.analytics.metrics.track(Event.PerformedSearch(true)) } } }