diff --git a/app/metrics.yaml b/app/metrics.yaml index 3b78f720c..5a15283cb 100644 --- a/app/metrics.yaml +++ b/app/metrics.yaml @@ -3315,3 +3315,61 @@ storage.stats: - perf-android-fe@mozilla.com - mcomella@mozilla.com expires: "2021-02-01" + +progressive_web_app: + homescreen_tap: + type: event + description: | + A user taps on PWA homescreen icon + bugs: + - https://github.com/mozilla-mobile/fenix/issues/10261 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/11859 + notification_emails: + - fenix-core@mozilla.com + - erichards@mozilla.com + expires: "2021-03-01" + install_tap: + type: event + description: | + A user installs a PWA. Could be a shortcut or added to homescreen. + bugs: + - https://github.com/mozilla-mobile/fenix/issues/10261 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/11859 + notification_emails: + - fenix-core@mozilla.com + - erichards@mozilla.com + expires: "2021-03-01" + foreground: + type: event + description: | + A user brings the PWA into the foreground. + extra_keys: + time_ms: + description: | + The current time in ms when the PWA was brought to the foreground. + bugs: + - https://github.com/mozilla-mobile/fenix/issues/10261 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/11859 + notification_emails: + - fenix-core@mozilla.com + - erichards@mozilla.com + expires: "2021-03-01" + background: + type: event + description: | + A user puts the PWA into the background. + extra_keys: + time_ms: + description: | + The current time in ms when the PWA was backgrounded. + bugs: + - https://github.com/mozilla-mobile/fenix/issues/10261 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/11859 + notification_emails: + - fenix-core@mozilla.com + - erichards@mozilla.com + expires: "2021-03-01" diff --git a/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt b/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt index d16f956e9..14ab0713c 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt @@ -739,7 +739,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session } @CallSuper - final override fun onPause() { + override fun onPause() { super.onPause() if (findNavController().currentDestination?.id != R.id.searchFragment) { view?.hideKeyboard() diff --git a/app/src/main/java/org/mozilla/fenix/components/metrics/Event.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/Event.kt index 1768829c4..83d5ef93d 100644 --- a/app/src/main/java/org/mozilla/fenix/components/metrics/Event.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/Event.kt @@ -17,6 +17,7 @@ import org.mozilla.fenix.GleanMetrics.ErrorPage import org.mozilla.fenix.GleanMetrics.Events import org.mozilla.fenix.GleanMetrics.Logins import org.mozilla.fenix.GleanMetrics.Onboarding +import org.mozilla.fenix.GleanMetrics.ProgressiveWebApp import org.mozilla.fenix.GleanMetrics.SearchShortcuts import org.mozilla.fenix.GleanMetrics.Tip import org.mozilla.fenix.GleanMetrics.ToolbarSettings @@ -185,7 +186,21 @@ sealed class Event { object TabsTrayShareAllTabsPressed : Event() object TabsTrayCloseAllTabsPressed : Event() + object ProgressiveWebAppOpenFromHomescreenTap : Event() + object ProgressiveWebAppInstallAsShortcut : Event() + // Interaction events with extras + + data class ProgressiveWebAppForeground(val timeForegrounded: Long) : Event() { + override val extras: Map? + get() = mapOf(ProgressiveWebApp.foregroundKeys.timeMs to timeForegrounded.toString()) + } + + data class ProgressiveWebAppBackground(val timeBackgrounded: Long) : Event() { + override val extras: Map? + get() = mapOf(ProgressiveWebApp.backgroundKeys.timeMs to timeBackgrounded.toString()) + } + data class OnboardingToolbarPosition(val position: Position) : Event() { enum class Position { TOP, BOTTOM } 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 fb293c595..db2e02180 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 @@ -36,6 +36,7 @@ import org.mozilla.fenix.GleanMetrics.Pocket import org.mozilla.fenix.GleanMetrics.Preferences import org.mozilla.fenix.GleanMetrics.PrivateBrowsingMode import org.mozilla.fenix.GleanMetrics.PrivateBrowsingShortcut +import org.mozilla.fenix.GleanMetrics.ProgressiveWebApp import org.mozilla.fenix.GleanMetrics.QrScanner import org.mozilla.fenix.GleanMetrics.ReaderMode import org.mozilla.fenix.GleanMetrics.SearchDefaultEngine @@ -677,6 +678,20 @@ private val Event.wrapper: EventWrapper<*>? { Autoplay.settingChanged.record(it) }, { Autoplay.settingChangedKeys.valueOf(it) } ) + is Event.ProgressiveWebAppOpenFromHomescreenTap -> EventWrapper( + { ProgressiveWebApp.homescreenTap.record(it) } + ) + is Event.ProgressiveWebAppInstallAsShortcut -> EventWrapper( + { ProgressiveWebApp.installTap.record(it) } + ) + is Event.ProgressiveWebAppForeground -> EventWrapper( + { ProgressiveWebApp.foreground.record(it) }, + { ProgressiveWebApp.foregroundKeys.valueOf(it) } + ) + is Event.ProgressiveWebAppBackground -> EventWrapper( + { ProgressiveWebApp.background.record(it) }, + { ProgressiveWebApp.backgroundKeys.valueOf(it) } + ) // Don't record other events in Glean: is Event.AddBookmark -> null diff --git a/app/src/main/java/org/mozilla/fenix/components/metrics/MetricController.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/MetricController.kt index 3b7c5bb5c..16b47a519 100644 --- a/app/src/main/java/org/mozilla/fenix/components/metrics/MetricController.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/MetricController.kt @@ -20,6 +20,7 @@ import mozilla.components.feature.downloads.facts.DownloadsFacts import mozilla.components.feature.findinpage.facts.FindInPageFacts import mozilla.components.feature.media.facts.MediaFacts import mozilla.components.feature.prompts.dialog.LoginDialogFacts +import mozilla.components.feature.pwa.ProgressiveWebAppFacts import mozilla.components.support.base.Component import mozilla.components.support.base.facts.Action import mozilla.components.support.base.facts.Fact @@ -222,6 +223,12 @@ internal class ReleaseMetricController( } null } + Component.FEATURE_PWA to ProgressiveWebAppFacts.Items.HOMESCREEN_ICON_TAP -> { + Event.ProgressiveWebAppOpenFromHomescreenTap + } + Component.FEATURE_PWA to ProgressiveWebAppFacts.Items.INSTALL_SHORTCUT -> { + Event.ProgressiveWebAppInstallAsShortcut + } else -> null } } diff --git a/app/src/main/java/org/mozilla/fenix/customtabs/ExternalAppBrowserFragment.kt b/app/src/main/java/org/mozilla/fenix/customtabs/ExternalAppBrowserFragment.kt index ea853bd94..2387b9c58 100644 --- a/app/src/main/java/org/mozilla/fenix/customtabs/ExternalAppBrowserFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/customtabs/ExternalAppBrowserFragment.kt @@ -6,6 +6,7 @@ package org.mozilla.fenix.customtabs import android.content.Context import android.content.Intent +import android.os.SystemClock import android.view.View import androidx.core.view.isVisible import androidx.navigation.fragment.navArgs @@ -30,7 +31,9 @@ import org.mozilla.fenix.R import org.mozilla.fenix.browser.BaseBrowserFragment import org.mozilla.fenix.browser.CustomTabContextMenuCandidate import org.mozilla.fenix.browser.FenixSnackbarDelegate +import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.ext.components +import org.mozilla.fenix.ext.metrics import org.mozilla.fenix.ext.nav import org.mozilla.fenix.ext.requireComponents import org.mozilla.fenix.ext.settings @@ -150,6 +153,22 @@ class ExternalAppBrowserFragment : BaseBrowserFragment(), UserInteractionHandler } } + override fun onResume() { + super.onResume() + val currTimeMs = SystemClock.elapsedRealtimeNanos() / MS_PRECISION + requireComponents.analytics.metrics.track( + Event.ProgressiveWebAppForeground(currTimeMs) + ) + } + + override fun onPause() { + super.onPause() + val currTimeMs = SystemClock.elapsedRealtimeNanos() / MS_PRECISION + requireComponents.analytics.metrics.track( + Event.ProgressiveWebAppBackground(currTimeMs) + ) + } + override fun removeSessionIfNeeded(): Boolean { return customTabsIntegration.onBackPressed() || super.removeSessionIfNeeded() } @@ -192,4 +211,9 @@ class ExternalAppBrowserFragment : BaseBrowserFragment(), UserInteractionHandler view, FenixSnackbarDelegate(view) ) + + companion object { + // We only care about millisecond precision for telemetry events + internal const val MS_PRECISION = 1_000_000L + } } diff --git a/app/src/main/java/org/mozilla/fenix/shortcut/PwaOnboardingDialogFragment.kt b/app/src/main/java/org/mozilla/fenix/shortcut/PwaOnboardingDialogFragment.kt index 43b9099fc..05d8520e3 100644 --- a/app/src/main/java/org/mozilla/fenix/shortcut/PwaOnboardingDialogFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/shortcut/PwaOnboardingDialogFragment.kt @@ -38,7 +38,9 @@ class PwaOnboardingDialogFragment : DialogFragment() { add_button.setOnClickListener { viewLifecycleOwner.lifecycleScope.launch { components.useCases.webAppUseCases.addToHomescreen() - }.invokeOnCompletion { dismiss() } + }.invokeOnCompletion { + dismiss() + } } } } diff --git a/docs/metrics.md b/docs/metrics.md index b21181614..fdf276a7a 100644 --- a/docs/metrics.md +++ b/docs/metrics.md @@ -159,6 +159,10 @@ The following metrics are added to the ping: | private_browsing_shortcut.pinned_shortcut_priv |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user pressed the pinned private shortcut in Android home screen, opening up a new private search. |[1](https://github.com/mozilla-mobile/fenix/pull/5194)||2020-10-01 | | | private_browsing_shortcut.static_shortcut_priv |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user pressed the long-press shortcut "Open new private tab", opening up a new private search. |[1](https://github.com/mozilla-mobile/fenix/pull/5194)||2020-10-01 | | | private_browsing_shortcut.static_shortcut_tab |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user pressed the long-press shortcut "Open new tab", opening up a new search. |[1](https://github.com/mozilla-mobile/fenix/pull/5194)||2020-10-01 | | +| progressive_web_app.background |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user puts the PWA into the background. |[1](https://github.com/mozilla-mobile/fenix/pull/11859)|
  • time_ms: The current time in ms when the PWA was backgrounded.
|2021-03-01 | | +| progressive_web_app.foreground |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user brings the PWA into the foreground. |[1](https://github.com/mozilla-mobile/fenix/pull/11859)|
  • time_ms: The current time in ms when the PWA was brought to the foreground.
|2021-03-01 | | +| progressive_web_app.homescreen_tap |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user taps on PWA homescreen icon |[1](https://github.com/mozilla-mobile/fenix/pull/11859)||2021-03-01 | | +| progressive_web_app.install_tap |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user installs a PWA. Could be a shortcut or added to homescreen. |[1](https://github.com/mozilla-mobile/fenix/pull/11859)||2021-03-01 | | | qr_scanner.navigation_allowed |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user tapped "allow" on the prompt, directing the user to the website scanned |[1](https://github.com/mozilla-mobile/fenix/pull/2524#issuecomment-492739967)||2020-10-01 | | | qr_scanner.navigation_denied |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user tapped "deny" on the prompt, putting the user back to the scanning view |[1](https://github.com/mozilla-mobile/fenix/pull/2524#issuecomment-492739967)||2020-10-01 | | | qr_scanner.opened |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user opened the QR scanner |[1](https://github.com/mozilla-mobile/fenix/pull/2524#issuecomment-492739967)||2020-10-01 | |