1
0
Fork 0

For #10261: PWA Telemetry (#11859)

* Add PWA events to metrics.

Track events for add to homescreen and install.

Map PWA facts to events

* Map component facts to local metrics

Add events pings to fragments

Supress long method for events

Move install event to AC and collect facts

Retrieve fg and bg events from Facts. Do not track intent fg/bg events, only views

* Allow onPause in base fragment to send telemetry for PWA in the external app fragment. Track foreground and bg locally in fenix, and route install and home screen taps from AC facts

* Rebase
master
Elise Richards 2020-08-03 13:59:31 -05:00 committed by GitHub
parent 3cb1acc35a
commit 3e8cab19c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 127 additions and 2 deletions

View File

@ -3315,3 +3315,61 @@ storage.stats:
- perf-android-fe@mozilla.com - perf-android-fe@mozilla.com
- mcomella@mozilla.com - mcomella@mozilla.com
expires: "2021-02-01" 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"

View File

@ -739,7 +739,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
} }
@CallSuper @CallSuper
final override fun onPause() { override fun onPause() {
super.onPause() super.onPause()
if (findNavController().currentDestination?.id != R.id.searchFragment) { if (findNavController().currentDestination?.id != R.id.searchFragment) {
view?.hideKeyboard() view?.hideKeyboard()

View File

@ -17,6 +17,7 @@ import org.mozilla.fenix.GleanMetrics.ErrorPage
import org.mozilla.fenix.GleanMetrics.Events import org.mozilla.fenix.GleanMetrics.Events
import org.mozilla.fenix.GleanMetrics.Logins import org.mozilla.fenix.GleanMetrics.Logins
import org.mozilla.fenix.GleanMetrics.Onboarding import org.mozilla.fenix.GleanMetrics.Onboarding
import org.mozilla.fenix.GleanMetrics.ProgressiveWebApp
import org.mozilla.fenix.GleanMetrics.SearchShortcuts import org.mozilla.fenix.GleanMetrics.SearchShortcuts
import org.mozilla.fenix.GleanMetrics.Tip import org.mozilla.fenix.GleanMetrics.Tip
import org.mozilla.fenix.GleanMetrics.ToolbarSettings import org.mozilla.fenix.GleanMetrics.ToolbarSettings
@ -185,7 +186,21 @@ sealed class Event {
object TabsTrayShareAllTabsPressed : Event() object TabsTrayShareAllTabsPressed : Event()
object TabsTrayCloseAllTabsPressed : Event() object TabsTrayCloseAllTabsPressed : Event()
object ProgressiveWebAppOpenFromHomescreenTap : Event()
object ProgressiveWebAppInstallAsShortcut : Event()
// Interaction events with extras // Interaction events with extras
data class ProgressiveWebAppForeground(val timeForegrounded: Long) : Event() {
override val extras: Map<ProgressiveWebApp.foregroundKeys, String>?
get() = mapOf(ProgressiveWebApp.foregroundKeys.timeMs to timeForegrounded.toString())
}
data class ProgressiveWebAppBackground(val timeBackgrounded: Long) : Event() {
override val extras: Map<ProgressiveWebApp.backgroundKeys, String>?
get() = mapOf(ProgressiveWebApp.backgroundKeys.timeMs to timeBackgrounded.toString())
}
data class OnboardingToolbarPosition(val position: Position) : Event() { data class OnboardingToolbarPosition(val position: Position) : Event() {
enum class Position { TOP, BOTTOM } enum class Position { TOP, BOTTOM }

View File

@ -36,6 +36,7 @@ import org.mozilla.fenix.GleanMetrics.Pocket
import org.mozilla.fenix.GleanMetrics.Preferences import org.mozilla.fenix.GleanMetrics.Preferences
import org.mozilla.fenix.GleanMetrics.PrivateBrowsingMode import org.mozilla.fenix.GleanMetrics.PrivateBrowsingMode
import org.mozilla.fenix.GleanMetrics.PrivateBrowsingShortcut import org.mozilla.fenix.GleanMetrics.PrivateBrowsingShortcut
import org.mozilla.fenix.GleanMetrics.ProgressiveWebApp
import org.mozilla.fenix.GleanMetrics.QrScanner import org.mozilla.fenix.GleanMetrics.QrScanner
import org.mozilla.fenix.GleanMetrics.ReaderMode import org.mozilla.fenix.GleanMetrics.ReaderMode
import org.mozilla.fenix.GleanMetrics.SearchDefaultEngine import org.mozilla.fenix.GleanMetrics.SearchDefaultEngine
@ -677,6 +678,20 @@ private val Event.wrapper: EventWrapper<*>?
{ Autoplay.settingChanged.record(it) }, { Autoplay.settingChanged.record(it) },
{ Autoplay.settingChangedKeys.valueOf(it) } { Autoplay.settingChangedKeys.valueOf(it) }
) )
is Event.ProgressiveWebAppOpenFromHomescreenTap -> EventWrapper<NoExtraKeys>(
{ ProgressiveWebApp.homescreenTap.record(it) }
)
is Event.ProgressiveWebAppInstallAsShortcut -> EventWrapper<NoExtraKeys>(
{ 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: // Don't record other events in Glean:
is Event.AddBookmark -> null is Event.AddBookmark -> null

View File

@ -20,6 +20,7 @@ import mozilla.components.feature.downloads.facts.DownloadsFacts
import mozilla.components.feature.findinpage.facts.FindInPageFacts import mozilla.components.feature.findinpage.facts.FindInPageFacts
import mozilla.components.feature.media.facts.MediaFacts import mozilla.components.feature.media.facts.MediaFacts
import mozilla.components.feature.prompts.dialog.LoginDialogFacts import mozilla.components.feature.prompts.dialog.LoginDialogFacts
import mozilla.components.feature.pwa.ProgressiveWebAppFacts
import mozilla.components.support.base.Component import mozilla.components.support.base.Component
import mozilla.components.support.base.facts.Action import mozilla.components.support.base.facts.Action
import mozilla.components.support.base.facts.Fact import mozilla.components.support.base.facts.Fact
@ -222,6 +223,12 @@ internal class ReleaseMetricController(
} }
null null
} }
Component.FEATURE_PWA to ProgressiveWebAppFacts.Items.HOMESCREEN_ICON_TAP -> {
Event.ProgressiveWebAppOpenFromHomescreenTap
}
Component.FEATURE_PWA to ProgressiveWebAppFacts.Items.INSTALL_SHORTCUT -> {
Event.ProgressiveWebAppInstallAsShortcut
}
else -> null else -> null
} }
} }

