From 4b9cc954fa670f14bfec4c81617d44f65c849a40 Mon Sep 17 00:00:00 2001 From: Sachin Date: Fri, 26 Jun 2020 17:38:08 -0700 Subject: [PATCH] for #11830 added new metric for collecting startup method from all startup phases (#11940) * for #11830 added new metric for collecting startup method move all source startup telemetry into its own logic and added an UNKOWN state * switched back to onNewIntent solution * renamed the metric --- app/metrics.yaml | 26 +++++++++++++++++++ .../java/org/mozilla/fenix/HomeActivity.kt | 25 ++++++++++++++++-- .../components/metrics/GleanMetricsService.kt | 4 +++ .../fenix/components/metrics/Metrics.kt | 7 +++++ .../customtabs/ExternalAppBrowserActivity.kt | 2 ++ docs/metrics.md | 1 + 6 files changed, 63 insertions(+), 2 deletions(-) diff --git a/app/metrics.yaml b/app/metrics.yaml index e61bdcc16..ab66f5cae 100644 --- a/app/metrics.yaml +++ b/app/metrics.yaml @@ -8,6 +8,32 @@ no_lint: - CATEGORY_GENERIC events: + app_received_intent: + type: event + description: | + The system received an Intent for the HomeActivity. An intent + is received an external entity wants to the app to display + content. Intents can be received when the app is closed – at + which point the app will be opened – or when the app is + already opened – at which point the already open app will make + changes such as loading a url. This can be used loosely as a + heuristic for when the user requested to open the app. The + HomeActivity encompasses the home screen and browser screen but + may include other screens. This differs from the app_opened + probe because it measures all startups, not just cold startup. + extra_keys: + source: + description: | + The method used to open Fenix. Possible values are `app_icon`, + `custom_tab`, `link` or `unknown` + bugs: + - https://github.com/mozilla-mobile/fenix/issues/11830 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/11940/ + notification_emails: + - esmyth@mozilla.com + - perf-android-fe@mozilla.com + expires: "2020-12-01" app_opened: type: event description: | diff --git a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt index a80def5b0..d8c5c7124 100644 --- a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt +++ b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt @@ -174,10 +174,14 @@ open class HomeActivity : LocaleAwareAppCompatActivity() { lifecycle.addObserver(BreadcrumbsRecorder(components.analytics.crashReporter, navHost.navController, ::getBreadcrumbMessage)) - intent - ?.toSafeIntent() + val safeIntent = intent?.toSafeIntent() + safeIntent ?.let(::getIntentSource) ?.also { components.analytics.metrics.track(Event.OpenedApp(it)) } + // record on cold startup + safeIntent + ?.let(::getIntentAllSource) + ?.also { components.analytics.metrics.track(Event.AppRecievedIntent(it)) } } supportActionBar?.hide() @@ -250,6 +254,15 @@ open class HomeActivity : LocaleAwareAppCompatActivity() { ?.let { it as? TabTrayDialogFragment } ?.also { it.dismissAllowingStateLoss() } } + + // If there is a warm or hot startup, onNewIntent method is always called first. + // Note: This does not work in case of an user sending an intent with ACTION_VIEW + // for example, launch the application, and than use adb to send an intent with + // ACTION_VIEW to open a link. In this case, we will get multiple telemetry events. + intent + .toSafeIntent() + .let(::getIntentAllSource) + ?.also { components.analytics.metrics.track(Event.AppRecievedIntent(it)) } } /** @@ -320,6 +333,14 @@ open class HomeActivity : LocaleAwareAppCompatActivity() { } } + protected open fun getIntentAllSource(intent: SafeIntent): Event.AppRecievedIntent.Source? { + return when { + intent.isLauncherIntent -> Event.AppRecievedIntent.Source.APP_ICON + intent.action == Intent.ACTION_VIEW -> Event.AppRecievedIntent.Source.LINK + else -> Event.AppRecievedIntent.Source.UNKNOWN + } + } + /** * External sources such as 3rd party links and shortcuts use this function to enter * private mode directly before the content view is created. Returns the mode set by the intent diff --git a/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt index 6ad4107f0..043cfed25 100644 --- a/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt @@ -97,6 +97,10 @@ private val Event.wrapper: EventWrapper<*>? { Events.appOpened.record(it) }, { Events.appOpenedKeys.valueOf(it) } ) + is Event.AppRecievedIntent -> EventWrapper( + { Events.appReceivedIntent.record(it) }, + { Events.appReceivedIntentKeys.valueOf(it) } + ) is Event.SearchBarTapped -> EventWrapper( { Events.searchBarTapped.record(it) }, { Events.searchBarTappedKeys.valueOf(it) } diff --git a/app/src/main/java/org/mozilla/fenix/components/metrics/Metrics.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/Metrics.kt index 50da78067..007dd1536 100644 --- a/app/src/main/java/org/mozilla/fenix/components/metrics/Metrics.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/Metrics.kt @@ -309,6 +309,13 @@ sealed class Event { get() = hashMapOf(Events.appOpenedKeys.source to source.name) } + data class AppRecievedIntent(val source: Source) : Event() { + enum class Source { APP_ICON, LINK, CUSTOM_TAB, UNKNOWN } + + override val extras: Map? + get() = hashMapOf(Events.appReceivedIntentKeys.source to source.name) + } + data class CollectionSaveButtonPressed(val fromScreen: String) : Event() { override val extras: Map? get() = mapOf(Collections.saveButtonKeys.fromScreen to fromScreen) diff --git a/app/src/main/java/org/mozilla/fenix/customtabs/ExternalAppBrowserActivity.kt b/app/src/main/java/org/mozilla/fenix/customtabs/ExternalAppBrowserActivity.kt index 7e1e20c6c..2914f7326 100644 --- a/app/src/main/java/org/mozilla/fenix/customtabs/ExternalAppBrowserActivity.kt +++ b/app/src/main/java/org/mozilla/fenix/customtabs/ExternalAppBrowserActivity.kt @@ -41,6 +41,8 @@ open class ExternalAppBrowserActivity : HomeActivity() { final override fun getIntentSource(intent: SafeIntent) = Event.OpenedApp.Source.CUSTOM_TAB + final override fun getIntentAllSource(intent: SafeIntent) = Event.AppRecievedIntent.Source.CUSTOM_TAB + final override fun getIntentSessionId(intent: SafeIntent) = intent.getSessionId() override fun getNavDirections( diff --git a/docs/metrics.md b/docs/metrics.md index aa17d6773..22c7f6dbb 100644 --- a/docs/metrics.md +++ b/docs/metrics.md @@ -100,6 +100,7 @@ The following metrics are added to the ping: | download_notification.try_again |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user tapped on try again when a download fails in the download notification |[1](https://github.com/mozilla-mobile/fenix/pull/6554)||2020-09-01 | | error_page.visited_error |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user encountered an error page |[1](https://github.com/mozilla-mobile/fenix/pull/2491#issuecomment-492414486)|
  • error_type: The error type of the error page encountered
