From faac7272c698a3d0082935207a586e2a0a8c0cb3 Mon Sep 17 00:00:00 2001 From: amddg44 Date: Wed, 19 Jun 2024 21:04:21 +0200 Subject: [PATCH] Additional Autofill KPI pixels (#2943) Task/Issue URL: https://app.asana.com/0/1201462886803403/1207512213117497/f Tech Design URL: Additional Task URL: https://app.asana.com/0/1201462886803403/1207512213117504/f Description: Updates enabled user pixel firing rules and adds new autofill toggle pixel for search DAUs. Also adds new Autofill debug feature to bulk add dummy data for testing. --- Core/PixelEvent.swift | 5 +++ DuckDuckGo.xcodeproj/project.pbxproj | 2 +- .../xcshareddata/swiftpm/Package.resolved | 4 +- DuckDuckGo/AppDelegate.swift | 11 ++++++ DuckDuckGo/AutofillDebugViewController.swift | 39 +++++++++++++++++++ DuckDuckGo/Debug.storyboard | 27 ++++++++----- 6 files changed, 76 insertions(+), 12 deletions(-) diff --git a/Core/PixelEvent.swift b/Core/PixelEvent.swift index c5ca60309d..37bfdf78a0 100644 --- a/Core/PixelEvent.swift +++ b/Core/PixelEvent.swift @@ -265,6 +265,8 @@ extension Pixel { case autofillActiveUser case autofillEnabledUser case autofillOnboardedUser + case autofillToggledOn + case autofillToggledOff case autofillLoginsStacked case autofillMultipleAuthCallsTriggered @@ -993,6 +995,9 @@ extension Pixel.Event { case .autofillActiveUser: return "m_autofill_activeuser" case .autofillEnabledUser: return "m_autofill_enableduser" case .autofillOnboardedUser: return "m_autofill_onboardeduser" + case .autofillToggledOn: return "m_autofill_toggled_on" + case .autofillToggledOff: return "m_autofill_toggled_off" + case .autofillLoginsStacked: return "m_autofill_logins_stacked" case .autofillMultipleAuthCallsTriggered: return "m_autofill_multiple_auth_calls_triggered" diff --git a/DuckDuckGo.xcodeproj/project.pbxproj b/DuckDuckGo.xcodeproj/project.pbxproj index edc966597c..c14745d65e 100644 --- a/DuckDuckGo.xcodeproj/project.pbxproj +++ b/DuckDuckGo.xcodeproj/project.pbxproj @@ -9782,7 +9782,7 @@ repositoryURL = "https://github.com/DuckDuckGo/BrowserServicesKit"; requirement = { kind = exactVersion; - version = "158.0.0"; + version = 158.1.0; }; }; 9F8FE9472BAE50E50071E372 /* XCRemoteSwiftPackageReference "lottie-spm" */ = { diff --git a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 20531931c2..4deeff451d 100644 --- a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -32,8 +32,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/DuckDuckGo/BrowserServicesKit", "state" : { - "revision" : "61df946265d05c401b472d76f837a13552722367", - "version" : "158.0.0" + "revision" : "201a932642275eeccc213940a1e85c6c19a6f3d0", + "version" : "158.1.0" } }, { diff --git a/DuckDuckGo/AppDelegate.swift b/DuckDuckGo/AppDelegate.swift index 73d89258b7..fa4d65c14c 100644 --- a/DuckDuckGo/AppDelegate.swift +++ b/DuckDuckGo/AppDelegate.swift @@ -893,6 +893,7 @@ import WebKit private func setUpAutofillPixelReporter() { autofillPixelReporter = AutofillPixelReporter( userDefaults: .standard, + autofillEnabled: AppDependencyProvider.shared.appSettings.autofillCredentialsEnabled, eventMapping: EventMapping {event, _, params, _ in switch event { case .autofillActiveUser: @@ -901,6 +902,10 @@ import WebKit Pixel.fire(pixel: .autofillEnabledUser) case .autofillOnboardedUser: Pixel.fire(pixel: .autofillOnboardedUser) + case .autofillToggledOn: + Pixel.fire(pixel: .autofillToggledOn, withAdditionalParameters: params ?? [:]) + case .autofillToggledOff: + Pixel.fire(pixel: .autofillToggledOff, withAdditionalParameters: params ?? [:]) case .autofillLoginsStacked: Pixel.fire(pixel: .autofillLoginsStacked, withAdditionalParameters: params ?? [:]) default: @@ -908,6 +913,12 @@ import WebKit } }, installDate: StatisticsUserDefaults().installDate ?? Date()) + + _ = NotificationCenter.default.addObserver(forName: AppUserDefaults.Notifications.autofillEnabledChange, + object: nil, + queue: nil) { [weak self] _ in + self?.autofillPixelReporter?.updateAutofillEnabledStatus(AppDependencyProvider.shared.appSettings.autofillCredentialsEnabled) + } } @MainActor diff --git a/DuckDuckGo/AutofillDebugViewController.swift b/DuckDuckGo/AutofillDebugViewController.swift index 118b338bdf..9fcb1604db 100644 --- a/DuckDuckGo/AutofillDebugViewController.swift +++ b/DuckDuckGo/AutofillDebugViewController.swift @@ -29,6 +29,7 @@ class AutofillDebugViewController: UITableViewController { case resetEmailProtectionInContextSignUp = 202 case resetDaysSinceInstalledTo0 = 203 case resetAutofillData = 204 + case addAutofillData = 205 } let defaults = AppUserDefaults() @@ -52,9 +53,12 @@ class AutofillDebugViewController: UITableViewController { try? secureVault?.deleteAllWebsiteCredentials() let autofillPixelReporter = AutofillPixelReporter( userDefaults: .standard, + autofillEnabled: AppUserDefaults().autofillCredentialsEnabled, eventMapping: EventMapping { _, _, _, _ in }) autofillPixelReporter.resetStoreDefaults() ActionMessageView.present(message: "Autofill Data reset") + } else if cell.tag == Row.addAutofillData.rawValue { + promptForNumberOfLoginsToAdd() } else if cell.tag == Row.resetEmailProtectionInContextSignUp.rawValue { EmailManager().resetEmailProtectionInContextPrompt() tableView.deselectRow(at: indexPath, animated: true) @@ -63,7 +67,42 @@ class AutofillDebugViewController: UITableViewController { tableView.deselectRow(at: indexPath, animated: true) } } + } + + private func promptForNumberOfLoginsToAdd() { + let alertController = UIAlertController(title: "Enter number of Logins to add", message: nil, preferredStyle: .alert) + + alertController.addTextField { textField in + textField.placeholder = "Number" + textField.keyboardType = .numberPad + } + + let submitAction = UIAlertAction(title: "Add", style: .default) { [unowned alertController] _ in + let textField = alertController.textFields![0] + if let numberString = textField.text, let number = Int(numberString) { + self.addLogins(number) + } + } + alertController.addAction(submitAction) + alertController.addAction(UIAlertAction(title: "Cancel", style: .cancel)) + present(alertController, animated: true) + } + + private func addLogins(_ count: Int) { + let secureVault = try? AutofillSecureVaultFactory.makeVault(reporter: SecureVaultReporter()) + + for i in 1...count { + let account = SecureVaultModels.WebsiteAccount(title: "", username: "Dax \(i)", domain: "https://fill.dev", notes: "") + let credentials = SecureVaultModels.WebsiteCredentials(account: account, password: "password".data(using: .utf8)) + do { + _ = try secureVault?.storeWebsiteCredentials(credentials) + } catch let error { + os_log(.debug, "Error inserting credential \(error.localizedDescription)") + } + + } + ActionMessageView.present(message: "Autofill Data added") } } diff --git a/DuckDuckGo/Debug.storyboard b/DuckDuckGo/Debug.storyboard index fbcb3cf974..eaeae18022 100644 --- a/DuckDuckGo/Debug.storyboard +++ b/DuckDuckGo/Debug.storyboard @@ -371,12 +371,21 @@ + + + + + + + + + - + @@ -385,7 +394,7 @@ - + @@ -842,17 +851,17 @@ - + - + - + - +