2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-09 19:10:42 +00:00

For #968 - Adds telemetry for app entry point

This commit is contained in:
Jeff Boek 2019-03-18 14:32:03 -07:00
parent 0e9400730b
commit 71a155c8f1
5 changed files with 51 additions and 7 deletions

View File

@ -4,6 +4,21 @@
$schema: moz://mozilla.org/schemas/glean/metrics/1-0-0 $schema: moz://mozilla.org/schemas/glean/metrics/1-0-0
events:
app_opened:
type: event
description: >
A User opened the app
extra_keys:
source: "The source from which the app was opened"
bugs:
- 123456789
data_reviews:
- N/A
notification_emails:
- telemetry-client-dev@mozilla.com
expires: never
metrics: metrics:
default_browser: default_browser:
type: boolean type: boolean

View File

@ -32,6 +32,8 @@ import org.mozilla.fenix.settings.SettingsFragmentDirections
@SuppressWarnings("TooManyFunctions") @SuppressWarnings("TooManyFunctions")
open class HomeActivity : AppCompatActivity() { open class HomeActivity : AppCompatActivity() {
open val isCustomTab = false
val themeManager = DefaultThemeManager().also { val themeManager = DefaultThemeManager().also {
it.onThemeChange = { theme -> it.onThemeChange = { theme ->
setTheme(theme) setTheme(theme)
@ -60,16 +62,22 @@ open class HomeActivity : AppCompatActivity() {
setSupportActionBar(navigationToolbar) setSupportActionBar(navigationToolbar)
NavigationUI.setupWithNavController(navigationToolbar, navHost.navController, appBarConfiguration) NavigationUI.setupWithNavController(navigationToolbar, navHost.navController, appBarConfiguration)
val safeIntent = intent?.let { SafeIntent(it) }
if (safeIntent?.isLauncherIntent == true) {
val source = if (isCustomTab) Event.OpenedAppSource.CUSTOM_TAB else Event.OpenedAppSource.APP_ICON
components.analytics.metrics.track(Event.OpenedApp(source))
}
handleOpenedFromExternalSourceIfNecessary(intent) handleOpenedFromExternalSourceIfNecessary(intent)
} }
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
// There is no session, or it has timed out; we should pop everything to home // There is no session, or it has timed out; we should pop everything to home
if (components.core.sessionStorage.current() == null) { if (components.core.sessionStorage.current() == null) {
navHost.navController.popBackStack(R.id.homeFragment, false) navHost.navController.popBackStack(R.id.homeFragment, false)
} }
components.analytics.metrics.track(Event.OpenedApp)
} }
override fun onNewIntent(intent: Intent?) { override fun onNewIntent(intent: Intent?) {

View File

@ -4,11 +4,13 @@
package org.mozilla.fenix.components.metrics package org.mozilla.fenix.components.metrics
import android.content.Context import android.content.Context
import mozilla.components.service.glean.EventMetricType
import mozilla.components.service.glean.Glean import mozilla.components.service.glean.Glean
import mozilla.components.support.utils.Browsers import mozilla.components.support.utils.Browsers
import org.mozilla.fenix.BuildConfig import org.mozilla.fenix.BuildConfig
import org.mozilla.fenix.utils.Settings import org.mozilla.fenix.utils.Settings
import org.mozilla.fenix.debug.GleanMetrics.Metrics import org.mozilla.fenix.debug.GleanMetrics.Metrics
import org.mozilla.fenix.debug.GleanMetrics.Events
class GleanMetricsService(private val context: Context) : MetricsService { class GleanMetricsService(private val context: Context) : MetricsService {
override fun start() { override fun start() {
@ -20,9 +22,18 @@ class GleanMetricsService(private val context: Context) : MetricsService {
} }
} }
override fun track(event: Event) { } private fun mapEventToGlean(event: Event): EventMetricType? = when(event) {
is Event.OpenedApp -> Events.appOpened
else -> null
}
override fun shouldTrack(event: Event): Boolean = Settings.getInstance(context).isTelemetryEnabled override fun track(event: Event) {
mapEventToGlean(event)?.record(event.extras)
}
override fun shouldTrack(event: Event): Boolean {
return Settings.getInstance(context).isTelemetryEnabled
}
companion object { companion object {
private const val IsGleanEnabled = BuildConfig.TELEMETRY private const val IsGleanEnabled = BuildConfig.TELEMETRY

View File

@ -9,7 +9,15 @@ sealed class Event {
object AddBookmark : Event() object AddBookmark : Event()
object RemoveBookmark : Event() object RemoveBookmark : Event()
object OpenedBookmark : Event() object OpenedBookmark : Event()
object OpenedApp : Event()
enum class OpenedAppSource {
APP_ICON, CUSTOM_TAB
}
data class OpenedApp(val source: OpenedAppSource) : Event() {
override val extras: Map<String, String>?
get() = hashMapOf("source" to source.name)
}
object OpenedAppFirstRun : Event() object OpenedAppFirstRun : Event()
object InteractWithSearchURLArea : Event() object InteractWithSearchURLArea : Event()
object SavedLoginandPassword : Event() object SavedLoginandPassword : Event()
@ -38,7 +46,7 @@ sealed class Event {
object OpenedPocketStory : Event() object OpenedPocketStory : Event()
object DarkModeEnabled : Event() object DarkModeEnabled : Event()
val extras: Map<String, Any>? open val extras: Map<String, String>?
get() = null get() = null
} }

View File

@ -6,4 +6,6 @@ package org.mozilla.fenix.customtabs
import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.HomeActivity
class CustomTabActivity : HomeActivity() class CustomTabActivity : HomeActivity() {
override val isCustomTab = true
}