Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
Telemetry for credit card autofill
Browse files Browse the repository at this point in the history
  • Loading branch information
rocketsroger committed Aug 18, 2021
1 parent ef036f3 commit 610cefd
Show file tree
Hide file tree
Showing 13 changed files with 823 additions and 5 deletions.
446 changes: 446 additions & 0 deletions app/docs/metrics.md

Large diffs are not rendered by default.

154 changes: 154 additions & 0 deletions app/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5809,3 +5809,157 @@ recent_tabs:
notification_emails:
- android-probes@mozilla.com
expires: "2022-06-23"
credit_cards:
saved:
type: counter
description: |
A counter of the number of credit cards that have been saved
manually by the user.
send_in_pings:
- metrics
bugs:
- TODO
data_reviews:
- TODO
data_sensitivity:
- interaction
notification_emails:
- android-probes@mozilla.com
expires: "2022-09-01"
deleted:
type: counter
description: |
A counter of the number of credit cards that have been deleted by
the user.
send_in_pings:
- metrics
bugs:
- TODO
data_reviews:
- TODO
data_sensitivity:
- interaction
notification_emails:
- android-probes@mozilla.com
expires: "2022-09-01"
modified:
type: counter
description: |
A counter of the number of credit cards that have been modified by
the user.
send_in_pings:
- metrics
bugs:
- TODO
data_reviews:
- TODO
data_sensitivity:
- interaction
notification_emails:
- android-probes@mozilla.com
expires: "2022-09-01"
form_detected:
type: event
description: |
A credit card form was detected.
send_in_pings:
- metrics
bugs:
- TODO
data_reviews:
- TODO
data_sensitivity:
- interaction
notification_emails:
- android-probes@mozilla.com
expires: "2022-09-01"
autofilled:
type: event
description: |
User has autofilled a credit card.
send_in_pings:
- metrics
bugs:
- TODO
data_reviews:
- TODO
data_sensitivity:
- interaction
notification_emails:
- android-probes@mozilla.com
expires: "2022-09-01"
autofill_prompt_shown:
type: event
description: |
Credit card autofill prompt was shown.
send_in_pings:
- metrics
bugs:
- TODO
data_reviews:
- TODO
data_sensitivity:
- interaction
notification_emails:
- android-probes@mozilla.com
expires: "2022-09-01"
autofill_prompt_expanded:
type: event
description: |
Credit card autofill prompt was expanded.
send_in_pings:
- metrics
bugs:
- TODO
data_reviews:
- TODO
data_sensitivity:
- interaction
notification_emails:
- android-probes@mozilla.com
expires: "2022-09-01"
autofill_prompt_dismissed:
type: event
description: |
Credit card autofill prompt was dismissed.
send_in_pings:
- metrics
bugs:
- TODO
data_reviews:
- TODO
data_sensitivity:
- interaction
notification_emails:
- android-probes@mozilla.com
expires: "2022-09-01"
management_add_tapped:
type: event
description: |
User has tapped the add button through credit card management settings.
send_in_pings:
- metrics
bugs:
- TODO
data_reviews:
- TODO
data_sensitivity:
- interaction
notification_emails:
- android-probes@mozilla.com
expires: "2022-09-01"
management_card_tapped:
type: event
description: |
User has tapped on a saved card through credit card management settings.
send_in_pings:
- metrics
bugs:
- TODO
data_reviews:
- TODO
data_sensitivity:
- interaction
notification_emails:
- android-probes@mozilla.com
expires: "2022-09-01"
12 changes: 12 additions & 0 deletions app/src/main/java/org/mozilla/fenix/components/metrics/Event.kt
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,18 @@ sealed class Event {
object AndroidAutofillRequestWithLogins : Event()
object AndroidAutofillRequestWithoutLogins : Event()

// Credit cards
object CreditCardSaved : Event()
object CreditCardDeleted : Event()
object CreditCardModified : Event()
object CreditCardFormDetected : Event()
object CreditCardAutofilled : Event()
object CreditCardAutofillPromptShown : Event()
object CreditCardAutofillPromptExpanded : Event()
object CreditCardAutofillPromptDismissed : Event()
object CreditCardManagementAddTapped : Event()
object CreditCardManagementCardTapped : Event()

// Interaction events with extras

data class TopSiteSwipeCarousel(val page: Int) : Event() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.mozilla.fenix.GleanMetrics.Collections
import org.mozilla.fenix.GleanMetrics.ContextMenu
import org.mozilla.fenix.GleanMetrics.ContextualMenu
import org.mozilla.fenix.GleanMetrics.CrashReporter
import org.mozilla.fenix.GleanMetrics.CreditCards
import org.mozilla.fenix.GleanMetrics.CustomTab
import org.mozilla.fenix.GleanMetrics.DownloadNotification
import org.mozilla.fenix.GleanMetrics.DownloadsMisc
Expand Down Expand Up @@ -863,6 +864,36 @@ private val Event.wrapper: EventWrapper<*>?
is Event.AndroidAutofillConfirmationSuccessful -> EventWrapper<NoExtraKeys>(
{ AndroidAutofill.confirmSuccessful.record(it) }
)
is Event.CreditCardSaved -> EventWrapper<NoExtraKeys>(
{ CreditCards.saved.add(1) }
)
is Event.CreditCardDeleted -> EventWrapper<NoExtraKeys>(
{ CreditCards.deleted.add(1) }
)
is Event.CreditCardModified -> EventWrapper<NoExtraKeys>(
{ CreditCards.modified.add(1) }
)
is Event.CreditCardFormDetected -> EventWrapper<NoExtraKeys>(
{ CreditCards.formDetected.record(it) }
)
is Event.CreditCardAutofillPromptShown -> EventWrapper<NoExtraKeys>(
{ CreditCards.autofillPromptShown.record(it) }
)
is Event.CreditCardAutofillPromptExpanded -> EventWrapper<NoExtraKeys>(
{ CreditCards.autofillPromptExpanded.record(it) }
)
is Event.CreditCardAutofillPromptDismissed -> EventWrapper<NoExtraKeys>(
{ CreditCards.autofillPromptDismissed.record(it) }
)
is Event.CreditCardAutofilled -> EventWrapper<NoExtraKeys>(
{ CreditCards.autofilled.record(it) }
)
is Event.CreditCardManagementAddTapped -> EventWrapper<NoExtraKeys>(
{ CreditCards.managementAddTapped.record(it) }
)
is Event.CreditCardManagementCardTapped -> EventWrapper<NoExtraKeys>(
{ CreditCards.managementCardTapped.record(it) }
)

// Don't record other events in Glean:
is Event.AddBookmark -> null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import mozilla.components.feature.customtabs.CustomTabsFacts
import mozilla.components.feature.downloads.facts.DownloadsFacts
import mozilla.components.feature.findinpage.facts.FindInPageFacts
import mozilla.components.feature.media.facts.MediaFacts
import mozilla.components.feature.prompts.facts.CreditCardAutofillDialogFacts
import mozilla.components.feature.prompts.facts.LoginDialogFacts
import mozilla.components.feature.pwa.ProgressiveWebAppFacts
import mozilla.components.feature.search.telemetry.ads.AdsTelemetry
Expand Down Expand Up @@ -164,6 +165,16 @@ internal class ReleaseMetricController(
Component.FEATURE_PROMPTS to LoginDialogFacts.Items.CANCEL -> Event.LoginDialogPromptCancelled
Component.FEATURE_PROMPTS to LoginDialogFacts.Items.NEVER_SAVE -> Event.LoginDialogPromptNeverSave
Component.FEATURE_PROMPTS to LoginDialogFacts.Items.SAVE -> Event.LoginDialogPromptSave
Component.FEATURE_PROMPTS to CreditCardAutofillDialogFacts.Items.AUTOFILL_CREDIT_CARD_FORM_DETECTED ->
Event.CreditCardFormDetected
Component.FEATURE_PROMPTS to CreditCardAutofillDialogFacts.Items.AUTOFILL_CREDIT_CARD_SUCCESS ->
Event.CreditCardAutofilled
Component.FEATURE_PROMPTS to CreditCardAutofillDialogFacts.Items.AUTOFILL_CREDIT_CARD_PROMPT_SHOWN ->
Event.CreditCardAutofillPromptShown
Component.FEATURE_PROMPTS to CreditCardAutofillDialogFacts.Items.AUTOFILL_CREDIT_CARD_PROMPT_EXPANDED ->
Event.CreditCardAutofillPromptExpanded
Component.FEATURE_PROMPTS to CreditCardAutofillDialogFacts.Items.AUTOFILL_CREDIT_CARD_PROMPT_DISMISSED ->
Event.CreditCardAutofillPromptDismissed

Component.FEATURE_FINDINPAGE to FindInPageFacts.Items.CLOSE -> Event.FindInPageClosed
Component.FEATURE_FINDINPAGE to FindInPageFacts.Items.INPUT -> Event.FindInPageSearchCommitted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ class CreditCardEditorFragment : SecureFragment(R.layout.fragment_credit_card_ed
controller = DefaultCreditCardEditorController(
storage = storage,
lifecycleScope = lifecycleScope,
navController = findNavController()
navController = findNavController(),
requireContext().components.analytics.metrics
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class CreditCardsManagementFragment : SecureFragment() {
interactor = DefaultCreditCardsManagementInteractor(
controller = DefaultCreditCardsManagementController(
navController = findNavController()
)
),
requireContext().components.analytics.metrics
)
val binding = ComponentCreditCardsBinding.bind(view)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import kotlinx.coroutines.launch
import mozilla.components.concept.storage.NewCreditCardFields
import mozilla.components.concept.storage.UpdatableCreditCardFields
import mozilla.components.service.sync.autofill.AutofillCreditCardsAddressesStorage
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.metrics.MetricController
import org.mozilla.fenix.settings.creditcards.CreditCardEditorFragment
import org.mozilla.fenix.settings.creditcards.interactor.CreditCardEditorInteractor

Expand Down Expand Up @@ -55,6 +57,7 @@ class DefaultCreditCardEditorController(
private val storage: AutofillCreditCardsAddressesStorage,
private val lifecycleScope: CoroutineScope,
private val navController: NavController,
private val metrics: MetricController,
private val ioDispatcher: CoroutineDispatcher = Dispatchers.IO
) : CreditCardEditorController {

Expand All @@ -69,6 +72,7 @@ class DefaultCreditCardEditorController(
lifecycleScope.launch(Dispatchers.Main) {
navController.popBackStack()
}
metrics.track(Event.CreditCardDeleted)
}
}

Expand All @@ -79,6 +83,7 @@ class DefaultCreditCardEditorController(
lifecycleScope.launch(Dispatchers.Main) {
navController.popBackStack()
}
metrics.track(Event.CreditCardSaved)
}
}

Expand All @@ -89,6 +94,7 @@ class DefaultCreditCardEditorController(
lifecycleScope.launch(Dispatchers.Main) {
navController.popBackStack()
}
metrics.track(Event.CreditCardModified)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
package org.mozilla.fenix.settings.creditcards.interactor

import mozilla.components.concept.storage.CreditCard
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.metrics.MetricController
import org.mozilla.fenix.settings.creditcards.controller.CreditCardsManagementController

/**
Expand Down Expand Up @@ -34,14 +36,17 @@ interface CreditCardsManagementInteractor {
* all user interactions.
*/
class DefaultCreditCardsManagementInteractor(
private val controller: CreditCardsManagementController
private val controller: CreditCardsManagementController,
private val metrics: MetricController
) : CreditCardsManagementInteractor {

override fun onSelectCreditCard(creditCard: CreditCard) {
controller.handleCreditCardClicked(creditCard)
metrics.track(Event.CreditCardManagementAddTapped)
}

override fun onAddCreditCardClick() {
controller.handleAddCreditCardClicked()
metrics.track(Event.CreditCardManagementCardTapped)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.junit.runner.RunWith
import org.mozilla.fenix.GleanMetrics.Addons
import org.mozilla.fenix.GleanMetrics.Awesomebar
import org.mozilla.fenix.GleanMetrics.BookmarksManagement
import org.mozilla.fenix.GleanMetrics.CreditCards
import org.mozilla.fenix.GleanMetrics.Events
import org.mozilla.fenix.GleanMetrics.History
import org.mozilla.fenix.GleanMetrics.SyncedTabs
Expand Down Expand Up @@ -261,4 +262,47 @@ class GleanMetricsServiceTest {
gleanService.track(Event.DefaultBrowserNotifTapped)
assertTrue(Events.defaultBrowserNotifTapped.testHasValue())
}

@Test
fun `credit card events are correctly recorded`() {
assertFalse(CreditCards.saved.testHasValue())
gleanService.track(Event.CreditCardSaved)
assertTrue(CreditCards.saved.testHasValue())

assertFalse(CreditCards.deleted.testHasValue())
gleanService.track(Event.CreditCardDeleted)
assertTrue(CreditCards.deleted.testHasValue())

assertFalse(CreditCards.modified.testHasValue())
gleanService.track(Event.CreditCardModified)
assertTrue(CreditCards.modified.testHasValue())

assertFalse(CreditCards.formDetected.testHasValue())
gleanService.track(Event.CreditCardFormDetected)
assertTrue(CreditCards.formDetected.testHasValue())

assertFalse(CreditCards.autofilled.testHasValue())
gleanService.track(Event.CreditCardAutofilled)
assertTrue(CreditCards.autofilled.testHasValue())

assertFalse(CreditCards.autofillPromptShown.testHasValue())
gleanService.track(Event.CreditCardAutofillPromptShown)
assertTrue(CreditCards.autofillPromptShown.testHasValue())

assertFalse(CreditCards.autofillPromptExpanded.testHasValue())
gleanService.track(Event.CreditCardAutofillPromptExpanded)
assertTrue(CreditCards.autofillPromptExpanded.testHasValue())

assertFalse(CreditCards.autofillPromptDismissed.testHasValue())
gleanService.track(Event.CreditCardAutofillPromptDismissed)
assertTrue(CreditCards.autofillPromptDismissed.testHasValue())

assertFalse(CreditCards.managementAddTapped.testHasValue())
gleanService.track(Event.CreditCardManagementAddTapped)
assertTrue(CreditCards.managementAddTapped.testHasValue())

assertFalse(CreditCards.managementCardTapped.testHasValue())
gleanService.track(Event.CreditCardManagementCardTapped)
assertTrue(CreditCards.managementCardTapped.testHasValue())
}
}

0 comments on commit 610cefd

Please sign in to comment.