Skip to content

Commit

Permalink
Add FXIOS-7734 [v121] Telemetry - Additional credit card telemetry ev…
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Vladut committed Nov 16, 2023
1 parent 04a15b1 commit 0429b4b
Show file tree
Hide file tree
Showing 7 changed files with 341 additions and 4 deletions.
8 changes: 8 additions & 0 deletions Client/AccessoryViewProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class AccessoryViewProvider: UIView, Themeable {
showCreditCard = false
case .creditCard:
showCreditCard = true
sendCreditCardAutofillPromptShownTelemetry()
}

setNeedsLayout()
Expand Down Expand Up @@ -208,4 +209,11 @@ class AccessoryViewProvider: UIView, Themeable {
private func tappedCardButton() {
savedCardsClosure?()
}

// MARK: Telemetry
fileprivate func sendCreditCardAutofillPromptShownTelemetry() {
TelemetryWrapper.recordEvent(category: .action,
method: .view,
object: .creditCardAutofillPromptShown)
}
}
38 changes: 34 additions & 4 deletions Client/Coordinators/CredentialAutofillCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ class CredentialAutofillCoordinator: BaseCoordinator {
bottomContainer: alertContainer,
theme: self.themeManager.currentTheme)
} else {
// Save a card telemetry
// send telemetry
if state == .save {
TelemetryWrapper.recordEvent(category: .action,
method: .tap,
object: .creditCardSavePromptCreate)
sendCreditCardSavePromptCreateTelemetry()
} else if state == .update {
sendCreditCardSavePromptUpdateTelemetry()
}

// Save or update a card toast message
Expand Down Expand Up @@ -105,11 +105,41 @@ class CredentialAutofillCoordinator: BaseCoordinator {
childViewController: viewController
)
router.present(bottomSheetVC)
if state == .save {
sendCreditCardSavePromptShownTelemetry()
} else if state == .selectSavedCard {
sendCreditCardAutofillPromptExpandedTelemetry()
}
}

func showPassCodeController() {
let passwordController = DevicePasscodeRequiredViewController()
passwordController.profile = profile
router.present(passwordController)
}

// MARK: Telemetry
fileprivate func sendCreditCardSavePromptShownTelemetry() {
TelemetryWrapper.recordEvent(category: .action,
method: .view,
object: .creditCardSavePromptShown)
}

fileprivate func sendCreditCardSavePromptCreateTelemetry() {
TelemetryWrapper.recordEvent(category: .action,
method: .tap,
object: .creditCardSavePromptCreate)
}

fileprivate func sendCreditCardSavePromptUpdateTelemetry() {
TelemetryWrapper.recordEvent(category: .action,
method: .tap,
object: .creditCardSavePromptUpdate)
}

fileprivate func sendCreditCardAutofillPromptExpandedTelemetry() {
TelemetryWrapper.recordEvent(category: .action,
method: .tap,
object: .creditCardAutofillPromptExpanded)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ class CreditCardBottomSheetViewController: UIViewController, UITableViewDelegate

// MARK: BottomSheet Delegate
func willDismiss() {
if viewModel.state == .selectSavedCard {
sendCreditCardAutofillPromptDismissedTelemetry()
}
}

// MARK: UITableViewDelegate
Expand Down Expand Up @@ -331,4 +334,12 @@ class CreditCardBottomSheetViewController: UIViewController, UITableViewDelegate
yesButton.setTitleColor(currentTheme.colors.textInverted, for: .normal)
cardTableView.reloadData()
}

// MARK: Telemetry

