Skip to content

Commit

Permalink
Add autofill default enabled state as a parameter to multiple autofil…
Browse files Browse the repository at this point in the history
…l pixels
  • Loading branch information
amddg44 committed Sep 22, 2023
1 parent 89fc56b commit bcf99dd
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 32 deletions.
2 changes: 2 additions & 0 deletions Core/Pixel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ public struct PixelParameters {
public static let returnUserErrorCode = "error_code"
public static let returnUserOldATB = "old_atb"
public static let returnUserNewATB = "new_atb"

public static let autofillDefaultState = "default_state"
}

public struct PixelValues {
Expand Down
24 changes: 16 additions & 8 deletions DuckDuckGo/AutofillLoginPromptViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ class AutofillLoginPromptViewController: UIViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if trigger == AutofillUserScript.GetTriggerType.autoprompt {
Pixel.fire(pixel: .autofillLoginsFillLoginInlineAutopromptDisplayed)
Pixel.fire(pixel: .autofillLoginsFillLoginInlineAutopromptDisplayed,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
} else {
Pixel.fire(pixel: .autofillLoginsFillLoginInlineManualDisplayed)
Pixel.fire(pixel: .autofillLoginsFillLoginInlineManualDisplayed,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
}
}

Expand All @@ -95,9 +97,11 @@ class AutofillLoginPromptViewController: UIViewController {
extension AutofillLoginPromptViewController: UISheetPresentationControllerDelegate {
func presentationControllerDidDismiss(_ presentationController: UIPresentationController) {
if self.trigger == AutofillUserScript.GetTriggerType.autoprompt {
Pixel.fire(pixel: .autofillLoginsAutopromptDismissed)
Pixel.fire(pixel: .autofillLoginsAutopromptDismissed,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
} else {
Pixel.fire(pixel: .autofillLoginsFillLoginInlineManualDismissed)
Pixel.fire(pixel: .autofillLoginsFillLoginInlineManualDismissed,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
}
completion?(nil, false)
}
Expand All @@ -107,9 +111,11 @@ extension AutofillLoginPromptViewController: AutofillLoginPromptViewModelDelegat
func autofillLoginPromptViewModel(_ viewModel: AutofillLoginPromptViewModel, didSelectAccount account: SecureVaultModels.WebsiteAccount) {

if trigger == AutofillUserScript.GetTriggerType.autoprompt {
Pixel.fire(pixel: .autofillLoginsFillLoginInlineAutopromptConfirmed)
Pixel.fire(pixel: .autofillLoginsFillLoginInlineAutopromptConfirmed,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
} else {
Pixel.fire(pixel: .autofillLoginsFillLoginInlineManualConfirmed)
Pixel.fire(pixel: .autofillLoginsFillLoginInlineManualConfirmed,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
}

if AppDependencyProvider.shared.autofillLoginSession.isValidSession {
Expand Down Expand Up @@ -163,9 +169,11 @@ extension AutofillLoginPromptViewController: AutofillLoginPromptViewModelDelegat
func autofillLoginPromptViewModelDidCancel(_ viewModel: AutofillLoginPromptViewModel) {
dismiss(animated: true) {
if self.trigger == AutofillUserScript.GetTriggerType.autoprompt {
Pixel.fire(pixel: .autofillLoginsAutopromptDismissed)
Pixel.fire(pixel: .autofillLoginsAutopromptDismissed,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
} else {
Pixel.fire(pixel: .autofillLoginsFillLoginInlineManualDismissed)
Pixel.fire(pixel: .autofillLoginsFillLoginInlineManualDismissed,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
}

self.completion?(nil, false)
Expand Down
6 changes: 4 additions & 2 deletions DuckDuckGo/AutofillLoginSettingsListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -628,9 +628,11 @@ extension AutofillLoginSettingsListViewController: AutofillLoginDetailsViewContr
extension AutofillLoginSettingsListViewController: EnableAutofillSettingsTableViewCellDelegate {
func enableAutofillSettingsTableViewCell(_ cell: EnableAutofillSettingsTableViewCell, didChangeSettings value: Bool) {
if value {
Pixel.fire(pixel: .autofillLoginsSettingsEnabled)
Pixel.fire(pixel: .autofillLoginsSettingsEnabled,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
} else {
Pixel.fire(pixel: .autofillLoginsSettingsDisabled)
Pixel.fire(pixel: .autofillLoginsSettingsDisabled,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
}

viewModel.isAutofillEnabledInSettings = value
Expand Down
4 changes: 4 additions & 0 deletions DuckDuckGo/AutofillSettingStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ struct AutofillSettingStatus {
let canAuthenticate = context.canEvaluatePolicy(.deviceOwnerAuthentication, error: &error)
return appSettings.autofillCredentialsEnabled && canAuthenticate
}

static var defaultState: String {
return appSettings.autofillCredentialsHasBeenEnabledAutomaticallyIfNecessary ? "on" : "off"
}
}
12 changes: 8 additions & 4 deletions DuckDuckGo/PasswordGenerationPromptViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class PasswordGenerationPromptViewController: UIViewController {

setupPasswordGenerationPromptView()

Pixel.fire(pixel: .autofillLoginsPasswordGenerationPromptDisplayed)
Pixel.fire(pixel: .autofillLoginsPasswordGenerationPromptDisplayed,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
}

private func setupPasswordGenerationPromptView() {
Expand All @@ -67,23 +68,26 @@ class PasswordGenerationPromptViewController: UIViewController {

extension PasswordGenerationPromptViewController: UISheetPresentationControllerDelegate {
func presentationControllerDidDismiss(_ presentationController: UIPresentationController) {
Pixel.fire(pixel: .autofillLoginsPasswordGenerationPromptDismissed)
Pixel.fire(pixel: .autofillLoginsPasswordGenerationPromptDismissed,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])

self.completion?(false)
}
}

extension PasswordGenerationPromptViewController: PasswordGenerationPromptViewModelDelegate {
func passwordGenerationPromptViewModelDidSelect(_ viewModel: PasswordGenerationPromptViewModel) {
Pixel.fire(pixel: .autofillLoginsPasswordGenerationPromptConfirmed)
Pixel.fire(pixel: .autofillLoginsPasswordGenerationPromptConfirmed,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])

dismiss(animated: true) {
self.completion?(true)
}
}

func passwordGenerationPromptViewModelDidCancel(_ viewModel: PasswordGenerationPromptViewModel) {
Pixel.fire(pixel: .autofillLoginsPasswordGenerationPromptDismissed)
Pixel.fire(pixel: .autofillLoginsPasswordGenerationPromptDismissed,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])

dismiss(animated: true) {
self.completion?(false)
Expand Down
35 changes: 20 additions & 15 deletions DuckDuckGo/SaveLoginViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ class SaveLoginViewController: UIViewController {
return
}
switch viewModel.layoutType {
case .newUser:
Pixel.fire(pixel: .autofillLoginsSaveLoginModalDismissed)
case .saveLogin:
Pixel.fire(pixel: .autofillLoginsSaveLoginModalDismissed)
case .newUser, .saveLogin:
Pixel.fire(pixel: .autofillLoginsSaveLoginModalDismissed,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
case .savePassword:
Pixel.fire(pixel: .autofillLoginsSavePasswordModalDismissed)
Pixel.fire(pixel: .autofillLoginsSavePasswordModalDismissed,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
case .updateUsername:
Pixel.fire(pixel: .autofillLoginsUpdateUsernameModalDismissed)
case .updatePassword:
Expand All @@ -100,12 +100,12 @@ class SaveLoginViewController: UIViewController {
installChildViewController(controller)

switch saveViewModel.layoutType {
case .newUser:
Pixel.fire(pixel: .autofillLoginsSaveLoginModalDisplayed)
case .saveLogin:
Pixel.fire(pixel: .autofillLoginsSaveLoginModalDisplayed)
case .newUser, .saveLogin:
Pixel.fire(pixel: .autofillLoginsSaveLoginModalDisplayed,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
case .savePassword:
Pixel.fire(pixel: .autofillLoginsSavePasswordModalDisplayed)
Pixel.fire(pixel: .autofillLoginsSavePasswordModalDisplayed,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
case .updateUsername:
Pixel.fire(pixel: .autofillLoginsUpdateUsernameModalDisplayed)
case .updatePassword:
Expand All @@ -119,9 +119,11 @@ extension SaveLoginViewController: SaveLoginViewModelDelegate {
switch viewModel.layoutType {
case .saveLogin, .savePassword, .newUser:
if viewModel.layoutType == .savePassword {
Pixel.fire(pixel: .autofillLoginsSavePasswordModalConfirmed)
Pixel.fire(pixel: .autofillLoginsSavePasswordModalConfirmed,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
} else {
Pixel.fire(pixel: .autofillLoginsSaveLoginModalConfirmed)
Pixel.fire(pixel: .autofillLoginsSaveLoginModalConfirmed,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
}
delegate?.saveLoginViewController(self, didSaveCredentials: credentialManager.credentials)
case .updatePassword, .updateUsername:
Expand All @@ -148,15 +150,17 @@ extension SaveLoginViewController: SaveLoginViewModelDelegate {
alertController.overrideUserInterfaceStyle()

let disableAction = UIAlertAction(title: UserText.autofillKeepEnabledAlertDisableAction, style: .cancel) { _ in
Pixel.fire(pixel: .autofillLoginsFillLoginInlineDisablePromptAutofillDisabled)
Pixel.fire(pixel: .autofillLoginsFillLoginInlineDisablePromptAutofillDisabled,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
if isSelfPresentingAlert {
self.delegate?.saveLoginViewControllerDidCancel(self)
}
AppDependencyProvider.shared.appSettings.autofillCredentialsEnabled = false
}

let keepUsingAction = UIAlertAction(title: UserText.autofillKeepEnabledAlertKeepUsingAction, style: .default) { _ in
Pixel.fire(pixel: .autofillLoginsFillLoginInlineDisablePromptAutofillKept)
Pixel.fire(pixel: .autofillLoginsFillLoginInlineDisablePromptAutofillKept,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
if isSelfPresentingAlert {
self.delegate?.saveLoginViewControllerDidCancel(self)
}
Expand All @@ -170,7 +174,8 @@ extension SaveLoginViewController: SaveLoginViewModelDelegate {
if isAlreadyDismissed {
delegate?.saveLoginViewController(self, didRequestPresentConfirmKeepUsingAlertController: alertController)
} else {
Pixel.fire(pixel: .autofillLoginsFillLoginInlineDisablePromptShown)
Pixel.fire(pixel: .autofillLoginsFillLoginInlineDisablePromptShown,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
present(alertController, animated: true)
}
}
Expand Down
3 changes: 2 additions & 1 deletion DuckDuckGo/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,8 @@ class SettingsViewController: UITableViewController {
syncDataProviders: syncDataProviders
)
autofillController.delegate = self
Pixel.fire(pixel: .autofillSettingsOpened)
Pixel.fire(pixel: .autofillSettingsOpened,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
navigationController?.pushViewController(autofillController, animated: animated)
}

Expand Down
3 changes: 2 additions & 1 deletion DuckDuckGo/TabViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2496,7 +2496,8 @@ extension TabViewController: SaveLoginViewControllerDelegate {

func saveLoginViewController(_ viewController: SaveLoginViewController,
didRequestPresentConfirmKeepUsingAlertController alertController: UIAlertController) {
Pixel.fire(pixel: .autofillLoginsFillLoginInlineDisablePromptShown)
Pixel.fire(pixel: .autofillLoginsFillLoginInlineDisablePromptShown,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
present(alertController, animated: true)
}
}
Expand Down
3 changes: 2 additions & 1 deletion DuckDuckGo/TabViewControllerBrowsingMenuExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,8 @@ extension TabViewController {
}

private func onOpenAutofillLoginsAction() {
Pixel.fire(pixel: .browsingMenuAutofill)
Pixel.fire(pixel: .browsingMenuAutofill,
withAdditionalParameters: [PixelParameters.autofillDefaultState: AutofillSettingStatus.defaultState])
delegate?.tabDidRequestAutofillLogins(tab: self)
}

Expand Down

0 comments on commit bcf99dd

Please sign in to comment.