Skip to content
This repository was archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
Map component facts to local metrics
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Elise Richards committed Jul 28, 2020
1 parent cefdd02 commit 3cef53d
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 28 deletions.
35 changes: 20 additions & 15 deletions app/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3140,47 +3140,52 @@ progressive_web_app:
bugs:
- https://github.com/mozilla-mobile/fenix/issues/10261
data_reviews:
- https://github.com/mozilla-mobile/fenix/issues/10261
- https://github.com/mozilla-mobile/fenix/pull/11859
notification_emails:
- fenix-core@mozilla.com
- erichards@mozilla.com
expires: "2020-09-01"
install_menu_tap:
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/issues/10261
- https://github.com/mozilla-mobile/fenix/pull/11859
notification_emails:
- fenix-core@mozilla.com
- erichards@mozilla.com
expires: "2020-09-01"
add_to_homescreen_tap:
expires: "2021-03-01"
foreground:
type: event
description: |
A user taps the add to homescreen icon for a PWA
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/issues/10261
- https://github.com/mozilla-mobile/fenix/pull/11859
notification_emails:
- fenix-core@mozilla.com
- erichards@mozilla.com
expires: "2020-09-01"
bring_to_foreground:
expires: "2021-03-01"
background:
type: event
description: |
A user brings the PWA into the foreground after a specified time interval.
A user puts the PWA into the background.
extra_keys:
duration:
time_ms:
description: |
The length of time in ms that the PWA was in the background
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/issues/10261
- https://github.com/mozilla-mobile/fenix/pull/11859
notification_emails:
- fenix-core@mozilla.com
- erichards@mozilla.com
expires: "2020-09-01"
expires: "2021-03-01"
Original file line number Diff line number Diff line change
Expand Up @@ -652,17 +652,19 @@ private val Event.wrapper: EventWrapper<*>?
is Event.TabsTrayCloseAllTabsPressed -> EventWrapper<NoExtraKeys>(
{ org.mozilla.fenix.GleanMetrics.TabsTray.closeAllTabs.record(it) }
)
is Event.ProgressiveWebAppHomescreenTap -> EventWrapper<NoExtraKeys>(
is Event.ProgressiveWebAppOpenFromHomescreenTap -> EventWrapper<NoExtraKeys>(
{ ProgressiveWebApp.homescreenTap.record(it) }
)
is Event.ProgressiveWebAppInstallMenuTap -> EventWrapper<NoExtraKeys>(
{ ProgressiveWebApp.installMenuTap.record(it) }
is Event.ProgressiveWebAppInstallAsShortcut -> EventWrapper<NoExtraKeys>(
{ ProgressiveWebApp.installTap.record(it) }
)
is Event.ProgressiveWebAppAddToHomescreenTap -> EventWrapper<NoExtraKeys>(
{ ProgressiveWebApp.addToHomescreenTap.record(it) }
is Event.ProgressiveWebAppForeground -> EventWrapper(
{ ProgressiveWebApp.foreground.record(it) },
{ ProgressiveWebApp.foregroundKeys.valueOf(it) }
)
is Event.ProgressiveWebAppBringToForeground -> EventWrapper<NoExtraKeys>(
{ ProgressiveWebApp.bringToForeground.record(it) }
is Event.ProgressiveWebAppBackground -> EventWrapper(
{ ProgressiveWebApp.background.record(it) },
{ ProgressiveWebApp.backgroundKeys.valueOf(it) }
)

// Don't record other events in Glean:
Expand Down
35 changes: 35 additions & 0 deletions app/src/main/java/org/mozilla/fenix/components/metrics/Metrics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package org.mozilla.fenix.components.metrics

import android.content.Context
import mozilla.components.browser.awesomebar.facts.BrowserAwesomeBarFacts
import mozilla.components.feature.pwa.ProgressiveWebAppFacts
import mozilla.components.browser.errorpages.ErrorType
import mozilla.components.browser.menu.facts.BrowserMenuFacts
import mozilla.components.browser.search.SearchEngine
Expand Down Expand Up @@ -48,6 +49,7 @@ import org.mozilla.fenix.R
import org.mozilla.fenix.search.awesomebar.ShortcutsSuggestionProvider
import java.util.Locale

@Suppress("LongMethod")
sealed class Event {

// Interaction Events
Expand Down Expand Up @@ -202,7 +204,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<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() {
enum class Position { TOP, BOTTOM }

Expand Down Expand Up @@ -504,6 +520,7 @@ sealed class Event {
get() = null
}

@Suppress("LongMethod")
private fun Fact.toEvent(): Event? = when (Pair(component, item)) {
Component.FEATURE_FINDINPAGE to FindInPageFacts.Items.CLOSE -> Event.FindInPageClosed
Component.FEATURE_FINDINPAGE to FindInPageFacts.Items.INPUT -> Event.FindInPageSearchCommitted
Expand Down Expand Up @@ -582,6 +599,24 @@ private fun Fact.toEvent(): Event? = when (Pair(component, item)) {
}
null
}
Component.FEATURE_PWA to ProgressiveWebAppFacts.Items.HOMESCREEN_ICON_TAP -> {
Event.ProgressiveWebAppOpenFromHomescreenTap
}
Component.FEATURE_PWA to ProgressiveWebAppFacts.Items.INSTALL_SHORTCUT -> {
Event.ProgressiveWebAppInstallAsShortcut
}
Component.FEATURE_PWA to ProgressiveWebAppFacts.Items.ENTER_BACKGROUND -> {
metadata?.get(ProgressiveWebAppFacts.MetadataKeys.BACKGROUND_TIME)?.let { duration ->
require(duration is Long) { "Expected duration to be a Long" }
Event.ProgressiveWebAppBackground(duration)
}
}
Component.FEATURE_PWA to ProgressiveWebAppFacts.Items.ENTER_FOREGROUND -> {
metadata?.get(ProgressiveWebAppFacts.MetadataKeys.FOREGROUND_TIME)?.let { duration ->
require(duration is Long) { "Expected duration to be a Long" }
Event.ProgressiveWebAppForeground(duration)
}
}
else -> null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,12 @@ import org.mozilla.fenix.components.TopSiteStorage
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.getRootView
import org.mozilla.fenix.ext.metrics
import org.mozilla.fenix.ext.nav
import org.mozilla.fenix.ext.navigateSafe
import org.mozilla.fenix.ext.sessionsOfType
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.settings.deletebrowsingdata.deleteAndQuit
import org.mozilla.fenix.utils.Do
import kotlin.coroutines.coroutineContext

/**
* An interface that handles the view manipulation of the BrowserToolbar, triggered by the Interactor
Expand Down Expand Up @@ -229,7 +227,6 @@ class DefaultBrowserToolbarController(
with(activity.components.useCases.webAppUseCases) {
if (isInstallable()) {
addToHomescreen()
activity.metrics.track(Event.ProgressiveWebAppAddToHomescreenTap)
} else {
val directions =
BrowserFragmentDirections.actionBrowserFragmentToCreateShortcutFragment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,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
Expand Down Expand Up @@ -137,6 +139,7 @@ class ExternalAppBrowserFragment : BaseBrowserFragment(), UserInteractionHandler
)
)
)
activity.metrics.track(Event.ProgressiveWebAppOpenFromHomescreenTap)
} else {
viewLifecycleOwner.lifecycle.addObserver(
PoweredByNotification(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import androidx.lifecycle.lifecycleScope
import kotlinx.android.synthetic.main.fragment_create_shortcut.*
import kotlinx.coroutines.launch
import org.mozilla.fenix.R
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.metrics
import org.mozilla.fenix.ext.requireComponents

/**
Expand All @@ -40,7 +38,9 @@ class PwaOnboardingDialogFragment : DialogFragment() {
add_button.setOnClickListener {
viewLifecycleOwner.lifecycleScope.launch {
components.useCases.webAppUseCases.addToHomescreen()
}.invokeOnCompletion { dismiss() }
}.invokeOnCompletion {
dismiss()
}
}
}
}
4 changes: 4 additions & 0 deletions docs/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,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)|<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_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 | |
Expand Down

0 comments on commit 3cef53d

Please sign in to comment.