diff --git a/app/metrics.yaml b/app/metrics.yaml index 61bcfead0..038fa418e 100644 --- a/app/metrics.yaml +++ b/app/metrics.yaml @@ -4291,6 +4291,47 @@ tabs: - fenix-core@mozilla.com expires: "2021-08-01" +banner_open_in_app: + displayed: + type: event + description: | + Open in App banner was shown. + bugs: + - https://github.com/mozilla-mobile/fenix/issues/16828 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/17049 + data_sensitivity: + - interaction + notification_emails: + - fenix-core@mozilla.com + expires: "2021-08-01" + dismissed: + type: event + description: | + User tapped 'dismiss' on Open in App banner. + bugs: + - https://github.com/mozilla-mobile/fenix/issues/16828 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/17049 + data_sensitivity: + - interaction + notification_emails: + - fenix-core@mozilla.com + expires: "2021-08-01" + go_to_settings: + type: event + description: | + User tapped 'go to settings' on Open in App banner. + bugs: + - https://github.com/mozilla-mobile/fenix/issues/16828 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/17049 + data_sensitivity: + - interaction + notification_emails: + - fenix-core@mozilla.com + expires: "2021-08-01" + contextual_menu: copy_tapped: type: event diff --git a/app/src/main/java/org/mozilla/fenix/browser/OpenInAppOnboardingObserver.kt b/app/src/main/java/org/mozilla/fenix/browser/OpenInAppOnboardingObserver.kt index 1d129a027..65cb98795 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/OpenInAppOnboardingObserver.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/OpenInAppOnboardingObserver.kt @@ -22,6 +22,9 @@ import mozilla.components.support.base.feature.LifecycleAwareFeature import mozilla.components.support.ktx.kotlin.tryGetHostFromUrl import mozilla.components.support.ktx.kotlinx.coroutines.flow.ifAnyChanged import org.mozilla.fenix.R +import org.mozilla.fenix.components.metrics.Event +import org.mozilla.fenix.components.metrics.Event.BannerOpenInAppGoToSettings +import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.nav import org.mozilla.fenix.utils.Settings @@ -85,6 +88,7 @@ class OpenInAppOnboardingObserver( infoBanner?.showBanner() sessionDomainForDisplayedBanner = url.tryGetHostFromUrl() settings.shouldShowOpenInAppBanner = false + context.components.analytics.metrics.track(Event.BannerOpenInAppDisplayed) } } @@ -95,12 +99,18 @@ class OpenInAppOnboardingObserver( message = context.getString(R.string.open_in_app_cfr_info_message), dismissText = context.getString(R.string.open_in_app_cfr_negative_button_text), actionText = context.getString(R.string.open_in_app_cfr_positive_button_text), - container = container + container = container, + dismissAction = ::dismissAction ) { val directions = BrowserFragmentDirections.actionBrowserFragmentToSettingsFragment( preferenceToScrollTo = context.getString(R.string.pref_key_open_links_in_external_app) ) + context.components.analytics.metrics.track(BannerOpenInAppGoToSettings) navController.nav(R.id.browserFragment, directions) } } + + private fun dismissAction() { + context.components.analytics.metrics.track(Event.BannerOpenInAppDismissed) + } } diff --git a/app/src/main/java/org/mozilla/fenix/components/metrics/Event.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/Event.kt index a6e43ea03..983d228df 100644 --- a/app/src/main/java/org/mozilla/fenix/components/metrics/Event.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/Event.kt @@ -200,6 +200,10 @@ sealed class Event { object HaveOpenTabs : Event() object HaveNoOpenTabs : Event() + object BannerOpenInAppDisplayed : Event() + object BannerOpenInAppDismissed : Event() + object BannerOpenInAppGoToSettings : Event() + object ContextMenuCopyTapped : Event() object ContextMenuSearchTapped : Event() object ContextMenuSelectAllTapped : Event() 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 3b8da8e11..d1e653f09 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 @@ -17,6 +17,7 @@ import org.mozilla.fenix.GleanMetrics.AboutPage import org.mozilla.fenix.GleanMetrics.Addons import org.mozilla.fenix.GleanMetrics.AppTheme import org.mozilla.fenix.GleanMetrics.Autoplay +import org.mozilla.fenix.GleanMetrics.BannerOpenInApp import org.mozilla.fenix.GleanMetrics.BookmarksManagement import org.mozilla.fenix.GleanMetrics.BrowserSearch import org.mozilla.fenix.GleanMetrics.Collections @@ -733,6 +734,16 @@ private val Event.wrapper: EventWrapper<*>? { Metrics.hasTopSites.set(false) } ) + is Event.BannerOpenInAppDisplayed -> EventWrapper( + { BannerOpenInApp.displayed.record(it) } + ) + is Event.BannerOpenInAppDismissed -> EventWrapper( + { BannerOpenInApp.dismissed.record(it) } + ) + is Event.BannerOpenInAppGoToSettings -> EventWrapper( + { BannerOpenInApp.goToSettings.record(it) } + ) + // Don't record other events in Glean: is Event.AddBookmark -> null is Event.OpenedBookmark -> null diff --git a/app/src/test/java/org/mozilla/fenix/browser/OpenInAppOnboardingObserverTest.kt b/app/src/test/java/org/mozilla/fenix/browser/OpenInAppOnboardingObserverTest.kt index ce0cf7f01..ec8405f3f 100644 --- a/app/src/test/java/org/mozilla/fenix/browser/OpenInAppOnboardingObserverTest.kt +++ b/app/src/test/java/org/mozilla/fenix/browser/OpenInAppOnboardingObserverTest.kt @@ -11,7 +11,9 @@ import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.LifecycleRegistry import androidx.navigation.NavController import io.mockk.every +import io.mockk.just import io.mockk.mockk +import io.mockk.runs import io.mockk.spyk import io.mockk.verify import kotlinx.coroutines.ExperimentalCoroutinesApi @@ -28,6 +30,7 @@ import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith +import org.mozilla.fenix.ext.components import org.mozilla.fenix.helpers.FenixRobolectricTestRunner import org.mozilla.fenix.utils.Settings @@ -138,6 +141,7 @@ class OpenInAppOnboardingObserverTest { every { settings.openLinksInExternalApp } returns false every { settings.shouldShowOpenInAppCfr } returns true every { appLinksUseCases.appLinkRedirect.invoke(any()).hasExternalApp() } returns true + every { context.components.analytics.metrics.track(any()) } just runs store.dispatch(ContentAction.UpdateLoadingStateAction("1", true)).joinBlocking() openInAppOnboardingObserver.start() diff --git a/docs/metrics.md b/docs/metrics.md index c301f0ec6..1ed8a6125 100644 --- a/docs/metrics.md +++ b/docs/metrics.md @@ -55,6 +55,9 @@ The following metrics are added to the ping: | app_theme.dark_theme_selected |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user selected Dark Theme |[1](https://github.com/mozilla-mobile/fenix/pull/7968), [2](https://github.com/mozilla-mobile/fenix/pull/13958#issuecomment-676857877)|
  • source: The source from where dark theme was selected. The source can be 'SETTINGS' or 'ONBOARDING'
