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

Commit

Permalink
Add events pings to fragments
Browse files Browse the repository at this point in the history
  • Loading branch information
Elise Richards committed Jul 20, 2020
1 parent 221569e commit 7a7b8c6
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ 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>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ sealed class Event {
object TabsTrayShareAllTabsPressed : Event()
object TabsTrayCloseAllTabsPressed : Event()

object ProgressiveWebAppHomescreenTap : Event()
object ProgressiveWebAppOpenFromHomescreenTap : Event()
object ProgressiveWebAppInstallMenuTap : Event()
object ProgressiveWebAppAddToHomescreenTap : Event()

Expand Down Expand Up @@ -599,7 +599,7 @@ private fun Fact.toEvent(): Event? = when (Pair(component, item)) {
null
}
Component.FEATURE_PWA to ProgressiveWebAppFacts.Items.HOMESCREEN_ICON_TAP -> {
Event.ProgressiveWebAppHomescreenTap
Event.ProgressiveWebAppOpenFromHomescreenTap
}
Component.FEATURE_PWA to ProgressiveWebAppFacts.Items.ENTER_BACKGROUND -> {
metadata?.get(ProgressiveWebAppFacts.MetadataKeys.BACKGROUND_TIME)?.let { duration ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ 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 @@ -208,7 +207,7 @@ class DefaultBrowserToolbarController(
.show()
}
}
ToolbarMenu.Item.AddToHomeScreen, ToolbarMenu.Item.InstallToHomeScreen -> {
ToolbarMenu.Item.AddToHomeScreen -> {
activity.settings().installPwaOpened = true
MainScope().launch {
with(activity.components.useCases.webAppUseCases) {
Expand All @@ -223,6 +222,21 @@ class DefaultBrowserToolbarController(
}
}
}
ToolbarMenu.Item.InstallToHomeScreen -> {
activity.settings().installPwaOpened = true
MainScope().launch {
with(activity.components.useCases.webAppUseCases) {
if (isInstallable()) {
addToHomescreen()
activity.metrics.track(Event.ProgressiveWebAppInstallMenuTap)
} else {
val directions =
BrowserFragmentDirections.actionBrowserFragmentToCreateShortcutFragment()
navController.navigateSafe(R.id.browserFragment, directions)
}
}
}
}
ToolbarMenu.Item.Share -> {
val directions = NavGraphDirections.actionGlobalShareFragment(
data = arrayOf(
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 @@ -40,7 +40,10 @@ class PwaOnboardingDialogFragment : DialogFragment() {
add_button.setOnClickListener {
viewLifecycleOwner.lifecycleScope.launch {
components.useCases.webAppUseCases.addToHomescreen()
}.invokeOnCompletion { dismiss() }
requireContext().metrics.track(Event.ProgressiveWebAppAddToHomescreenTap)
}.invokeOnCompletion {
dismiss()
}
}
}
}

0 comments on commit 7a7b8c6

Please sign in to comment.