From 6aeb6286a3fc2c33b257057f701e384c1eea6363 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 | 4 +++- ...rPageNavigationHandler+MaliciousSite.swift | 20 ++++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/DuckDuckGo/MaliciousSiteProtection/Settings/MaliciousSiteProtectionSettingsViewModel.swift b/DuckDuckGo/MaliciousSiteProtection/Settings/MaliciousSiteProtectionSettingsViewModel.swift index e16110ee6a..a0dcc466f2 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 @@ -60,6 +62,6 @@ final class MaliciousSiteProtectionSettingsViewModel: ObservableObject { private func updateMaliciousSiteProtection(enabled isEnabled: Bool) { manager.isEnabled = isEnabled isMaliciousSiteProtectionEnabled = isEnabled + PixelKit.fire(MaliciousSiteProtection.Event.settingToggled(to: isEnabled)) } - } diff --git a/DuckDuckGo/SpecialErrorPage/SpecialErrorPageNavigationHandler+MaliciousSite.swift b/DuckDuckGo/SpecialErrorPage/SpecialErrorPageNavigationHandler+MaliciousSite.swift index 5ba6553d11..46dfbf67ac 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() { } }