Skip to content

Commit

Permalink
Additional Autofill KPI pixels (#2943)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
amddg44 authored Jun 19, 2024
1 parent 56ded44 commit faac727
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 12 deletions.
5 changes: 5 additions & 0 deletions Core/PixelEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ extension Pixel {
case autofillActiveUser
case autofillEnabledUser
case autofillOnboardedUser
case autofillToggledOn
case autofillToggledOff
case autofillLoginsStacked

case autofillMultipleAuthCallsTriggered
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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" */ = {
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",
"state" : {
"revision" : "61df946265d05c401b472d76f837a13552722367",
"version" : "158.0.0"
"revision" : "201a932642275eeccc213940a1e85c6c19a6f3d0",
"version" : "158.1.0"
}
},
{
Expand Down
11 changes: 11 additions & 0 deletions DuckDuckGo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,7 @@ import WebKit
private func setUpAutofillPixelReporter() {
autofillPixelReporter = AutofillPixelReporter(
userDefaults: .standard,
autofillEnabled: AppDependencyProvider.shared.appSettings.autofillCredentialsEnabled,
eventMapping: EventMapping<AutofillPixelEvent> {event, _, params, _ in
switch event {
case .autofillActiveUser:
Expand All @@ -901,13 +902,23 @@ 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:
break
}
},
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
Expand Down
39 changes: 39 additions & 0 deletions DuckDuckGo/AutofillDebugViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class AutofillDebugViewController: UITableViewController {
case resetEmailProtectionInContextSignUp = 202
case resetDaysSinceInstalledTo0 = 203
case resetAutofillData = 204
case addAutofillData = 205
}

let defaults = AppUserDefaults()
Expand All @@ -52,9 +53,12 @@ class AutofillDebugViewController: UITableViewController {
try? secureVault?.deleteAllWebsiteCredentials()
let autofillPixelReporter = AutofillPixelReporter(
userDefaults: .standard,
autofillEnabled: AppUserDefaults().autofillCredentialsEnabled,
eventMapping: EventMapping<AutofillPixelEvent> { _, _, _, _ 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)
Expand All @@ -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")
}

}
27 changes: 18 additions & 9 deletions DuckDuckGo/Debug.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -371,12 +371,21 @@
</tableViewCellContentView>
<listContentConfiguration key="contentConfiguration" text="Reset Autofill Data" secondaryText=""/>
</tableViewCell>
<tableViewCell clipsSubviews="YES" tag="205" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" id="Sjd-Vj-2U1">
<rect key="frame" x="0.0" y="139" width="414" height="44.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="Sjd-Vj-2U1" id="xcw-b6-0cK">
<rect key="frame" x="0.0" y="0.0" width="414" height="44.5"/>
<autoresizingMask key="autoresizingMask"/>
</tableViewCellContentView>
<listContentConfiguration key="contentConfiguration" text="Add Test Autofill Data" secondaryText=""/>
</tableViewCell>
</cells>
</tableViewSection>
<tableViewSection headerTitle="Email Protection" id="iDX-JX-E1u">
<cells>
<tableViewCell clipsSubviews="YES" tag="202" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" id="tsg-0B-svT">
<rect key="frame" x="0.0" y="217" width="414" height="44.5"/>
<rect key="frame" x="0.0" y="261.5" width="414" height="44.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="tsg-0B-svT" id="waU-fZ-uIn">
<rect key="frame" x="0.0" y="0.0" width="414" height="44.5"/>
Expand All @@ -385,7 +394,7 @@
<listContentConfiguration key="contentConfiguration" text="Reset Email Protection InContext Signup Prompt"/>
</tableViewCell>
<tableViewCell clipsSubviews="YES" tag="203" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" id="zG5-R0-kxQ">
<rect key="frame" x="0.0" y="261.5" width="414" height="44.5"/>
<rect key="frame" x="0.0" y="306" width="414" height="44.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="zG5-R0-kxQ" id="4zQ-oz-2TS">
<rect key="frame" x="0.0" y="0.0" width="414" height="44.5"/>
Expand Down Expand Up @@ -842,17 +851,17 @@
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="ConfigurationURLTableViewCell" id="i6Y-Di-PX3" customClass="ConfigurationURLTableViewCell" customModule="DuckDuckGo" customModuleProvider="target">
<rect key="frame" x="0.0" y="50" width="414" height="85.5"/>
<rect key="frame" x="0.0" y="50" width="414" height="86"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="i6Y-Di-PX3" id="qn4-gq-5fa">
<rect key="frame" x="0.0" y="0.0" width="414" height="85.5"/>
<rect key="frame" x="0.0" y="0.0" width="414" height="86"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" distribution="equalSpacing" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="pKD-Xm-Eu1">
<rect key="frame" x="20" y="11" width="374" height="63.5"/>
<rect key="frame" x="20" y="11" width="374" height="64"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" distribution="fillEqually" translatesAutoresizingMaskIntoConstraints="NO" id="j3A-OZ-DWy">
<rect key="frame" x="0.0" y="0.0" width="44" height="63.5"/>
<rect key="frame" x="0.0" y="0.0" width="44" height="64"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="gKw-J7-XIW">
<rect key="frame" x="0.0" y="0.0" width="44" height="21"/>
Expand All @@ -862,22 +871,22 @@
<nil key="highlightedColor"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Subtitle" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="UrI-B0-rWf">
<rect key="frame" x="0.0" y="21" width="44" height="21"/>
<rect key="frame" x="0.0" y="21" width="44" height="21.5"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<color key="textColor" name="accent"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="6RK-ug-mZa">
<rect key="frame" x="0.0" y="42.5" width="44" height="21"/>
<rect key="frame" x="0.0" y="43" width="44" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</stackView>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="right" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Nkj-yK-cgm">
<rect key="frame" x="350" y="0.0" width="24" height="63.5"/>
<rect key="frame" x="350" y="0.0" width="24" height="64"/>
<inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
<state key="normal" image="Reload-24"/>
</button>
Expand Down

0 comments on commit faac727

Please sign in to comment.