From 81f4f71fe03cee7c88df178fb1fd0b339a5bc04d Mon Sep 17 00:00:00 2001 From: Alessandro Boron Date: Wed, 8 Jan 2025 12:16:55 +1100 Subject: [PATCH] Implement Pixels --- ...ciousSiteProtectionSettingsViewModel.swift | 6 ++++++ ...rPageNavigationHandler+MaliciousSite.swift | 20 ++++++++++--------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/DuckDuckGo/MaliciousSiteProtection/Settings/MaliciousSiteProtectionSettingsViewModel.swift b/DuckDuckGo/MaliciousSiteProtection/Settings/MaliciousSiteProtectionSettingsViewModel.swift index 626475384f2..cfad4e6f121 100644 --- a/DuckDuckGo/MaliciousSiteProtection/Settings/MaliciousSiteProtectionSettingsViewModel.swift +++ b/DuckDuckGo/MaliciousSiteProtection/Settings/MaliciousSiteProtectionSettingsViewModel.swift @@ -21,6 +21,8 @@ import Foundation import Combine import Core import SwiftUI +import PixelKit +import MaliciousSiteProtection final class MaliciousSiteProtectionSettingsViewModel: ObservableObject { @Published var shouldShowMaliciousSiteProtectionSection = false @@ -50,4 +52,8 @@ final class MaliciousSiteProtectionSettingsViewModel: ObservableObject { urlOpener.open(URL.maliciousSiteProtectionLearnMore) } + private func updateMaliciousSiteProtection(enabled isEnabled: Bool) { + isMaliciousSiteProtectionOn = isEnabled + PixelKit.fire(MaliciousSiteProtection.Event.settingToggled(to: isEnabled)) + } } diff --git a/DuckDuckGo/SpecialErrorPage/SpecialErrorPageNavigationHandler+MaliciousSite.swift b/DuckDuckGo/SpecialErrorPage/SpecialErrorPageNavigationHandler+MaliciousSite.swift index 2d58fc8f9b9..2743e3d0125 100644 --- a/DuckDuckGo/SpecialErrorPage/SpecialErrorPageNavigationHandler+MaliciousSite.swift +++ b/DuckDuckGo/SpecialErrorPage/SpecialErrorPageNavigationHandler+MaliciousSite.swift @@ -23,6 +23,7 @@ import Core import SpecialErrorPages import WebKit import MaliciousSiteProtection +import PixelKit enum MaliciousSiteProtectionNavigationResult: Equatable { case navigationHandled(NavigationType) @@ -109,6 +110,7 @@ extension MaliciousSiteProtectionNavigationHandler: MaliciousSiteProtectionNavig let response = MaliciousSiteDetectionNavigationResponse(navigationAction: navigationAction, errorData: errorData) return .navigationHandled(.mainFrame(response)) } else { + PixelKit.fire(MaliciousSiteProtection.Event.iframeLoaded(category: threatKind)) // Extract the URL of the source frame (the iframe) that initiated the navigation action let iFrameTopURL = navigationAction.sourceFrame.safeRequest?.url ?? url let errorData = SpecialErrorData.maliciousSite(kind: threatKind, url: iFrameTopURL) @@ -137,19 +139,19 @@ extension MaliciousSiteProtectionNavigationHandler: MaliciousSiteProtectionNavig extension MaliciousSiteProtectionNavigationHandler: SpecialErrorPageActionHandler { func visitSite(url: URL, errorData: SpecialErrorData) { - maliciousURLExemptions[url] = errorData.threatKind - bypassedMaliciousSiteThreatKind = errorData.threatKind + guard let threatKind = errorData.threatKind else { + assertionFailure("Error Data should have a threat kind") + return + } + maliciousURLExemptions[url] = threatKind + bypassedMaliciousSiteThreatKind = threatKind - // Fire Pixel + PixelKit.fire(MaliciousSiteProtection.Event.visitSite(category: threatKind)) } - func leaveSite() { - // Fire Pixel - } + func leaveSite() { } - func advancedInfoPresented() { - // Fire Pixel - } + func advancedInfoPresented() { } }