diff --git a/app/metrics.yaml b/app/metrics.yaml index 73651477d5..482dd009fd 100644 --- a/app/metrics.yaml +++ b/app/metrics.yaml @@ -7356,6 +7356,171 @@ credit_cards: tags: - Autofill +addresses: + saved: + type: counter + description: | + A counter of the number of addresses that have been saved + manually by the user. + bugs: + - https://github.com/mozilla-mobile/fenix/issues/24857 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/25216 + data_sensitivity: + - interaction + notification_emails: + - android-probes@mozilla.com + expires: 105 + metadata: + tags: + - Autofill + updated: + type: counter + description: | + A counter of the number of addresses that have been updated + manually by the user. + bugs: + - https://github.com/mozilla-mobile/fenix/issues/24857 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/25216 + data_sensitivity: + - interaction + notification_emails: + - android-probes@mozilla.com + expires: 105 + metadata: + tags: + - Autofill + deleted: + type: counter + description: | + A counter of the number of addresses that have been deleted by + the user. + bugs: + - https://github.com/mozilla-mobile/fenix/issues/24857 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/25216 + data_sensitivity: + - interaction + notification_emails: + - android-probes@mozilla.com + expires: 105 + metadata: + tags: + - Autofill + form_detected: + type: event + description: | + A address form was detected. + bugs: + - https://github.com/mozilla-mobile/fenix/issues/18711 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/25216 + data_sensitivity: + - interaction + notification_emails: + - android-probes@mozilla.com + expires: 105 + metadata: + tags: + - Autofill + autofilled: + type: event + description: | + User has autofilled an address. + bugs: + - https://github.com/mozilla-mobile/fenix/issues/18711 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/25216 + data_sensitivity: + - interaction + notification_emails: + - android-probes@mozilla.com + expires: 105 + metadata: + tags: + - Autofill + autofill_prompt_shown: + type: event + description: | + Address autofill prompt was shown. + bugs: + - https://github.com/mozilla-mobile/fenix/issues/24857 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/25216 + data_sensitivity: + - interaction + notification_emails: + - android-probes@mozilla.com + expires: 105 + metadata: + tags: + - Autofill + autofill_prompt_expanded: + type: event + description: | + Address autofill prompt was expanded. + bugs: + - https://github.com/mozilla-mobile/fenix/issues/24857 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/25216 + data_sensitivity: + - interaction + notification_emails: + - android-probes@mozilla.com + expires: 105 + metadata: + tags: + - Autofill + autofill_prompt_dismissed: + type: event + description: | + Address autofill prompt was dismissed. + bugs: + - https://github.com/mozilla-mobile/fenix/issues/24857 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/25216 + data_sensitivity: + - interaction + notification_emails: + - android-probes@mozilla.com + expires: 105 + metadata: + tags: + - Autofill + management_add_tapped: + type: event + description: | + User has tapped the add button through address management settings. + bugs: + - https://github.com/mozilla-mobile/fenix/issues/24857 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/20909 + data_sensitivity: + - interaction + notification_emails: + - android-probes@mozilla.com + expires: 105 + metadata: + tags: + - Autofill + management_address_tapped: + type: event + description: | + User has tapped on a saved address through address management settings. + bugs: + - https://github.com/mozilla-mobile/fenix/issues/24857 + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/25216 + data_sensitivity: + - interaction + notification_emails: + - android-probes@mozilla.com + expires: 105 + metadata: + tags: + - Autofill + search_terms: number_of_search_term_group: type: event 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 c9502cc9f5..dea7d5bdbc 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 @@ -17,6 +17,7 @@ import mozilla.components.feature.awesomebar.provider.SessionSuggestionProvider import mozilla.components.feature.contextmenu.facts.ContextMenuFacts import mozilla.components.feature.media.facts.MediaFacts import mozilla.components.feature.prompts.dialog.LoginDialogFacts +import mozilla.components.feature.prompts.facts.AddressAutofillDialogFacts import mozilla.components.feature.prompts.facts.CreditCardAutofillDialogFacts import mozilla.components.feature.pwa.ProgressiveWebAppFacts import mozilla.components.feature.search.telemetry.ads.AdsTelemetry @@ -34,6 +35,7 @@ import mozilla.components.support.webextensions.facts.WebExtensionFacts import mozilla.telemetry.glean.private.NoExtras import org.mozilla.fenix.BuildConfig import org.mozilla.fenix.GleanMetrics.Addons +import org.mozilla.fenix.GleanMetrics.Addresses import org.mozilla.fenix.GleanMetrics.ContextMenu import org.mozilla.fenix.GleanMetrics.AndroidAutofill import org.mozilla.fenix.GleanMetrics.Awesomebar @@ -170,6 +172,18 @@ internal class ReleaseMetricController( CreditCards.savePromptCreate.record(NoExtras()) Component.FEATURE_PROMPTS to CreditCardAutofillDialogFacts.Items.AUTOFILL_CREDIT_CARD_UPDATED -> CreditCards.savePromptUpdate.record(NoExtras()) + + Component.FEATURE_PROMPTS to AddressAutofillDialogFacts.Items.AUTOFILL_ADDRESS_FORM_DETECTED -> + Addresses.formDetected.record(NoExtras()) + Component.FEATURE_PROMPTS to AddressAutofillDialogFacts.Items.AUTOFILL_ADDRESS_SUCCESS -> + Addresses.autofilled.record(NoExtras()) + Component.FEATURE_PROMPTS to AddressAutofillDialogFacts.Items.AUTOFILL_ADDRESS_PROMPT_SHOWN -> + Addresses.autofillPromptShown.record(NoExtras()) + Component.FEATURE_PROMPTS to AddressAutofillDialogFacts.Items.AUTOFILL_ADDRESS_PROMPT_EXPANDED -> + Addresses.autofillPromptExpanded.record(NoExtras()) + Component.FEATURE_PROMPTS to AddressAutofillDialogFacts.Items.AUTOFILL_ADDRESS_PROMPT_DISMISSED -> + Addresses.autofillPromptDismissed.record(NoExtras()) + Component.FEATURE_AUTOFILL to AutofillFacts.Items.AUTOFILL_REQUEST -> { val hasMatchingLogins = metadata?.get(AutofillFacts.Metadata.HAS_MATCHING_LOGINS) as Boolean? if (hasMatchingLogins == true) { diff --git a/app/src/main/java/org/mozilla/fenix/settings/address/AddressManagementFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/address/AddressManagementFragment.kt index 25c4edfe71..8b84917f4b 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/address/AddressManagementFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/address/AddressManagementFragment.kt @@ -16,6 +16,8 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import mozilla.components.lib.state.ext.consumeFrom import mozilla.components.lib.state.ext.observeAsComposableState +import mozilla.telemetry.glean.private.NoExtras +import org.mozilla.fenix.GleanMetrics.Addresses import org.mozilla.fenix.components.StoreProvider import org.mozilla.fenix.ext.components import org.mozilla.fenix.settings.address.controller.DefaultAddressManagementController @@ -59,8 +61,14 @@ class AddressManagementFragment : Fragment() { AddressList( addresses = addresses.value ?: emptyList(), - onAddressClick = interactor::onSelectAddress, - onAddAddressButtonClick = interactor::onAddAddressButtonClick + onAddressClick = { + interactor::onSelectAddress + Addresses.managementAddressTapped.record(NoExtras()) + }, + onAddAddressButtonClick = { + interactor::onAddAddressButtonClick + Addresses.managementAddTapped.record(NoExtras()) + } ) } } diff --git a/app/src/main/java/org/mozilla/fenix/settings/address/view/AddressEditorView.kt b/app/src/main/java/org/mozilla/fenix/settings/address/view/AddressEditorView.kt index e7863d733a..b25401c79d 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/address/view/AddressEditorView.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/address/view/AddressEditorView.kt @@ -16,6 +16,7 @@ import mozilla.components.browser.state.search.RegionState import mozilla.components.concept.storage.UpdatableAddressFields import mozilla.components.support.ktx.android.view.hideKeyboard import mozilla.components.support.ktx.android.view.showKeyboard +import org.mozilla.fenix.GleanMetrics.Addresses import org.mozilla.fenix.R import org.mozilla.fenix.databinding.FragmentAddressEditorBinding import org.mozilla.fenix.ext.placeCursorAtEnd @@ -102,8 +103,10 @@ class AddressEditorView( if (address != null) { interactor.onUpdateAddress(address.guid, addressFields) + Addresses.updated.add() } else { interactor.onSaveAddress(addressFields) + Addresses.saved.add() } } @@ -115,6 +118,7 @@ class AddressEditorView( } setPositiveButton(R.string.addressess_confirm_dialog_ok_button) { _, _ -> interactor.onDeleteAddress(guid) + Addresses.deleted.add() } create() }.show() diff --git a/app/src/test/java/org/mozilla/fenix/settings/address/AddressEditorViewTest.kt b/app/src/test/java/org/mozilla/fenix/settings/address/AddressEditorViewTest.kt index 45930fce64..dd8fc151b4 100644 --- a/app/src/test/java/org/mozilla/fenix/settings/address/AddressEditorViewTest.kt +++ b/app/src/test/java/org/mozilla/fenix/settings/address/AddressEditorViewTest.kt @@ -14,19 +14,24 @@ import kotlinx.coroutines.runBlocking import mozilla.components.browser.state.search.RegionState import mozilla.components.concept.storage.Address import mozilla.components.concept.storage.UpdatableAddressFields +import mozilla.components.service.glean.testing.GleanTestRule import mozilla.components.support.test.robolectric.testContext import org.junit.Assert.assertEquals import org.junit.Assert.assertNotEquals +import org.junit.Assert.assertNotNull +import org.junit.Assert.assertNull import org.junit.Before +import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith +import org.mozilla.fenix.GleanMetrics.Addresses import org.mozilla.fenix.R import org.mozilla.fenix.databinding.FragmentAddressEditorBinding import org.mozilla.fenix.helpers.FenixRobolectricTestRunner import org.mozilla.fenix.settings.address.interactor.AddressEditorInteractor import org.mozilla.fenix.settings.address.view.AddressEditorView -@RunWith(FenixRobolectricTestRunner::class) +@RunWith(FenixRobolectricTestRunner::class) // For gleanTestRule class AddressEditorViewTest { private lateinit var view: View @@ -35,6 +40,9 @@ class AddressEditorViewTest { private lateinit var binding: FragmentAddressEditorBinding private lateinit var address: Address + @get:Rule + val gleanTestRule = GleanTestRule(testContext) + @Before fun setup() { view = LayoutInflater.from(testContext).inflate(R.layout.fragment_address_editor, null) @@ -300,6 +308,30 @@ class AddressEditorViewTest { assertEquals(AddressUtils.countries[DEFAULT_COUNTRY]!!.displayName, binding.countryDropDown.selectedItem.toString()) } + @Test + fun `GIVEN an existing address WHEN the save button is clicked THEN proper metrics are recorded`() = runBlocking { + assertNull(Addresses.updated.testGetValue()) + + val addressEditorView = spyk(AddressEditorView(binding, interactor, address = address)) + addressEditorView.bind() + + binding.saveButton.performClick() + + assertNotNull(Addresses.updated.testGetValue()) + } + + @Test + fun `GIVEN a new address WHEN the save button is clicked THEN proper metrics are recorded`() = runBlocking { + assertNull(Addresses.saved.testGetValue()) + + val addressEditorView = spyk(AddressEditorView(binding, interactor)) + addressEditorView.bind() + + binding.saveButton.performClick() + + assertNotNull(Addresses.saved.testGetValue()) + } + private fun generateAddress(country: String = "US", addressLevel1: String = "Oregon") = Address( guid = "123", givenName = "Given",