|2020-09-01 | | events.app_opened |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user opened the app (from cold start, to the homescreen or browser) |[1](https://github.com/mozilla-mobile/fenix/pull/1067#issuecomment-474598673)|
  • source: The method used to open Fenix. Possible values are: `app_icon`, `custom_tab` or `link`
|2020-09-01 | +| events.app_opened_all_startup |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user opened the app to the HomeActivity. The HomeActivity encompasses the home screen and browser screen but may include other screens. This differs from the app_opened probe because it measures all startups, not just cold startup. |[1](https://github.com/mozilla-mobile/fenix/pull/11940/)|
  • source: The method used to open Fenix. Possible values are `app_icon`, `custom_tab`, `link` or `unknown`
|2020-12-01 | | events.browser_menu_action |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A browser menu item was tapped |[1](https://github.com/mozilla-mobile/fenix/pull/1214#issue-264756708), [2](https://github.com/mozilla-mobile/fenix/pull/5098#issuecomment-529658996), [3](https://github.com/mozilla-mobile/fenix/pull/6310)|
  • item: A string containing the name of the item the user tapped. These items include: Settings, Help, Desktop Site toggle on/off, Find in Page, New Tab, Private Tab, Share, Report Site Issue, Back/Forward button, Reload Button, Quit, Reader Mode On, Reader Mode Off, Open In app, Add To Top Sites, Add-ons Manager, Bookmarks, History
|2020-09-01 | | events.entered_url |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user entered a url |[1](https://github.com/mozilla-mobile/fenix/pull/1067#issuecomment-474598673)|
  • autocomplete: A boolean that tells us whether the URL was autofilled by an Autocomplete suggestion
|2020-09-01 | | events.opened_link |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user opened a link with Fenix |[1](https://github.com/mozilla-mobile/fenix/pull/5975)|
  • mode: The mode the link was opened in. Either 'PRIVATE' or 'NORMAL'.
|2020-09-01 |