From 4ed29ad39d8b913307deb6e798fd6c353b1cf519 Mon Sep 17 00:00:00 2001
From: Shane Osbourne <sosbourne@duckduckgo.com>
Date: Thu, 19 Oct 2023 15:23:34 +0100
Subject: [PATCH] dashboard updates

---
 DuckDuckGo.xcodeproj/project.pbxproj                |  4 ++--
 .../xcshareddata/swiftpm/Package.resolved           | 13 ++++++-------
 .../View/PrivacyDashboardViewController.swift       |  6 ++++--
 DuckDuckGo/Statistics/PixelEvent.swift              | 11 +++++++++++
 DuckDuckGo/Statistics/PixelParameters.swift         |  8 ++++++++
 .../Sources/PixelKit/PixelKit+Parameters.swift      |  3 +++
 6 files changed, 34 insertions(+), 11 deletions(-)

diff --git a/DuckDuckGo.xcodeproj/project.pbxproj b/DuckDuckGo.xcodeproj/project.pbxproj
index 9362900700..a16469abe0 100644
--- a/DuckDuckGo.xcodeproj/project.pbxproj
+++ b/DuckDuckGo.xcodeproj/project.pbxproj
@@ -14338,8 +14338,8 @@
 			isa = XCRemoteSwiftPackageReference;
 			repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit";
 			requirement = {
-				kind = exactVersion;
-				version = 81.4.0;
+				branch = "shane/form-updates";
+				kind = branch;
 			};
 		};
 		AA06B6B52672AF8100F541C5 /* XCRemoteSwiftPackageReference "Sparkle" */ = {
diff --git a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
index 61061163db..0ba9bb6570 100644
--- a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
+++ b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
@@ -14,8 +14,8 @@
       "kind" : "remoteSourceControl",
       "location" : "https://github.com/duckduckgo/BrowserServicesKit",
       "state" : {
-        "revision" : "4cf8e857cd78e15c64ba37839634970fc675947c",
-        "version" : "81.4.0"
+        "branch" : "shane/form-updates",
+        "revision" : "7184e09228bdc6fba213e9d8ec109ec0f3c58f40"
       }
     },
     {
@@ -23,8 +23,8 @@
       "kind" : "remoteSourceControl",
       "location" : "https://github.com/duckduckgo/content-scope-scripts",
       "state" : {
-        "revision" : "254b23cf292140498650421bb31fd05740f4579b",
-        "version" : "4.40.0"
+        "revision" : "aa279a3b006a0b1e009707311283c7fcaed24fb7",
+        "version" : "4.39.0"
       }
     },
     {
@@ -77,8 +77,7 @@
       "kind" : "remoteSourceControl",
       "location" : "https://github.com/duckduckgo/privacy-dashboard",
       "state" : {
-        "revision" : "51e2b46f413bf3ef18afefad631ca70f2c25ef70",
-        "version" : "1.4.0"
+        "revision" : "f505d33c24568af44b770aaa60d64ff1564de9dc"
       }
     },
     {
@@ -129,7 +128,7 @@
     {
       "identity" : "trackerradarkit",
       "kind" : "remoteSourceControl",
-      "location" : "https://github.com/duckduckgo/TrackerRadarKit.git",
+      "location" : "https://github.com/duckduckgo/TrackerRadarKit",
       "state" : {
         "revision" : "4684440d03304e7638a2c8086895367e90987463",
         "version" : "1.2.1"
diff --git a/DuckDuckGo/PrivacyDashboard/View/PrivacyDashboardViewController.swift b/DuckDuckGo/PrivacyDashboard/View/PrivacyDashboardViewController.swift
index 538096a36e..55dfa66272 100644
--- a/DuckDuckGo/PrivacyDashboard/View/PrivacyDashboardViewController.swift
+++ b/DuckDuckGo/PrivacyDashboard/View/PrivacyDashboardViewController.swift
@@ -171,16 +171,18 @@ final class PrivacyDashboardViewController: NSViewController {
 
 extension PrivacyDashboardViewController: PrivacyDashboardControllerDelegate {
 
-    func privacyDashboardController(_ privacyDashboardController: PrivacyDashboardController, didChangeProtectionSwitch isEnabled: Bool) {
+    func privacyDashboardController(_ privacyDashboardController: PrivacyDashboardController, didChangeProtectionSwitch protectionState: ProtectionState) {
         guard let domain = privacyDashboardController.privacyInfo?.url.host else {
             return
         }
 
         let configuration = ContentBlocking.shared.privacyConfigurationManager.privacyConfig
-        if isEnabled && configuration.isUserUnprotected(domain: domain) {
+        if protectionState.isProtected && configuration.isUserUnprotected(domain: domain) {
             configuration.userEnabledProtection(forDomain: domain)
+            Pixel.fire(.dashboardProtectionAllowlistRemove(triggerOrigin: protectionState.eventOrigin.screen.rawValue))
         } else {
             configuration.userDisabledProtection(forDomain: domain)
+            Pixel.fire(.dashboardProtectionAllowlistAdd(triggerOrigin: protectionState.eventOrigin.screen.rawValue))
         }
 
         let completionToken = ContentBlocking.shared.contentBlockingManager.scheduleCompilation()
diff --git a/DuckDuckGo/Statistics/PixelEvent.swift b/DuckDuckGo/Statistics/PixelEvent.swift
index 378f69b640..b7dfe1884f 100644
--- a/DuckDuckGo/Statistics/PixelEvent.swift
+++ b/DuckDuckGo/Statistics/PixelEvent.swift
@@ -155,6 +155,10 @@ extension Pixel {
         case duckPlayerSettingNever
         case duckPlayerSettingBackToDefault
 
+        // Dashboard
+        case dashboardProtectionAllowlistAdd(triggerOrigin: String?)
+        case dashboardProtectionAllowlistRemove(triggerOrigin: String?)
+
         // Network Protection Waitlist
         case networkProtectionWaitlistUserActive
         case networkProtectionWaitlistEntryPointMenuItemDisplayed
@@ -445,6 +449,13 @@ extension Pixel.Event {
             return "m_mac_duck-player_setting_never"
         case .duckPlayerSettingBackToDefault:
             return "m_mac_duck-player_setting_back-to-default"
+        case .duckPlayerSettingBackToDefault:
+            return "m_mac_duck-player_setting_back-to-default"
+
+        case .dashboardProtectionAllowlistAdd(let triggerOrigin):
+            return "m_mac_mp_wla"
+        case .dashboardProtectionAllowlistRemove(let triggerOrigin):
+            return "m_mac_mp_wlr"
 
         case .launchInitial:
             return "m.mac.first-launch"
diff --git a/DuckDuckGo/Statistics/PixelParameters.swift b/DuckDuckGo/Statistics/PixelParameters.swift
index 2fab15b4f1..bc5fbb8724 100644
--- a/DuckDuckGo/Statistics/PixelParameters.swift
+++ b/DuckDuckGo/Statistics/PixelParameters.swift
@@ -52,6 +52,14 @@ extension Pixel.Event {
         case .dailyPixel(let pixel, isFirst: _):
             return pixel.parameters
 
+        case .dashboardProtectionAllowlistAdd(let triggerOrigin):
+            guard let trigger = triggerOrigin else { return nil }
+            return [PixelKit.Parameters.dashboardTriggerOrigin: trigger]
+
+        case .dashboardProtectionAllowlistRemove(let triggerOrigin):
+            guard let trigger = triggerOrigin else { return nil }
+            return [PixelKit.Parameters.dashboardTriggerOrigin: trigger]
+
         // Don't use default to force new items to be thought about
         case .crash,
              .brokenSiteReport,
diff --git a/LocalPackages/PixelKit/Sources/PixelKit/PixelKit+Parameters.swift b/LocalPackages/PixelKit/Sources/PixelKit/PixelKit+Parameters.swift
index 6d5d65c57d..e3ab83f59d 100644
--- a/LocalPackages/PixelKit/Sources/PixelKit/PixelKit+Parameters.swift
+++ b/LocalPackages/PixelKit/Sources/PixelKit/PixelKit+Parameters.swift
@@ -53,6 +53,9 @@ public extension PixelKit {
 
         // Pixel experiments
         public static let experimentCohort = "cohort"
+
+        // Dashboard
+        public static let dashboardTriggerOrigin = "trigger_origin"
     }
 
     enum Values {