diff --git a/app/metrics.yaml b/app/metrics.yaml index ae7d23e73c..2c974162bf 100644 --- a/app/metrics.yaml +++ b/app/metrics.yaml @@ -4,6 +4,21 @@ $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: default_browser: type: boolean diff --git a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt index 7287aee733..933104a26c 100644 --- a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt +++ b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt @@ -32,6 +32,8 @@ import org.mozilla.fenix.settings.SettingsFragmentDirections @SuppressWarnings("TooManyFunctions") open class HomeActivity : AppCompatActivity() { + open val isCustomTab = false + val themeManager = DefaultThemeManager().also { it.onThemeChange = { theme -> setTheme(theme) @@ -60,16 +62,22 @@ open class HomeActivity : AppCompatActivity() { setSupportActionBar(navigationToolbar) 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) } - + override fun onResume() { super.onResume() // There is no session, or it has timed out; we should pop everything to home if (components.core.sessionStorage.current() == null) { navHost.navController.popBackStack(R.id.homeFragment, false) } - components.analytics.metrics.track(Event.OpenedApp) } override fun onNewIntent(intent: Intent?) { 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 6b6c8a1fba..80210a1e8f 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 @@ -4,11 +4,13 @@ package org.mozilla.fenix.components.metrics import android.content.Context +import mozilla.components.service.glean.EventMetricType import mozilla.components.service.glean.Glean import mozilla.components.support.utils.Browsers import org.mozilla.fenix.BuildConfig import org.mozilla.fenix.utils.Settings import org.mozilla.fenix.debug.GleanMetrics.Metrics +import org.mozilla.fenix.debug.GleanMetrics.Events class GleanMetricsService(private val context: Context) : MetricsService { 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 { private const val IsGleanEnabled = BuildConfig.TELEMETRY 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 710983f184..915cba6f90 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 @@ -9,7 +9,15 @@ sealed class Event { object AddBookmark : Event() object RemoveBookmark : 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? + get() = hashMapOf("source" to source.name) + } + object OpenedAppFirstRun : Event() object InteractWithSearchURLArea : Event() object SavedLoginandPassword : Event() @@ -38,7 +46,7 @@ sealed class Event { object OpenedPocketStory : Event() object DarkModeEnabled : Event() - val extras: Map? + open val extras: Map? get() = null } diff --git a/app/src/main/java/org/mozilla/fenix/customtabs/CustomTabActivity.kt b/app/src/main/java/org/mozilla/fenix/customtabs/CustomTabActivity.kt index d42a1c4f21..5132bf3192 100644 --- a/app/src/main/java/org/mozilla/fenix/customtabs/CustomTabActivity.kt +++ b/app/src/main/java/org/mozilla/fenix/customtabs/CustomTabActivity.kt @@ -6,4 +6,6 @@ package org.mozilla.fenix.customtabs import org.mozilla.fenix.HomeActivity -class CustomTabActivity : HomeActivity() +class CustomTabActivity : HomeActivity() { + override val isCustomTab = true +}