From fd28889d71f9fdfb81abb516745d3dc0a14de74c Mon Sep 17 00:00:00 2001 From: Mugurell Date: Fri, 17 Jun 2022 20:40:29 +0300 Subject: [PATCH] For #25658 - Track the site permissions prompt and user actions Track when the prompt is shown and when the permissions are allowed/denied. --- app/metrics.yaml | 65 +++++++++++++++++++ .../components/metrics/MetricController.kt | 14 ++++ .../metrics/MetricControllerTest.kt | 59 +++++++++++++++++ 3 files changed, 138 insertions(+) diff --git a/app/metrics.yaml b/app/metrics.yaml index 6c2751e299..f5467cf234 100644 --- a/app/metrics.yaml +++ b/app/metrics.yaml @@ -6162,6 +6162,71 @@ autoplay: metadata: tags: - SitePermissions + +site_permissions: + prompt_shown: + type: event + description: | + A prompt for the user to approve site permissions is shown. + extra_keys: + permissions: + description: | + Comma delimited list of permissions to approve. + type: string + bugs: + - https://github.com/mozilla-mobile/fenix/issues/25658 + data_reviews: + - ?????????????? + data_sensitivity: + - interaction + notification_emails: + - android-probes@mozilla.com + expires: 115 + metadata: + tags: + - SitePermissions + permissions_allowed: + type: event + description: | + User approved site permissions. + extra_keys: + permissions: + description: | + Comma delimited list of approved permissions. + type: string + bugs: + - https://github.com/mozilla-mobile/fenix/issues/25658 + data_reviews: + - ?????????????? + data_sensitivity: + - interaction + notification_emails: + - android-probes@mozilla.com + expires: 115 + metadata: + tags: + - SitePermissions + permissions_denied: + type: event + description: | + User denied site permissions. + extra_keys: + permissions: + description: | + Comma delimited list of approved permissions. + type: string + bugs: + - https://github.com/mozilla-mobile/fenix/issues/25658 + data_reviews: + - ?????????????? + data_sensitivity: + - interaction + notification_emails: + - android-probes@mozilla.com + expires: 115 + metadata: + tags: + - SitePermissions storage.stats: query_stats_duration: send_in_pings: diff --git a/app/src/main/java/org/mozilla/fenix/components/metrics/MetricController.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/MetricController.kt index 9f16bfc583..c9502cc9f5 100644 --- a/app/src/main/java/org/mozilla/fenix/components/metrics/MetricController.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/MetricController.kt @@ -21,6 +21,7 @@ import mozilla.components.feature.prompts.facts.CreditCardAutofillDialogFacts import mozilla.components.feature.pwa.ProgressiveWebAppFacts import mozilla.components.feature.search.telemetry.ads.AdsTelemetry import mozilla.components.feature.search.telemetry.incontent.InContentTelemetry +import mozilla.components.feature.sitepermissions.SitePermissionsFacts import mozilla.components.feature.syncedtabs.facts.SyncedTabsFacts import mozilla.components.feature.top.sites.facts.TopSitesFacts import mozilla.components.support.base.Component @@ -44,6 +45,7 @@ import org.mozilla.fenix.GleanMetrics.MediaNotification import org.mozilla.fenix.GleanMetrics.MediaState import org.mozilla.fenix.GleanMetrics.PerfAwesomebar import org.mozilla.fenix.GleanMetrics.ProgressiveWebApp +import org.mozilla.fenix.GleanMetrics.SitePermissions import org.mozilla.fenix.GleanMetrics.SyncedTabs import org.mozilla.fenix.search.awesomebar.ShortcutsSuggestionProvider import org.mozilla.fenix.utils.Settings @@ -293,6 +295,18 @@ internal class ReleaseMetricController( } Unit } + Component.FEATURE_SITEPERMISSIONS to SitePermissionsFacts.Items.PERMISSIONS -> { + when (action) { + Action.DISPLAY -> SitePermissions.promptShown.record(SitePermissions.PromptShownExtra(value)) + Action.CONFIRM -> + SitePermissions.permissionsAllowed.record(SitePermissions.PermissionsAllowedExtra(value)) + Action.CANCEL -> + SitePermissions.permissionsDenied.record(SitePermissions.PermissionsDeniedExtra(value)) + else -> { + // no-op + } + } + } else -> { // no-op diff --git a/app/src/test/java/org/mozilla/fenix/components/metrics/MetricControllerTest.kt b/app/src/test/java/org/mozilla/fenix/components/metrics/MetricControllerTest.kt index 23103f92ef..48b01b72b3 100644 --- a/app/src/test/java/org/mozilla/fenix/components/metrics/MetricControllerTest.kt +++ b/app/src/test/java/org/mozilla/fenix/components/metrics/MetricControllerTest.kt @@ -24,6 +24,7 @@ import mozilla.components.feature.prompts.facts.CreditCardAutofillDialogFacts import mozilla.components.feature.pwa.ProgressiveWebAppFacts import mozilla.components.feature.search.telemetry.ads.AdsTelemetry import mozilla.components.feature.search.telemetry.incontent.InContentTelemetry +import mozilla.components.feature.sitepermissions.SitePermissionsFacts import mozilla.components.feature.syncedtabs.facts.SyncedTabsFacts import mozilla.components.feature.top.sites.facts.TopSitesFacts import mozilla.components.support.base.Component @@ -49,6 +50,7 @@ import org.mozilla.fenix.GleanMetrics.LoginDialog import org.mozilla.fenix.GleanMetrics.MediaNotification import org.mozilla.fenix.GleanMetrics.PerfAwesomebar import org.mozilla.fenix.GleanMetrics.ProgressiveWebApp +import org.mozilla.fenix.GleanMetrics.SitePermissions import org.mozilla.fenix.GleanMetrics.SyncedTabs import org.mozilla.fenix.components.metrics.ReleaseMetricController.Companion import org.mozilla.fenix.helpers.FenixRobolectricTestRunner @@ -755,4 +757,61 @@ class MetricControllerTest { assertEquals(2, BrowserSearch.inContent["provider"].testGetValue()) } + + @Test + fun `GIVEN a site permissions prompt is shown WHEN processing the fact THEN the right metric is recorded`() { + val controller = ReleaseMetricController(emptyList(), { true }, { true }, mockk()) + val fact = Fact( + component = Component.FEATURE_SITEPERMISSIONS, + action = Action.DISPLAY, + item = SitePermissionsFacts.Items.PERMISSIONS, + value = "test" + ) + assertNull(SitePermissions.promptShown.testGetValue()) + + controller.run { + fact.process() + } + + assertEquals(1, SitePermissions.promptShown.testGetValue()!!.size) + assertEquals("test", SitePermissions.promptShown.testGetValue()!!.single().extra!!["permissions"]) + } + + @Test + fun `GIVEN site permissions are allowed WHEN processing the fact THEN the right metric is recorded`() { + val controller = ReleaseMetricController(emptyList(), { true }, { true }, mockk()) + val fact = Fact( + component = Component.FEATURE_SITEPERMISSIONS, + action = Action.CONFIRM, + item = SitePermissionsFacts.Items.PERMISSIONS, + value = "allow" + ) + assertNull(SitePermissions.promptShown.testGetValue()) + + controller.run { + fact.process() + } + + assertEquals(1, SitePermissions.permissionsAllowed.testGetValue()!!.size) + assertEquals("allow", SitePermissions.permissionsAllowed.testGetValue()!!.single().extra!!["permissions"]) + } + + @Test + fun `GIVEN site permissions are denied WHEN processing the fact THEN the right metric is recorded`() { + val controller = ReleaseMetricController(emptyList(), { true }, { true }, mockk()) + val fact = Fact( + component = Component.FEATURE_SITEPERMISSIONS, + action = Action.CANCEL, + item = SitePermissionsFacts.Items.PERMISSIONS, + value = "deny" + ) + assertNull(SitePermissions.promptShown.testGetValue()) + + controller.run { + fact.process() + } + + assertEquals(1, SitePermissions.permissionsDenied.testGetValue()!!.size) + assertEquals("deny", SitePermissions.permissionsDenied.testGetValue()!!.single().extra!!["permissions"]) + } }