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

Commit

Permalink
Closes #11909: Metrics for recording number of recently used PWAs
Browse files Browse the repository at this point in the history
  • Loading branch information
Grisha Kruglov committed Jun 26, 2020
1 parent 0fb9857 commit 4ecc9d3
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 4 deletions.
37 changes: 37 additions & 0 deletions app/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,43 @@ metrics:
notification_emails:
- [email protected]
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:
- [email protected]
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:
- [email protected]
expires: "2020-12-01"
search_count:
type: labeled_counter
description: |
Expand Down
26 changes: 26 additions & 0 deletions app/src/main/java/org/mozilla/fenix/HomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -188,6 +191,8 @@ open class HomeActivity : LocaleAwareAppCompatActivity() {
intent.removeExtra(START_IN_RECENTS_SCREEN)
moveTaskToBack(true)
}

captureSnapshotTelemetryMetrics()
}

@CallSuper
Expand Down Expand Up @@ -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.
Expand All @@ -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
}
}
10 changes: 6 additions & 4 deletions docs/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ The following metrics are added to the ping:
| collections.tab_select_opened |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user opened the select tabs screen (the first step of the collection creation flow) |[1](https://github.com/mozilla-mobile/fenix/pull/3935)||2020-09-01 |
| collections.tabs_added |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user saved a list of tabs to an existing collection |[1](https://github.com/mozilla-mobile/fenix/pull/3935)|<ul><li>tabs_open: The number of tabs open in the current session</li><li>tabs_selected: The number of tabs added to the collection</li></ul>|2020-09-01 |
| context_menu.item_tapped |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user tapped an item in the browsers context menu |[1](https://github.com/mozilla-mobile/fenix/pull/1344#issuecomment-479285010)|<ul><li>named: The name of the item that was tapped. Available items are: ``` open_in_new_tab, open_in_private_tab, open_image_in_new_tab, save_image, share_link, copy_link, copy_image_location ``` </li></ul>|2020-09-01 |
| contextual_hint.tracking_protection.dismiss |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |The enhanced tracking protection contextual hint was dismissed by pressing the close button |[1](https://github.com/mozilla-mobile/fenix/pull/TODO)||2020-09-01 |
| contextual_hint.tracking_protection.display |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |The enhanced tracking protection contextual hint was displayed. |[1](https://github.com/mozilla-mobile/fenix/pull/TODO)||2020-09-01 |
| contextual_hint.tracking_protection.inside_tap |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |The user tapped inside of the etp contextual hint (which brings up the etp panel for this site). |[1](https://github.com/mozilla-mobile/fenix/pull/TODO)||2020-09-01 |
| contextual_hint.tracking_protection.outside_tap |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |The user tapped outside of the etp contextual hint (which has no effect). |[1](https://github.com/mozilla-mobile/fenix/pull/TODO)||2020-09-01 |
| contextual_hint.tracking_protection.dismiss |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |The enhanced tracking protection contextual hint was dismissed by pressing the close button |[1](https://github.com/mozilla-mobile/fenix/pull/11923)||2020-09-01 |
| contextual_hint.tracking_protection.display |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |The enhanced tracking protection contextual hint was displayed. |[1](https://github.com/mozilla-mobile/fenix/pull/11923)||2020-09-01 |
| contextual_hint.tracking_protection.inside_tap |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |The user tapped inside of the etp contextual hint (which brings up the etp panel for this site). |[1](https://github.com/mozilla-mobile/fenix/pull/11923)||2020-09-01 |
| contextual_hint.tracking_protection.outside_tap |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |The user tapped outside of the etp contextual hint (which has no effect). |[1](https://github.com/mozilla-mobile/fenix/pull/11923)||2020-09-01 |
| crash_reporter.closed |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |The crash reporter was closed |[1](https://github.com/mozilla-mobile/fenix/pull/1214#issue-264756708)|<ul><li>crash_submitted: A boolean that tells us whether or not the user submitted a crash report </li></ul>|2020-09-01 |
| crash_reporter.opened |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |The crash reporter was displayed |[1](https://github.com/mozilla-mobile/fenix/pull/1214#issue-264756708)||2020-09-01 |
| custom_tab.action_button |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user pressed the action button provided by the launching app |[1](https://github.com/mozilla-mobile/fenix/pull/1697)||2020-09-01 |
Expand Down Expand Up @@ -251,8 +251,10 @@ The following metrics are added to the ping:
| metrics.adjust_network |[string](https://mozilla.github.io/glean/book/user/metrics/string.html) |A string containing the Adjust network ID from which the user installed Fenix. This will not send on the first session the user runs. If the install is organic, this will be empty. |[1](https://github.com/mozilla-mobile/fenix/pull/9253)||2020-09-01 |
| metrics.default_browser |[boolean](https://mozilla.github.io/glean/book/user/metrics/boolean.html) |Is Fenix the default browser? |[1](https://github.com/mozilla-mobile/fenix/pull/1067#issuecomment-474598673)||2020-09-01 |
| metrics.default_moz_browser |[string](https://mozilla.github.io/glean/book/user/metrics/string.html) |The name of the default browser on device if and only if it's a Mozilla owned product |[1](https://github.com/mozilla-mobile/fenix/pull/1953/), [2](https://github.com/mozilla-mobile/fenix/pull/5216)||2020-09-01 |
| metrics.has_recent_pwas |[boolean](https://mozilla.github.io/glean/book/user/metrics/boolean.html) |A boolean that indicates if the user has recently used PWAs. See recently_used_pwa_count for the actual count. |[1](https://github.com/mozilla-mobile/fenix/pull/11982#pullrequestreview-437963817)||2020-12-01 |
| metrics.has_top_sites |[boolean](https://mozilla.github.io/glean/book/user/metrics/boolean.html) |A boolean that indicates if the user has top sites |[1](https://github.com/mozilla-mobile/fenix/pull/9556)||2020-09-01 |
| metrics.mozilla_products |[string_list](https://mozilla.github.io/glean/book/user/metrics/string_list.html) |A list of all the Mozilla products installed on device. We currently scan for: Firefox, Firefox Beta, Firefox Aurora, Firefox Nightly, Firefox Fdroid, Firefox Lite, Reference Browser, Reference Browser Debug, Fenix, Focus, and Lockwise. |[1](https://github.com/mozilla-mobile/fenix/pull/1953/), [2](https://github.com/mozilla-mobile/fenix/pull/5216)||2020-09-01 |
| metrics.recently_used_pwa_count |[counter](https://mozilla.github.io/glean/book/user/metrics/counter.html) |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`. |[1](https://github.com/mozilla-mobile/fenix/pull/11982#pullrequestreview-437963817)||2020-12-01 |
| metrics.search_count |[labeled_counter](https://mozilla.github.io/glean/book/user/metrics/labeled_counters.html) |The labels for this counter are `<search-engine-name>.<source>`. If the search engine is bundled with Fenix `search-engine-name` will be the name of the search engine. If it's a custom search engine (defined: https://github.com/mozilla-mobile/fenix/issues/1607) the value will be `custom`. `source` will be: `action`, `suggestion`, `widget` or `shortcut` (depending on the source from which the search started). Also added the `other` option for the source but it should never enter on this case. |[1](https://github.com/mozilla-mobile/fenix/pull/1677), [2](https://github.com/mozilla-mobile/fenix/pull/5216), [3](https://github.com/mozilla-mobile/fenix/pull/7310)||2020-09-01 |
| metrics.search_widget_installed |[boolean](https://mozilla.github.io/glean/book/user/metrics/boolean.html) |Whether or not the search widget is installed |[1](https://github.com/mozilla-mobile/fenix/pull/10958)||2020-09-01 |
| metrics.toolbar_position |[string](https://mozilla.github.io/glean/book/user/metrics/string.html) |A string that indicates the new position of the toolbar TOP or BOTTOM |[1](https://github.com/mozilla-mobile/fenix/pull/6608)||2020-09-01 |
Expand Down

0 comments on commit 4ecc9d3

Please sign in to comment.