|2021-04-01 |2 | | autoplay.setting_changed |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user changed their autoplay setting to either block_cellular, block_audio, or block_all. |[1](https://github.com/mozilla-mobile/fenix/pull/13041#issuecomment-665777411)|
  • autoplay_setting: The new setting for autoplay: block_cellular, block_audio, or block_all.
|2021-02-01 |2 | | autoplay.visited_setting |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user visited the autoplay settings screen |[1](https://github.com/mozilla-mobile/fenix/pull/13041#issuecomment-665777411)||2021-02-01 |2 | +| banner_open_in_app.dismissed |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |User tapped 'dismiss' on Open in App banner. |[1](https://github.com/mozilla-mobile/fenix/pull/17049)||2021-08-01 |2 | +| banner_open_in_app.displayed |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |Open in App banner was shown. |[1](https://github.com/mozilla-mobile/fenix/pull/17049)||2021-08-01 |2 | +| banner_open_in_app.go_to_settings |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |User tapped 'go to settings' on Open in App banner. |[1](https://github.com/mozilla-mobile/fenix/pull/17049)||2021-08-01 |2 | | bookmarks_management.copied |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user copied a bookmark. |[1](https://github.com/mozilla-mobile/fenix/pull/1708), [2](https://github.com/mozilla-mobile/fenix/pull/13958#issuecomment-676857877)||2021-04-01 |2 | | bookmarks_management.edited |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user edited the title and/or URL of an existing bookmark. |[1](https://github.com/mozilla-mobile/fenix/pull/1708), [2](https://github.com/mozilla-mobile/fenix/pull/13958#issuecomment-676857877)||2021-04-01 |2 | | bookmarks_management.folder_add |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user added a new bookmark folder. |[1](https://github.com/mozilla-mobile/fenix/pull/1708), [2](https://github.com/mozilla-mobile/fenix/pull/13958#issuecomment-676857877)||2021-04-01 |2 |