From e19e13c7680bf07ff389ce4a2024398be99dde78 Mon Sep 17 00:00:00 2001 From: Jeff Boek Date: Tue, 2 Apr 2019 18:18:14 -0700 Subject: [PATCH] For #957 - Adds telemetry for context menu items --- app/metrics.yaml | 21 +++++++++++ .../components/metrics/GleanMetricsService.kt | 7 +++- .../fenix/components/metrics/Metrics.kt | 35 +++++++++++++++---- 3 files changed, 55 insertions(+), 8 deletions(-) diff --git a/app/metrics.yaml b/app/metrics.yaml index 9871ab5b6..2ed66ad22 100644 --- a/app/metrics.yaml +++ b/app/metrics.yaml @@ -101,6 +101,27 @@ events: - telemetry-client-dev@mozilla.com expires: "2020-03-01" +context_menu: + item_tapped: + type: event + description: > + A user tapped an item in the browsers context menu + extra_keys: + named: + description: > + The name of the item that was tapped. Available items are + ``` + open_in_new_tab, open_in_private_tab, open_image_in_new_tab, + save_image, share_link, copy_link, copy_image_location + ``` + bugs: + - 957 + data_reviews: + - TBD + notification_emails: + - telemetry-client-dev@mozilla.com + expires: "2020-03-01" + find_in_page: opened: type: event 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 23676967d..dce3f29da 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 @@ -8,6 +8,7 @@ import mozilla.components.service.glean.Glean import mozilla.components.service.glean.metrics.NoExtraKeys import mozilla.components.support.utils.Browsers import org.mozilla.fenix.BuildConfig +import org.mozilla.fenix.GleanMetrics.ContextMenu import org.mozilla.fenix.utils.Settings import org.mozilla.fenix.GleanMetrics.Metrics import org.mozilla.fenix.GleanMetrics.Events @@ -61,12 +62,16 @@ private val Event.wrapper is Event.FindInPageNext -> EventWrapper( { FindInPage.nextResult.record(it) } ) - is Event.FindInPagePrevious-> EventWrapper( + is Event.FindInPagePrevious -> EventWrapper( { FindInPage.previousResult.record(it) } ) is Event.FindInPageSearchCommitted -> EventWrapper( { FindInPage.searchedPage.record(it) } ) + is Event.ContextMenuItemTapped -> EventWrapper( + { ContextMenu.itemTapped.record(it) }, + { ContextMenu.itemTappedKeys.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 75a83d402..db439e608 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 @@ -74,26 +74,47 @@ sealed class Event { get() = mapOf("engine" to engine) } - object FindInPageOpened: Event() - object FindInPageClosed: Event() - object FindInPageNext: Event() - object FindInPagePrevious: Event() - object FindInPageSearchCommitted: Event() + object FindInPageOpened : Event() + object FindInPageClosed : Event() + object FindInPageNext : Event() + object FindInPagePrevious : Event() + object FindInPageSearchCommitted : Event() + class ContextMenuItemTapped private constructor(val item: String) : Event() { + override val extras: Map? + get() = mapOf("named" to item) + + companion object { + fun create(context_item: String) = allowList[context_item]?.let { ContextMenuItemTapped(it) } + + private val allowList = mapOf( + "mozac.feature.contextmenu.open_in_new_tab" to "open_in_new_tab", + "mozac.feature.contextmenu.open_in_private_tab" to "open_in_private_tab", + "mozac.feature.contextmenu.open_image_in_new_tab" to "open_image_in_new_tab", + "mozac.feature.contextmenu.save_image" to "save_image", + "mozac.feature.contextmenu.share_link" to "share_link", + "mozac.feature.contextmenu.copy_link" to "copy_link", + "mozac.feature.contextmenu.copy_image_location" to "copy_image_location" + ) + } + } open val extras: Map? get() = null } -private fun Fact.toEvent(): Event? = when(Pair(component, item)){ +private fun Fact.toEvent(): Event? = when (Pair(component, item)) { Pair(Component.FEATURE_FINDINPAGE, "previous") -> Event.FindInPagePrevious Pair(Component.FEATURE_FINDINPAGE, "next") -> Event.FindInPageNext Pair(Component.FEATURE_FINDINPAGE, "close") -> Event.FindInPageClosed Pair(Component.FEATURE_FINDINPAGE, "input") -> Event.FindInPageSearchCommitted + Pair(Component.FEATURE_CONTEXTMENU, "item") -> { + metadata?.get("item")?.let { Event.ContextMenuItemTapped.create(it.toString()) } + } + else -> null } - interface MetricsService { fun start() fun track(event: Event)