Skip to content

Commit

Permalink
for mozilla-mobile#11830 added new metric for collecting startup method
Browse files Browse the repository at this point in the history
for mozilla-mobile#11830 collecting startup metric inaside onNewIntent in HomeActivity

clean up, added comments
  • Loading branch information
sraturi committed Jun 25, 2020
1 parent b84f55c commit 3b6ffda
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 3 deletions.
17 changes: 17 additions & 0 deletions app/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@ no_lint:
- CATEGORY_GENERIC

events:
app_opened_all_startup:
type: event
description: |
A user opened the app from any one of the following flow
hot, warm or cold start to the homescreen.
extra_keys:
source:
description: |
The method used to open Fenix. Possible values are `app_icon`,
`custom_tab` or `link`
bugs:
- https://github.com/mozilla-mobile/fenix/issues/11830
data_reviews:
- NA
notification_emails:
- [email protected]
expires: "2020-12-01"
app_opened:
type: event
description: |
Expand Down
30 changes: 27 additions & 3 deletions app/src/main/java/org/mozilla/fenix/HomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,16 @@ open class HomeActivity : LocaleAwareAppCompatActivity() {
if (settings().isTelemetryEnabled) {
lifecycle.addObserver(BreadcrumbsRecorder(components.analytics.crashReporter,
navHost.navController, ::getBreadcrumbMessage))

intent
?.toSafeIntent()
// reporting cold startup
val safeIntent = intent?.toSafeIntent()
safeIntent
?.let(::getIntentSource)
?.also { components.analytics.metrics.track(Event.OpenedApp(it)) }
safeIntent
?.let(::getIntentStartSource)
?.also {
components.analytics.metrics.track(Event.OpenedAppAllStart(it))
}
}
supportActionBar?.hide()

Expand Down Expand Up @@ -236,6 +241,16 @@ open class HomeActivity : LocaleAwareAppCompatActivity() {
val intentHandled = intentProcessors.any { it.process(intent, navHost.navController, this.intent) }
browsingModeManager.mode = getModeFromIntentOrLastKnown(intent)

if (settings().isTelemetryEnabled) {
/* If there is a warm or hot startup, onNewIntent method is always called first.
* we use the new intent to record how the app was started rather than the
* original activity intent */
intent.toSafeIntent()
.let(::getIntentStartSource)
?.also {
components.analytics.metrics.track(Event.OpenedAppAllStart(it))
}
}
if (intentHandled) {
supportFragmentManager
.primaryNavigationFragment
Expand Down Expand Up @@ -315,6 +330,15 @@ open class HomeActivity : LocaleAwareAppCompatActivity() {
}
}

@VisibleForTesting(otherwise = PROTECTED)
internal open fun getIntentStartSource(intent: SafeIntent): Event.OpenedAppAllStart.Source? {
return when {
intent.isLauncherIntent -> Event.OpenedAppAllStart.Source.APP_ICON
intent.action == Intent.ACTION_VIEW -> Event.OpenedAppAllStart.Source.LINK
else -> null
}
}

/**
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ private val Event.wrapper: EventWrapper<*>?
{ Events.appOpened.record(it) },
{ Events.appOpenedKeys.valueOf(it) }
)
is Event.OpenedAppAllStart -> EventWrapper(
{ Events.appOpenedAllStartup.record(it) },
{ Events.appOpenedAllStartupKeys.valueOf(it) }
)
is Event.SearchBarTapped -> EventWrapper(
{ Events.searchBarTapped.record(it) },
{ Events.searchBarTappedKeys.valueOf(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,12 @@ sealed class Event {
override val extras: Map<Events.appOpenedKeys, String>?
get() = hashMapOf(Events.appOpenedKeys.source to source.name)
}
data class OpenedAppAllStart(val source: Source) : Event() {
enum class Source { APP_ICON, LINK, CUSTOM_TAB }

override val extras: Map<Events.appOpenedKeys, String>?
get() = hashMapOf(Events.appOpenedKeys.source to source.name)
}

data class CollectionSaveButtonPressed(val fromScreen: String) : Event() {
override val extras: Map<Collections.saveButtonKeys, String>?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ open class ExternalAppBrowserActivity : HomeActivity() {

final override fun getIntentSource(intent: SafeIntent) = Event.OpenedApp.Source.CUSTOM_TAB

final override fun getIntentStartSource(intent: SafeIntent) = Event.OpenedAppAllStart.Source.CUSTOM_TAB

final override fun getIntentSessionId(intent: SafeIntent) = intent.getSessionId()

override fun getNavDirections(
Expand Down
1 change: 1 addition & 0 deletions docs/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)|<ul><li>error_type: The error type of the error page encountered</li></ul>|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)|<ul><li>source: The method used to open Fenix. Possible values are: `app_icon`, `custom_tab` or `link` </li></ul>|2020-09-01 |
| events.app_opened_all_startup |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user opened the app from any one of the following flow hot, warm or cold start to the homescreen. |[1](NA)|<ul><li>source: The method used to open Fenix. Possible values are `app_icon`, `custom_tab` or `link` </li></ul>|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)|<ul><li>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 </li></ul>|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)|<ul><li>autocomplete: A boolean that tells us whether the URL was autofilled by an Autocomplete suggestion </li></ul>|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)|<ul><li>mode: The mode the link was opened in. Either 'PRIVATE' or 'NORMAL'. </li></ul>|2020-09-01 |
Expand Down

0 comments on commit 3b6ffda

Please sign in to comment.