1
0
Fork 0

Closes #11909: Metrics for recording number of recently used PWAs

master
Grisha Kruglov 2020-06-25 17:35:52 -07:00 committed by Grisha Kruglov
parent eeabcb10ff
commit f8cb1d6b48
3 changed files with 65 additions and 0 deletions

View File

@ -497,6 +497,43 @@ metrics:
notification_emails:
- fenix-core@mozilla.com
expires: "2020-09-01"
recently_used_pwa_count:
type: counter
lifetime: application
description: |
A counter that indicates how many PWAs a user has recently used.
Threshold for "recency" set in HomeActivity#PWA_RECENTLY_USED_THRESHOLD.
Currently we are not told by the OS when a PWA is removed by the user,
so we use the "recently used" heuristic to judge how many PWAs are still
active, as a proxy for "installed". This value will only be set if the
user has at least *one* recently used PWA. If they have 0, this metric
will not be sent, resulting in a null value during analysis on the
server-side. To disambiguate between a failed `recently_used_pwa_count`
metric and 0 recent PWAs, please see `has_recent_pwas`.
send_in_pings:
- metrics
bugs:
- https://github.com/mozilla-mobile/fenix/issues/11909
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/11982#pullrequestreview-437963817
notification_emails:
- fenix-core@mozilla.com
expires: "2020-12-01"
has_recent_pwas:
type: boolean
lifetime: application
description: |
A boolean that indicates if the user has recently used PWAs.
See recently_used_pwa_count for the actual count.
send_in_pings:
- metrics
bugs:
- https://github.com/mozilla-mobile/fenix/issues/11909
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/11982#pullrequestreview-437963817
notification_emails:
- fenix-core@mozilla.com
expires: "2020-12-01"
search_count:
type: labeled_counter
description: |

View File

@ -8,6 +8,7 @@ import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.os.StrictMode
import android.text.format.DateUtils
import android.util.AttributeSet
import android.view.View
import android.view.WindowManager
@ -27,6 +28,7 @@ import androidx.navigation.ui.NavigationUI
import androidx.recyclerview.widget.LinearLayoutManager
import kotlinx.android.synthetic.main.activity_home.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import mozilla.components.browser.search.SearchEngine
import mozilla.components.browser.session.Session
@ -50,6 +52,7 @@ import mozilla.components.support.locale.LocaleAwareAppCompatActivity
import mozilla.components.support.utils.SafeIntent
import mozilla.components.support.utils.toSafeIntent
import mozilla.components.support.webextensions.WebExtensionPopupFeature
import org.mozilla.fenix.GleanMetrics.Metrics
import org.mozilla.fenix.browser.UriOpenedObserver
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
import org.mozilla.fenix.browser.browsingmode.BrowsingModeManager
@ -188,6 +191,8 @@ open class HomeActivity : LocaleAwareAppCompatActivity() {
intent.removeExtra(START_IN_RECENTS_SCREEN)
moveTaskToBack(true)
}
captureSnapshotTelemetryMetrics()
}
@CallSuper
@ -523,6 +528,23 @@ open class HomeActivity : LocaleAwareAppCompatActivity() {
this.visualCompletenessQueue = visualCompletenessQueue
}
private fun captureSnapshotTelemetryMetrics() = CoroutineScope(Dispatchers.IO).launch {
// PWA
val recentlyUsedPwaCount = components.core.webAppShortcutManager.recentlyUsedWebAppsCount(
activeThresholdMs = PWA_RECENTLY_USED_THRESHOLD
)
if (recentlyUsedPwaCount == 0) {
Metrics.hasRecentPwas.set(false)
} else {
Metrics.hasRecentPwas.set(true)
// This metric's lifecycle is set to 'application', meaning that it gets reset upon
// application restart. Combined with the behaviour of the metric type itself (a growing counter),
// it's important that this metric is only set once per application's lifetime.
// Otherwise, we're going to over-count.
Metrics.recentlyUsedPwaCount.add(recentlyUsedPwaCount)
}
}
@VisibleForTesting
internal fun isActivityColdStarted(startingIntent: Intent, activityIcicle: Bundle?): Boolean =
// First time opening this activity in the task.
@ -541,5 +563,9 @@ open class HomeActivity : LocaleAwareAppCompatActivity() {
const val EXTRA_OPENED_FROM_NOTIFICATION = "notification_open"
const val delay = 5000L
const val START_IN_RECENTS_SCREEN = "start_in_recents_screen"
// PWA must have been used within last 30 days to be considered "recently used" for the
// telemetry purposes.
const val PWA_RECENTLY_USED_THRESHOLD = DateUtils.DAY_IN_MILLIS * 30L
}
}

File diff suppressed because one or more lines are too long