fileprivate func sendCreditCardAutofillPromptDismissedTelemetry() {
TelemetryWrapper.recordEvent(category: .action,
method: .close,
object: .creditCardAutofillPromptDismissed)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class CreditCardSettingsViewController: SensitiveViewController, Themeable {
self.creditCardTableViewController.didSelectCardAtIndex = {
[weak self] creditCard in
self?.viewCreditCard(card: creditCard)
self?.sendCreditCardsManagementCardTappedTelemetry()
}
}

Expand Down Expand Up @@ -104,6 +105,7 @@ class CreditCardSettingsViewController: SensitiveViewController, Themeable {
DispatchQueue.main.async { [weak self] in
let newState = creditCards?.isEmpty ?? true ? CreditCardSettingsState.empty : CreditCardSettingsState.list
self?.updateState(type: newState)
self?.sendCreditCardsSavedAllTelemetry(numberOfSavedCreditCards: creditCards?.count ?? 0)
}
}
}
Expand Down Expand Up @@ -158,6 +160,7 @@ class CreditCardSettingsViewController: SensitiveViewController, Themeable {

if successVal {
self?.updateCreditCardList()
self?.sendTelemetry(forStatus: status)
}

self?.creditCardAddEditView?.dismiss(animated: true)
Expand All @@ -183,9 +186,62 @@ class CreditCardSettingsViewController: SensitiveViewController, Themeable {
@objc
private func addCreditCard() {
updateState(type: .add)
sendCreditCardsManagementAddTappedTelemetry()
}

private func viewCreditCard(card: CreditCard) {
updateState(type: .view, creditCard: card)
}

// MARK: Telemetry
fileprivate func sendTelemetry(forStatus status: CreditCardModifiedStatus) {
switch status {
case .savedCard:
self.sendCreditCardsSavedTelemetry()
case .updatedCard:
self.sendCreditCardsModifiedTelemetry()
case .removedCard:
self.sendCreditCardsDeletedTelemetry()
case .none:
break
}
}

private func sendCreditCardsManagementAddTappedTelemetry() {
TelemetryWrapper.recordEvent(category: .action,
method: .tap,
object: .creditCardManagementAddTapped)
}

private func sendCreditCardsManagementCardTappedTelemetry() {
TelemetryWrapper.recordEvent(category: .action,
method: .tap,
object: .creditCardManagementCardTapped)
}

private func sendCreditCardsSavedAllTelemetry(numberOfSavedCreditCards: Int) {
let savedCardsExtra = [TelemetryWrapper.EventExtraKey.creditCardsQuantity.rawValue: Int64(numberOfSavedCreditCards)]
TelemetryWrapper.recordEvent(category: .information,
method: .foreground,
object: .creditCardSavedAll,
extras: savedCardsExtra)
}

private func sendCreditCardsSavedTelemetry() {
TelemetryWrapper.recordEvent(category: .action,
method: .add,
object: .creditCardSaved)
}

private func sendCreditCardsDeletedTelemetry() {
TelemetryWrapper.recordEvent(category: .action,
method: .delete,
object: .creditCardDeleted)
}

private func sendCreditCardsModifiedTelemetry() {
TelemetryWrapper.recordEvent(category: .action,
method: .change,
object: .creditCardModified)
}
}
38 changes: 38 additions & 0 deletions Client/Telemetry/TelemetryWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,17 @@ extension TelemetryWrapper {
case creditCardSyncEnabled = "creditCardSyncEnabled"
case creditCardAutofillToggle = "creditCardAutofillToggle"
case creditCardSyncToggle = "creditCardSyncToggle"
case creditCardAutofillPromptShown = "creditCard-autofill-prompt-shown"
case creditCardAutofillPromptExpanded = "creditCard-autofill-prompt-expanded"
case creditCardAutofillPromptDismissed = "creditCard-autofill-prompt-dismissed"
case creditCardSavePromptShown = "creditCard-save-prompt-shown"
case creditCardSavePromptUpdate = "creditCard-save-prompt-update"
case creditCardManagementAddTapped = "creditCard-management-add-tapped"
case creditCardManagementCardTapped = "creditCard-management-card-tapped"
case creditCardSaved = "creditCard-saved"
case creditCardSavedAll = "creditCard-saved-all"
case creditCardDeleted = "creditCard-deleted"
case creditCardModified = "creditCard-modified"
case notificationPermission = "notificationPermission"
case engagementNotification = "engagementNotification"
// MARK: New Onboarding
Expand Down Expand Up @@ -739,6 +750,7 @@ extension TelemetryWrapper {
case isCreditCardSyncToggleEnabled = "is-credit-card-sync-toggle-enabled"
case isCreditCardAutofillEnabled = "is-credit-card-autofill-enabled"
case isCreditCardSyncEnabled = "is-credit-card-sync-enabled"
case creditCardsQuantity = "credit-cards-quantity"

// Password Manager
case loginsQuantity = "loginsQuantity"
Expand Down Expand Up @@ -1002,6 +1014,32 @@ extension TelemetryWrapper {
value: value,
extras: extras)
}
case(.action, .view, .creditCardAutofillPromptShown, _, _):
GleanMetrics.CreditCard.autofillPromptShown.record()
case(.action, .tap, .creditCardAutofillPromptExpanded, _, _):
GleanMetrics.CreditCard.autofillPromptExpanded.record()
case(.action, .close, .creditCardAutofillPromptDismissed, _, _):
GleanMetrics.CreditCard.autofillPromptDismissed.record()
case(.action, .view, .creditCardSavePromptShown, _, _):
GleanMetrics.CreditCard.savePromptShown.record()
case(.action, .tap, .creditCardSavePromptUpdate, _, _):
GleanMetrics.CreditCard.savePromptUpdate.record()
case(.action, .tap, .creditCardManagementAddTapped, _, _):
GleanMetrics.CreditCard.managementAddTapped.record()
case(.action, .tap, .creditCardManagementCardTapped, _, _):
GleanMetrics.CreditCard.managementCardTapped.record()
case(.action, .add, .creditCardSaved, _, _):
GleanMetrics.CreditCard.saved.add()
case(.information, .foreground, .creditCardSavedAll, _, let extras):
if let quantity = extras?[EventExtraKey.creditCardsQuantity.rawValue] as? Int64 {
GleanMetrics.CreditCard.savedAll.set(quantity)
} else {
recordUninstrumentedMetrics(category: category, method: method, object: object, value: value, extras: extras)
}
case(.action, .delete, .creditCardDeleted, _, _):
GleanMetrics.CreditCard.deleted.add()
case(.action, .change, .creditCardModified, _, _):
GleanMetrics.CreditCard.modified.add()
// MARK: Settings Menu
case (.action, .open, .settingsMenuSetAsDefaultBrowser, _, _):
GleanMetrics.SettingsMenu.setAsDefaultBrowserPressed.add()
Expand Down
126 changes: 126 additions & 0 deletions Client/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4650,6 +4650,132 @@ credit_card:
- [email protected]
expires: "2024-06-01"

autofill_prompt_shown:
type: event
description: |
Records when the credit card autofill prompt was shown.
bugs:
- https://github.com/mozilla-mobile/firefox-ios/issues/14902
data_reviews:
- https://github.com/mozilla-mobile/firefox-ios/pull/16685
notification_emails:
- [email protected]
expires: "2024-06-01"
autofill_prompt_expanded:
type: event
description: |
Records when the credit card autofill prompt was expanded.
bugs:
- https://github.com/mozilla-mobile/firefox-ios/issues/14902
data_reviews:
- https://github.com/mozilla-mobile/firefox-ios/pull/16685
notification_emails:
- [email protected]
expires: "2024-06-01"
autofill_prompt_dismissed:
type: event
description: |
Records when the credit card autofill prompt was dismissed.
bugs:
- https://github.com/mozilla-mobile/firefox-ios/issues/14902
data_reviews:
- https://github.com/mozilla-mobile/firefox-ios/pull/16685
notification_emails:
- [email protected]
expires: "2024-06-01"
save_prompt_shown:
type: event
description: |
Records when the credit card autofill save prompt is shown.
bugs:
- https://github.com/mozilla-mobile/firefox-ios/issues/14902
data_reviews:
- https://github.com/mozilla-mobile/firefox-ios/pull/16685
notification_emails:
- [email protected]
expires: "2024-06-01"
save_prompt_update:
type: event
description: |
Records when the user updated a credit card using the autofill save prompt.
bugs:
- https://github.com/mozilla-mobile/firefox-ios/issues/14902
data_reviews:
- https://github.com/mozilla-mobile/firefox-ios/pull/16685
notification_emails:
- [email protected]
expires: "2024-06-01"
management_add_tapped:
type: event
description: |
Records when the user has tapped the add button through credit card management settings.
bugs:
- https://github.com/mozilla-mobile/firefox-ios/issues/14902
data_reviews:
- https://github.com/mozilla-mobile/firefox-ios/pull/16685
notification_emails:
- [email protected]
expires: "2024-06-01"
management_card_tapped:
type: event
description: |
Records when the user has tapped on a saved card through credit card management settings.
bugs:
- https://github.com/mozilla-mobile/firefox-ios/issues/14902
data_reviews:
- https://github.com/mozilla-mobile/firefox-ios/pull/16685
notification_emails:
- [email protected]
expires: "2024-06-01"
saved:
type: counter
description: |
A counter of the number of credit cards that have been saved by the user.
bugs:
- https://github.com/mozilla-mobile/firefox-ios/issues/14902
data_reviews:
- https://github.com/mozilla-mobile/firefox-ios/pull/16685
notification_emails:
- [email protected]
expires: "2024-06-01"
unit: counter of credit_card.saved
saved_all:
type: quantity
description: |
Record the number of ALL the credit cards that have been currently stored by the user.
bugs:
- https://github.com/mozilla-mobile/firefox-ios/issues/14902
data_reviews:
- https://github.com/mozilla-mobile/firefox-ios/pull/16685
notification_emails:
- [email protected]
expires: "2024-06-01"
unit: quantity of credit_card.saved_all
deleted:
type: counter
description: |
A counter of the number of credit cards that have been deleted by the user.
bugs:
- https://github.com/mozilla-mobile/firefox-ios/issues/14902
data_reviews:
- https://github.com/mozilla-mobile/firefox-ios/pull/16685
notification_emails:
- [email protected]
expires: "2024-06-01"
unit: counter of credit_card.deleted
modified:
type: counter
description: |
A counter of the number of credit cards that have been modified by the user.
bugs:
- https://github.com/mozilla-mobile/firefox-ios/issues/14902
data_reviews:
- https://github.com/mozilla-mobile/firefox-ios/pull/16685
notification_emails:
- [email protected]
expires: "2024-06-01"
unit: counter of credit_card.modified

baseline.validation:
startup_duration:
type: timespan
Expand Down
Loading

0 comments on commit 0429b4b

Please sign in to comment.