View File

@ -6,6 +6,7 @@ package org.mozilla.fenix.customtabs
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.SystemClock
import android.view.View import android.view.View
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.navigation.fragment.navArgs 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.BaseBrowserFragment
import org.mozilla.fenix.browser.CustomTabContextMenuCandidate import org.mozilla.fenix.browser.CustomTabContextMenuCandidate
import org.mozilla.fenix.browser.FenixSnackbarDelegate import org.mozilla.fenix.browser.FenixSnackbarDelegate
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.metrics
import org.mozilla.fenix.ext.nav import org.mozilla.fenix.ext.nav
import org.mozilla.fenix.ext.requireComponents import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.ext.settings 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 { override fun removeSessionIfNeeded(): Boolean {
return customTabsIntegration.onBackPressed() || super.removeSessionIfNeeded() return customTabsIntegration.onBackPressed() || super.removeSessionIfNeeded()
} }
@ -192,4 +211,9 @@ class ExternalAppBrowserFragment : BaseBrowserFragment(), UserInteractionHandler
view, view,
FenixSnackbarDelegate(view) FenixSnackbarDelegate(view)
) )
companion object {
// We only care about millisecond precision for telemetry events
internal const val MS_PRECISION = 1_000_000L
}
} }

View File

@ -38,7 +38,9 @@ class PwaOnboardingDialogFragment : DialogFragment() {
add_button.setOnClickListener { add_button.setOnClickListener {
viewLifecycleOwner.lifecycleScope.launch { viewLifecycleOwner.lifecycleScope.launch {
components.useCases.webAppUseCases.addToHomescreen() components.useCases.webAppUseCases.addToHomescreen()
}.invokeOnCompletion { dismiss() } }.invokeOnCompletion {
dismiss()
}
} }
} }
} }

View File

@ -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.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_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 | | | 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)|<ul><li>time_ms: The current time in ms when the PWA was backgrounded. </li></ul>|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)|<ul><li>time_ms: The current time in ms when the PWA was brought to the foreground. </li></ul>|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_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.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 | | | 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 | |