Skip to content

Commit

Permalink
Fixes mozilla-mobile#1024 - Adds metrics for browser menu items
Browse files Browse the repository at this point in the history
  • Loading branch information
boek committed Mar 27, 2019
1 parent db440ed commit 1d532d1
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 1 deletion.
17 changes: 17 additions & 0 deletions app/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,23 @@ events:
notification_emails:
- telemetry-client-dev@mozilla.com
expires: "2020-03-01"
browser_menu_action:
type: event
description: >
A browser menu item was tapped
extra_keys:
item:
description: >
A string containing the name of the item the user tapped. These items include:
Settings, Your library, Help, Desktop Site toggle on/off, Find in Page, New Tab,
Private Tab, Share, Report Site Issue, Back/Forward button, Reload Button
bugs:
- 1024
data_reviews:
- TBD
notification_emails:
- telemetry-client-dev@mozilla.com
expires: "2020-03-01"

metrics:
default_browser:
Expand Down
29 changes: 28 additions & 1 deletion app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import org.mozilla.fenix.utils.ItsNotBrokenSnack
import org.mozilla.fenix.R
import org.mozilla.fenix.components.FindInPageIntegration
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.metrics.Event.BrowserMenuItemTapped.Item
import org.mozilla.fenix.components.toolbar.SearchAction
import org.mozilla.fenix.components.toolbar.SearchState
import org.mozilla.fenix.components.toolbar.ToolbarComponent
Expand Down Expand Up @@ -255,7 +256,10 @@ class BrowserFragment : Fragment(), BackHandler {
Event.SearchBarTapped(Event.SearchBarTapped.Source.BROWSER)
)
}
is SearchAction.ToolbarMenuItemTapped -> handleToolbarItemInteraction(it)
is SearchAction.ToolbarMenuItemTapped -> {
trackToolbarItemInteraction(it)
handleToolbarItemInteraction(it)
}
}
}
}
Expand Down Expand Up @@ -287,6 +291,29 @@ class BrowserFragment : Fragment(), BackHandler {
promptsFeature.withFeature { it.onActivityResult(requestCode, resultCode, data) }
}

// This method triggers the complexity warning. However it's actually not that hard to understand.
@SuppressWarnings("ComplexMethod")
private fun trackToolbarItemInteraction(action: SearchAction.ToolbarMenuItemTapped) {
val item = when (action.item) {
ToolbarMenu.Item.Back -> Item.BACK
ToolbarMenu.Item.Forward -> Item.FORWARD
ToolbarMenu.Item.Reload -> Item.RELOAD
ToolbarMenu.Item.Stop -> Item.STOP
ToolbarMenu.Item.Settings -> Item.SETTINGS
ToolbarMenu.Item.Library -> Item.LIBRARY
is ToolbarMenu.Item.RequestDesktop ->
if (action.item.isChecked) Item.DESKTOP_VIEW_ON else Item.DESKTOP_VIEW_OFF
ToolbarMenu.Item.NewPrivateTab -> Item.NEW_PRIVATE_TAB
ToolbarMenu.Item.FindInPage -> Item.FIND_IN_PAGE
ToolbarMenu.Item.ReportIssue -> Item.REPORT_SITE_ISSUE
ToolbarMenu.Item.Help -> Item.HELP
ToolbarMenu.Item.NewTab -> Item.NEW_TAB
ToolbarMenu.Item.OpenInFenix -> Item.OPEN_IN_FENIX
ToolbarMenu.Item.Share -> Item.SHARE
}

requireComponents.analytics.metrics.track(Event.BrowserMenuItemTapped(item))
}
// This method triggers the complexity warning. However it's actually not that hard to understand.
@SuppressWarnings("ComplexMethod")
private fun handleToolbarItemInteraction(action: SearchAction.ToolbarMenuItemTapped) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ private val Event.wrapper
is Event.CrashReporterClosed -> EventWrapper(Events.crashreporterClose) {
Events.crashreporterCloseKeys.valueOf(it)
}
is Event.BrowserMenuItemTapped -> EventWrapper(Events.browserMenuAction) {
Events.browserMenuActionKeys.valueOf(it)
}

else -> null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ private val Event.name: String?
is Event.PerformedSearch -> ""
is Event.CrashReporterOpened -> ""
is Event.CrashReporterClosed -> ""
is Event.BrowserMenuItemTapped -> ""
}

class LeanplumMetricsService(private val application: Application) : MetricsService {
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/org/mozilla/fenix/components/metrics/Metrics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ sealed class Event {
get() = mapOf("crash_submitted" to crashSubmitted.toString())
}

data class BrowserMenuItemTapped(val item: Item) : Event() {
enum class Item {
SETTINGS, LIBRARY, HELP, DESKTOP_VIEW_ON, DESKTOP_VIEW_OFF, FIND_IN_PAGE, NEW_TAB,
NEW_PRIVATE_TAB, SHARE, REPORT_SITE_ISSUE, BACK, FORWARD, RELOAD, STOP, OPEN_IN_FENIX
}

override val extras: Map<String, String>?
get() = mapOf("item" to item.toString().toLowerCase())
}

open val extras: Map<String, String>?
get() = null
}
Expand Down

0 comments on commit 1d532d1

Please sign in to comment.