Skip to content

Commit

Permalink
Update to autofill DAU reporting for credential provider extension (#…
Browse files Browse the repository at this point in the history
…3851)

Task/Issue URL:
https://app.asana.com/0/1201462886803403/1208980858161408/f
Tech Design URL:
CC:

**Description**:
Update to include fill events from the iOS credential provider extension
towards Autofill DAUs in AutofillPixelReporter
  • Loading branch information
amddg44 authored Feb 1, 2025
1 parent bf14927 commit 79cbf91
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<array>
<string>$(GROUP_ID_PREFIX).vault</string>
<string>$(GROUP_ID_PREFIX).bookmarks</string>
<string>$(GROUP_ID_PREFIX).statistics</string>
<string>$(GROUP_ID_PREFIX).autofill</string>
</array>
<key>keychain-access-groups</key>
<array>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<array>
<string>$(GROUP_ID_PREFIX).vault</string>
<string>$(GROUP_ID_PREFIX).bookmarks</string>
<string>$(GROUP_ID_PREFIX).statistics</string>
<string>$(GROUP_ID_PREFIX).autofill</string>
</array>
<key>keychain-access-groups</key>
<array>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,28 @@ class CredentialProviderViewController: ASCredentialProviderViewController {
private lazy var vaultCredentialManager: VaultCredentialManaging = VaultCredentialManager(secureVault: secureVault,
credentialIdentityStoreManager: credentialIdentityStoreManager)

private lazy var autofillPixelReporter: AutofillPixelReporter? = {
guard let sharedUserDefaults = UserDefaults(suiteName: "\(Global.groupIdPrefix).autofill"), sharedUserDefaults.bool(forKey: AutofillPixelReporter.Keys.autofillDauMigratedKey) else {
return nil
}

return AutofillPixelReporter(
standardUserDefaults: .standard,
appGroupUserDefaults: UserDefaults(suiteName: "\(Global.groupIdPrefix).autofill"),
autofillEnabled: true,
eventMapping: EventMapping<AutofillPixelEvent> { event, _, params, _ in
switch event {
case .autofillActiveUser:
Pixel.fire(pixel: .autofillActiveUser)
case .autofillLoginsStacked:
Pixel.fire(pixel: .autofillLoginsStacked, withAdditionalParameters: params ?? [:])
default:
break
}
},
installDate: StatisticsUserDefaults().installDate ?? Date())
}()

// MARK: - ASCredentialProviderViewController Overrides

override func prepareCredentialList(for serviceIdentifiers: [ASCredentialServiceIdentifier]) {
Expand Down Expand Up @@ -148,10 +170,12 @@ class CredentialProviderViewController: ASCredentialProviderViewController {
let credential = self.vaultCredentialManager.fetchCredential(for: item.account)

self.extensionContext.completeRequest(withSelectedCredential: credential, completionHandler: nil)
reportFillEvent()

}, onTextProvided: { [weak self] text in
if #available(iOSApplicationExtension 18.0, *) {
self?.extensionContext.completeRequest(withTextToInsert: text)
self?.reportFillEvent()
}
}, onDismiss: {
self.extensionContext.cancelRequest(withError: NSError(domain: ASExtensionErrorDomain,
Expand All @@ -178,6 +202,7 @@ class CredentialProviderViewController: ASCredentialProviderViewController {

self.extensionContext.completeRequest(withSelectedCredential: passwordCredential)
Pixel.fire(pixel: .autofillExtensionQuickTypeConfirmed)
reportFillEvent()
}

private func provideCredential(for credentialIdentity: ASPasswordCredentialIdentity) {
Expand All @@ -190,6 +215,7 @@ class CredentialProviderViewController: ASCredentialProviderViewController {

self.extensionContext.completeRequest(withSelectedCredential: passwordCredential)
Pixel.fire(pixel: .autofillExtensionQuickTypeConfirmed)
reportFillEvent()
}

private func authenticateAndHandleCredential(provideCredential: @escaping () -> Void) {
Expand Down Expand Up @@ -239,4 +265,10 @@ class CredentialProviderViewController: ASCredentialProviderViewController {

return !itemsWithV4.isEmpty
}

private func reportFillEvent() {
guard let autofillPixelReporter = autofillPixelReporter else { return }

NotificationCenter.default.post(name: .autofillFillEvent, object: nil)
}
}
4 changes: 2 additions & 2 deletions DuckDuckGo-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11958,8 +11958,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/DuckDuckGo/BrowserServicesKit.git";
requirement = {
branch = "graeme/fix-backfill-pixels";
kind = branch;
kind = exactVersion;
version = 233.1.0;
};
};
9F8FE9472BAE50E50071E372 /* XCRemoteSwiftPackageReference "lottie-spm" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/DuckDuckGo/BrowserServicesKit.git",
"state" : {
"branch" : "graeme/fix-backfill-pixels",
"revision" : "b1bc5c639b5fc9652d0a8bcd11e0bdf96f7f559a"
"revision" : "b874310b6db6687ef6be5f978edf2f5d03b7fc69",
"version" : "233.1.0"
}
},
{
Expand All @@ -59,8 +59,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/duckduckgo-autofill.git",
"state" : {
"revision" : "47c26dc32b94cdbcef3e6157497147917678c25c",
"version" : "16.1.0"
"revision" : "676d42679296a175169e433f2332e55644151edd",
"version" : "16.2.0"
}
},
{
Expand Down
3 changes: 2 additions & 1 deletion DuckDuckGo/AppLifecycle/AppStates/Launching.swift
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,8 @@ struct Launching: AppState {

let autofillUsageMonitor = AutofillUsageMonitor()
autofillPixelReporter = AutofillPixelReporter(
userDefaults: .standard,
standardUserDefaults: .standard,
appGroupUserDefaults: UserDefaults(suiteName: "\(Global.groupIdPrefix).autofill"),
autofillEnabled: AppDependencyProvider.shared.appSettings.autofillCredentialsEnabled,
eventMapping: EventMapping<AutofillPixelEvent> {event, _, params, _ in
switch event {
Expand Down
7 changes: 4 additions & 3 deletions DuckDuckGo/AutofillDebugViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ class AutofillDebugViewController: UITableViewController {
let secureVault = try? AutofillSecureVaultFactory.makeVault(reporter: SecureVaultReporter())
try? secureVault?.deleteAllWebsiteCredentials()
let autofillPixelReporter = AutofillPixelReporter(
userDefaults: .standard,
standardUserDefaults: .standard,
appGroupUserDefaults: UserDefaults(suiteName: "\(Global.groupIdPrefix).autofill"),
autofillEnabled: AppUserDefaults().autofillCredentialsEnabled,
eventMapping: EventMapping<AutofillPixelEvent> { _, _, _, _ in })
autofillPixelReporter.resetStoreDefaults()
Expand Down Expand Up @@ -101,7 +102,7 @@ class AutofillDebugViewController: UITableViewController {
}

private func promptForNumberOfLoginsToAdd() {
let alertController = UIAlertController(title: "Enter number of Logins to add", message: nil, preferredStyle: .alert)
let alertController = UIAlertController(title: "Enter number of Logins to add for autofill.me", message: nil, preferredStyle: .alert)

alertController.addTextField { textField in
textField.placeholder = "Number"
Expand All @@ -123,7 +124,7 @@ class AutofillDebugViewController: UITableViewController {
let secureVault = try? AutofillSecureVaultFactory.makeVault(reporter: SecureVaultReporter())

for i in 1...count {
let account = SecureVaultModels.WebsiteAccount(title: "", username: "Dax \(i)", domain: "fill.dev", notes: "")
let account = SecureVaultModels.WebsiteAccount(title: "", username: "Dax \(i)", domain: "autofill.me", notes: "")
let credentials = SecureVaultModels.WebsiteCredentials(account: account, password: "password".data(using: .utf8))
do {
_ = try secureVault?.storeWebsiteCredentials(credentials)
Expand Down
1 change: 1 addition & 0 deletions DuckDuckGo/DuckDuckGo.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<string>$(GROUP_ID_PREFIX).statistics</string>
<string>group.com.duckduckgo.app-configuration</string>
<string>$(GROUP_ID_PREFIX).vault</string>
<string>$(GROUP_ID_PREFIX).autofill</string>
</array>
<key>keychain-access-groups</key>
<array>
Expand Down
1 change: 1 addition & 0 deletions DuckDuckGo/DuckDuckGoAlpha.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<string>group.com.duckduckgo.alpha.netp</string>
<string>group.com.duckduckgo.alpha.statistics</string>
<string>group.com.duckduckgo.alpha.vault</string>
<string>group.com.duckduckgo.alpha.autofill</string>
</array>
<key>keychain-access-groups</key>
<array>
Expand Down

0 comments on commit 79cbf91

Please sign in to comment.