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

Commit

Permalink
Allow onPause in base fragment to send telemetry for PWA in the exter…
Browse files Browse the repository at this point in the history
…nal app fragment. Track foreground and bg locally in fenix, and route install and home screen taps from AC facts
  • Loading branch information
Elise Richards committed Jul 28, 2020
1 parent 3cef53d commit ca9687d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,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()
Expand Down
12 changes: 0 additions & 12 deletions app/src/main/java/org/mozilla/fenix/components/metrics/Metrics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -605,18 +605,6 @@ private fun Fact.toEvent(): Event? = when (Pair(component, item)) {
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 @@ -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
Expand Down Expand Up @@ -139,7 +140,6 @@ class ExternalAppBrowserFragment : BaseBrowserFragment(), UserInteractionHandler
)
)
)
activity.metrics.track(Event.ProgressiveWebAppOpenFromHomescreenTap)
} else {
viewLifecycleOwner.lifecycle.addObserver(
PoweredByNotification(
Expand All @@ -153,6 +153,20 @@ class ExternalAppBrowserFragment : BaseBrowserFragment(), UserInteractionHandler
}
}

override fun onResume() {
super.onResume()
requireComponents.analytics.metrics.track(
Event.ProgressiveWebAppForeground(SystemClock.elapsedRealtimeNanos())
)
}

override fun onPause() {
super.onPause()
requireComponents.analytics.metrics.track(
Event.ProgressiveWebAppBackground(SystemClock.elapsedRealtimeNanos())
)
}

override fun removeSessionIfNeeded(): Boolean {
return customTabsIntegration.onBackPressed() || super.removeSessionIfNeeded()
}
Expand Down

0 comments on commit ca9687d

Please sign in to comment.