Skip to content

Commit

Permalink
Merge branch 'main' into sam/privacy-pro-surveys
Browse files Browse the repository at this point in the history
# By Fernando Bunn (3) and others
# Via GitHub
* main:
  Autofill engagement KPIs for pixel reporting (#2806)
  autofill: don't prefix autofill email pixels with `m.mac.` (#2808)
  Bump BSK (#2807)
  Make profile selector optional (#2811)
  Add History to iOS (updated UI and rollout) (#2770)
  New autofill save & update password prompt pixels for alignment with iOS (#2801)
  Add mylife data broker (#2786)
  Increase test timeout (#2810)
  Subscription refactoring, BSK update (#2809)
  Check for entitlement in DBP agent (#2802)
  move permanent survey card to first position (#2804)

# Conflicts:
#	DuckDuckGo.xcodeproj/project.pbxproj
  • Loading branch information
samsymons committed May 23, 2024
2 parents e598a9f + 22905cd commit d8dab5c
Show file tree
Hide file tree
Showing 29 changed files with 976 additions and 380 deletions.
73 changes: 36 additions & 37 deletions DuckDuckGo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/BrowserServicesKit",
"state" : {
"branch" : "fcappelli/subscription_refactoring_2",
"revision" : "874ae4269db821797742655e134e72199c2813c8"
"revision" : "e1e436422bc167933baa0f90838958f2ac7119f3",
"version" : "146.2.0"
}
},
{
"identity" : "content-scope-scripts",
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/content-scope-scripts",
"state" : {
"revision" : "bb8e7e62104ed6506c7bfd3ef7aa4aca3686ed4f",
"version" : "5.15.0"
"revision" : "fa861c4eccb21d235e34070b208b78bdc32ece08",
"version" : "5.17.0"
}
},
{
Expand Down Expand Up @@ -131,8 +131,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser.git",
"state" : {
"revision" : "46989693916f56d1186bd59ac15124caef896560",
"version" : "1.3.1"
"revision" : "0fbc8848e389af3bb55c182bc19ca9d5dc2f255b",
"version" : "1.4.0"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1530"
version = "1.8">
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
Expand Down
37 changes: 32 additions & 5 deletions DuckDuckGo/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
let featureFlagger: FeatureFlagger
private var appIconChanger: AppIconChanger!
private var autoClearHandler: AutoClearHandler!
private(set) var autofillPixelReporter: AutofillPixelReporter?

private(set) var syncDataProviders: SyncDataProviders!
private(set) var syncService: DDGSyncing?
Expand All @@ -94,7 +95,13 @@ final class AppDelegate: NSObject, NSApplicationDelegate {

private var networkProtectionSubscriptionEventHandler: NetworkProtectionSubscriptionEventHandler?
#if DBP
private var dataBrokerProtectionSubscriptionEventHandler: DataBrokerProtectionSubscriptionEventHandler?
private lazy var dataBrokerProtectionSubscriptionEventHandler: DataBrokerProtectionSubscriptionEventHandler = {
let authManager = DataBrokerAuthenticationManagerBuilder.buildAuthenticationManager(subscriptionManager: subscriptionManager)
return DataBrokerProtectionSubscriptionEventHandler(featureDisabler: DataBrokerProtectionFeatureDisabler(),
authenticationManager: authManager,
pixelHandler: DataBrokerProtectionPixelsHandler())
}()

#endif

private var didFinishLaunching = false
Expand Down Expand Up @@ -216,9 +223,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
networkProtectionSubscriptionEventHandler = NetworkProtectionSubscriptionEventHandler(subscriptionManager: subscriptionManager,
tunnelController: tunnelController,
vpnUninstaller: vpnUninstaller)
#if DBP
dataBrokerProtectionSubscriptionEventHandler = DataBrokerProtectionSubscriptionEventHandler(subscriptionManager: subscriptionManager)
#endif
}

// swiftlint:disable:next function_body_length
Expand Down Expand Up @@ -310,14 +314,16 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
UNUserNotificationCenter.current().delegate = self

#if DBP
dataBrokerProtectionSubscriptionEventHandler?.registerForSubscriptionAccountManagerEvents()
dataBrokerProtectionSubscriptionEventHandler.registerForSubscriptionAccountManagerEvents()
#endif

#if DBP
DataBrokerProtectionAppEvents().applicationDidFinishLaunching()
#endif

setUpAutoClearHandler()

setUpAutofillPixelReporter()
}

func applicationDidBecomeActive(_ notification: Notification) {
Expand Down Expand Up @@ -584,6 +590,27 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
}
}
}

private func setUpAutofillPixelReporter() {
autofillPixelReporter = AutofillPixelReporter(
userDefaults: .standard,
eventMapping: EventMapping<AutofillPixelEvent> {event, _, params, _ in
switch event {
case .autofillActiveUser:
PixelKit.fire(GeneralPixel.autofillActiveUser)
case .autofillEnabledUser:
PixelKit.fire(GeneralPixel.autofillEnabledUser)
case .autofillOnboardedUser:
PixelKit.fire(GeneralPixel.autofillOnboardedUser)
case .autofillLoginsStacked:
PixelKit.fire(GeneralPixel.autofillLoginsStacked, withAdditionalParameters: params)
case .autofillCreditCardsStacked:
PixelKit.fire(GeneralPixel.autofillCreditCardsStacked, withAdditionalParameters: params)
}
},
passwordManager: PasswordManagerCoordinator.shared,
installDate: AppDelegate.firstLaunchDate)
}
}

extension AppDelegate: UNUserNotificationCenterDelegate {
Expand Down
7 changes: 6 additions & 1 deletion DuckDuckGo/Autofill/ContentOverlayViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ extension ContentOverlayViewController: SecureVaultManagerDelegate {

public func secureVaultManager(_: SecureVaultManager, didAutofill type: AutofillType, withObjectId objectId: String) {
PixelKit.fire(GeneralPixel.formAutofilled(kind: type.formAutofillKind))
NotificationCenter.default.post(name: .autofillFillEvent, object: nil)

if type.formAutofillKind == .password &&
passwordManagerCoordinator.isEnabled {
Expand Down Expand Up @@ -325,8 +326,12 @@ extension ContentOverlayViewController: SecureVaultManagerDelegate {

self.emailManager.updateLastUseDate()

PixelKit.fire(GeneralPixel.jsPixel(pixel), withAdditionalParameters: pixelParameters)
PixelKit.fire(NonStandardEvent(GeneralPixel.jsPixel(pixel)), withAdditionalParameters: pixelParameters)
NotificationCenter.default.post(name: .autofillFillEvent, object: nil)
} else {
if pixel.isIdentityPixel {
NotificationCenter.default.post(name: .autofillFillEvent, object: nil)
}
PixelKit.fire(GeneralPixel.jsPixel(pixel), withAdditionalParameters: pixel.pixelParameters)
}
}
Expand Down
6 changes: 5 additions & 1 deletion DuckDuckGo/DBP/DataBrokerProtectionPixelsHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ public class DataBrokerProtectionPixelsHandler: EventMapping<DataBrokerProtectio
.homeViewShowWebUI,
.homeViewShowBadPathError,
.homeViewCTAMoveApplicationClicked,
.homeViewCTAGrantPermissionClicked:
.homeViewCTAGrantPermissionClicked,

.entitlementCheckValid,
.entitlementCheckInvalid,
.entitlementCheckError:
PixelKit.fire(event, frequency: .dailyAndCount)
}
}
Expand Down
43 changes: 35 additions & 8 deletions DuckDuckGo/DBP/DataBrokerProtectionSubscriptionEventHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,55 @@ import Foundation
import Subscription
import DataBrokerProtection
import PixelKit
import Common

final class DataBrokerProtectionSubscriptionEventHandler {

private let subscriptionManager: SubscriptionManaging
private let authRepository: AuthenticationRepository
private let authenticationManager: DataBrokerProtectionAuthenticationManaging
private let featureDisabler: DataBrokerProtectionFeatureDisabling
private let pixelHandler: EventMapping<DataBrokerProtectionPixels>

init(subscriptionManager: SubscriptionManaging,
authRepository: AuthenticationRepository = KeychainAuthenticationData(),
featureDisabler: DataBrokerProtectionFeatureDisabling = DataBrokerProtectionFeatureDisabler()) {
self.subscriptionManager = subscriptionManager
self.authRepository = authRepository
init(featureDisabler: DataBrokerProtectionFeatureDisabling,
authenticationManager: DataBrokerProtectionAuthenticationManaging,
pixelHandler: EventMapping<DataBrokerProtectionPixels>) {
self.featureDisabler = featureDisabler
self.authenticationManager = authenticationManager
self.pixelHandler = pixelHandler
}

func registerForSubscriptionAccountManagerEvents() {
NotificationCenter.default.addObserver(self, selector: #selector(handleAccountDidSignOut), name: .accountDidSignOut, object: nil)
NotificationCenter.default.addObserver(self,
selector: #selector(handleAccountDidSignOut),
name: .accountDidSignOut,
object: nil)

NotificationCenter.default.addObserver(self,
selector: #selector(entitlementsDidChange),
name: .entitlementsDidChange,
object: nil)
}

@objc private func handleAccountDidSignOut() {
featureDisabler.disableAndDelete()
}

@objc private func entitlementsDidChange() {
Task { @MainActor in
do {
if try await authenticationManager.hasValidEntitlement() {
pixelHandler.fire(.entitlementCheckValid)
} else {
pixelHandler.fire(.entitlementCheckInvalid)
featureDisabler.disableAndDelete()
}
} catch {
/// We don't want to disable the agent in case of an error while checking for entitlements.
/// Since this is a destructive action, the only situation that should cause the data to be deleted and the agent to be removed is .success(false)
pixelHandler.fire(.entitlementCheckError)
assertionFailure("Error validating entitlement \(error)")
}
}
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ final class SecureVaultLoginImporter: LoginImporter {
}
}

if successful.count > 0 {
NotificationCenter.default.post(name: .autofillSaveEvent, object: nil, userInfo: nil)
}

return .init(successful: successful.count, duplicate: duplicates.count, failed: failed.count)
}

Expand Down
10 changes: 4 additions & 6 deletions DuckDuckGo/HomePage/Model/HomePageContinueSetUpModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,10 @@ extension HomePage.Models {
}

var randomisedFeatures: [FeatureType] {
var features = FeatureType.allCases
features.shuffle()
for (index, feature) in features.enumerated() where feature == .defaultBrowser {
features.remove(at: index)
features.insert(feature, at: 0)
}
var features: [FeatureType] = [.permanentSurvey, .defaultBrowser]
var shuffledFeatures = FeatureType.allCases.filter { $0 != .defaultBrowser && $0 != .permanentSurvey }
shuffledFeatures.shuffle()
features.append(contentsOf: shuffledFeatures)
return features
}

Expand Down
3 changes: 3 additions & 0 deletions DuckDuckGo/Menus/MainMenuActions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,9 @@ extension MainViewController {
try? vault?.deleteNoteFor(noteId: noteID)
}
UserDefaults.standard.set(false, forKey: UserDefaultsWrapper<Bool>.Key.homePageContinueSetUpImport.rawValue)

let autofillPixelReporter = AutofillPixelReporter(userDefaults: .standard, eventMapping: EventMapping<AutofillPixelEvent> { _, _, _, _ in }, installDate: nil)
autofillPixelReporter.resetStoreDefaults()
}

@objc func resetBookmarks(_ sender: Any?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ final class PasswordManagementViewController: NSViewController {
refetchWithText(searchField.stringValue) { [weak self] in
self?.syncModelsOnCredentials(savedCredentials, select: true)
}
NotificationCenter.default.post(name: .autofillSaveEvent, object: nil, userInfo: nil)
} else {
syncModelsOnCredentials(savedCredentials)
}
Expand Down
Loading

0 comments on commit d8dab5c

Please sign in to comment.