1
0
Fork 0

For #959 - Adds telemetry for when the search bar is tapped

master
Jeff Boek 2019-03-18 14:54:36 -07:00
parent 71a155c8f1
commit 786592e8d0
7 changed files with 56 additions and 21 deletions

View File

@ -8,7 +8,7 @@ events:
app_opened:
type: event
description: >
A User opened the app
A user opened the app
extra_keys:
source: "The source from which the app was opened"
bugs:
@ -18,6 +18,19 @@ events:
notification_emails:
- telemetry-client-dev@mozilla.com
expires: never
search_bar_tapped:
type: event
description: >
A user tapped the search bar
extra_keys:
source: "The source from which the search bar was tapped"
bugs:
- 123456789
data_reviews:
- N/A
notification_emails:
- telemetry-client-dev@mozilla.com
expires: never
metrics:
default_browser:

View File

@ -65,7 +65,7 @@ open class HomeActivity : AppCompatActivity() {
val safeIntent = intent?.let { SafeIntent(it) }
if (safeIntent?.isLauncherIntent == true) {
val source = if (isCustomTab) Event.OpenedAppSource.CUSTOM_TAB else Event.OpenedAppSource.APP_ICON
val source = if (isCustomTab) Event.OpenedApp.Source.CUSTOM_TAB else Event.OpenedApp.Source.APP_ICON
components.analytics.metrics.track(Event.OpenedApp(source))
}

View File

@ -42,6 +42,7 @@ import org.mozilla.fenix.IntentReceiverActivity
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.toolbar.SearchAction
import org.mozilla.fenix.components.toolbar.SearchState
import org.mozilla.fenix.components.toolbar.ToolbarComponent
@ -242,11 +243,16 @@ class BrowserFragment : Fragment(), BackHandler {
getAutoDisposeObservable<SearchAction>()
.subscribe {
when (it) {
is SearchAction.ToolbarTapped -> Navigation.findNavController(toolbarComponent.getView())
.navigate(
BrowserFragmentDirections.actionBrowserFragmentToSearchFragment(
requireComponents.core.sessionManager.selectedSession?.id)
)
is SearchAction.ToolbarTapped -> {
Navigation
.findNavController(toolbarComponent.getView())
.navigate(
BrowserFragmentDirections.actionBrowserFragmentToSearchFragment(
requireComponents.core.sessionManager.selectedSession?.id)
)
requireComponents.analytics.metrics.track(Event.SearchBarTapped(Event.SearchBarTapped.Source.BROWSER))
}
is SearchAction.ToolbarMenuItemTapped -> handleToolbarItemInteraction(it)
}
}

View File

@ -12,6 +12,13 @@ import org.mozilla.fenix.utils.Settings
import org.mozilla.fenix.debug.GleanMetrics.Metrics
import org.mozilla.fenix.debug.GleanMetrics.Events
private val Event.metricType: EventMetricType?
get() = when(this) {
is Event.OpenedApp -> Events.appOpened
is Event.SearchBarTapped -> Events.searchBarTapped
else -> null
}
class GleanMetricsService(private val context: Context) : MetricsService {
override fun start() {
Glean.initialize(context)
@ -22,17 +29,12 @@ class GleanMetricsService(private val context: Context) : MetricsService {
}
}
private fun mapEventToGlean(event: Event): EventMetricType? = when(event) {
is Event.OpenedApp -> Events.appOpened
else -> null
}
override fun track(event: Event) {
mapEventToGlean(event)?.record(event.extras)
event.metricType?.record(event.extras)
}
override fun shouldTrack(event: Event): Boolean {
return Settings.getInstance(context).isTelemetryEnabled
return Settings.getInstance(context).isTelemetryEnabled && event.metricType != null
}
companion object {

View File

@ -11,7 +11,7 @@ import com.leanplum.annotations.Parser
import org.mozilla.fenix.BuildConfig
import org.mozilla.fenix.utils.Settings
private val Event.name: String
private val Event.name: String?
get() = when (this) {
is Event.AddBookmark -> "E_Add_Bookmark"
is Event.RemoveBookmark -> "E_Remove_Bookmark"
@ -44,6 +44,9 @@ private val Event.name: String
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 -> ""
}
class LeanplumMetricsService(private val application: Application) : MetricsService {
@ -84,12 +87,14 @@ class LeanplumMetricsService(private val application: Application) : MetricsServ
}
override fun track(event: Event) {
Leanplum.track(event.name, event.extras)
event.name?.also {
Leanplum.track(it, event.extras)
}
}
override fun shouldTrack(event: Event): Boolean {
return Settings.getInstance(application).isTelemetryEnabled &&
token.type != Token.Type.Invalid
token.type != Token.Type.Invalid && !event.name.isNullOrEmpty()
}
companion object {

View File

@ -10,10 +10,9 @@ sealed class Event {
object RemoveBookmark : Event()
object OpenedBookmark : Event()
enum class OpenedAppSource {
APP_ICON, CUSTOM_TAB
}
data class OpenedApp(val source: OpenedAppSource) : Event() {
data class OpenedApp(val source: Source) : Event() {
enum class Source { APP_ICON, CUSTOM_TAB }
override val extras: Map<String, String>?
get() = hashMapOf("source" to source.name)
}
@ -46,6 +45,13 @@ sealed class Event {
object OpenedPocketStory : Event()
object DarkModeEnabled : Event()
// Interaction Events
data class SearchBarTapped(val source: Source) : Event() {
enum class Source { HOME, BROWSER }
override val extras: Map<String, String>?
get() = mapOf("source" to source.name)
}
open val extras: Map<String, String>?
get() = null
}

View File

@ -35,6 +35,7 @@ import org.mozilla.fenix.DefaultThemeManager
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.ext.archive
import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.home.sessions.ArchivedSession
@ -134,6 +135,8 @@ class HomeFragment : Fragment(), CoroutineScope {
view.toolbar.setOnClickListener {
val directions = HomeFragmentDirections.actionHomeFragmentToSearchFragment(null)
Navigation.findNavController(it).navigate(directions)
requireComponents.analytics.metrics.track(Event.SearchBarTapped(Event.SearchBarTapped.Source.HOME))
}
// There is currently an issue with visibility changes in ConstraintLayout 2.0.0-alpha3