Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parameter to multiple Autofill pixels #2032

Merged
merged 5 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -70,12 +70,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 @@ -96,12 +96,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 @@ -115,9 +115,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 @@ -144,15 +146,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 @@ -166,7 +170,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