Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.

Commit 53a405f

Browse files
authored
Fire a pixel when removing the VPN configuration (#3014)
Task/Issue URL: https://app.asana.com/0/414235014887631/1207698850203829/f Tech Design URL: CC: Description: This PR adds a pixel that reports when the VPN configuration has been removed, and why.
1 parent 62131b2 commit 53a405f

5 files changed

+33
-22
lines changed

Core/PixelEvent.swift

+6
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,9 @@ extension Pixel {
416416
case networkProtectionDNSUpdateCustom
417417
case networkProtectionDNSUpdateDefault
418418

419+
case networkProtectionVPNConfigurationRemoved
420+
case networkProtectionVPNConfigurationRemovalFailed
421+
419422
// MARK: remote messaging pixels
420423

421424
case remoteMessageShown
@@ -1102,6 +1105,9 @@ extension Pixel.Event {
11021105
case .networkProtectionDNSUpdateCustom: return "m_netp_ev_update_dns_custom"
11031106
case .networkProtectionDNSUpdateDefault: return "m_netp_ev_update_dns_default"
11041107

1108+
case .networkProtectionVPNConfigurationRemoved: return "m_netp_vpn_configuration_removed"
1109+
case .networkProtectionVPNConfigurationRemovalFailed: return "m_netp_vpn_configuration_removal_failed"
1110+
11051111
// MARK: remote messaging pixels
11061112

11071113
case .remoteMessageShown: return "m_remote_message_shown"

DuckDuckGo/AppDelegate.swift

+5-17
Original file line numberDiff line numberDiff line change
@@ -512,15 +512,14 @@ import WebKit
512512
#if NETWORK_PROTECTION
513513
widgetRefreshModel.refreshVPNWidget()
514514

515-
stopTunnelAndShowThankYouMessagingIfNeeded()
516-
517515
if tunnelDefaults.showEntitlementAlert {
518516
presentExpiredEntitlementAlert()
519517
}
520518

521519
presentExpiredEntitlementNotificationIfNeeded()
522520

523521
Task {
522+
await stopAndRemoveVPNIfNotAuthenticated()
524523
await refreshShortcuts()
525524
await vpnWorkaround.installRedditSessionWorkaround()
526525
}
@@ -536,25 +535,14 @@ import WebKit
536535
importPasswordsStatusHandler.checkSyncSuccessStatus()
537536
}
538537

539-
private func stopTunnelAndShowThankYouMessagingIfNeeded() {
540-
if accountManager.isUserAuthenticated {
541-
return
542-
}
543-
544-
if AppDependencyProvider.shared.vpnFeatureVisibility.isPrivacyProLaunched() && !accountManager.isUserAuthenticated {
545-
Task {
546-
await self.stopAndRemoveVPN(with: "subscription-check")
547-
}
548-
}
549-
}
550-
551-
private func stopAndRemoveVPN(with reason: String) async {
552-
guard await AppDependencyProvider.shared.networkProtectionTunnelController.isInstalled else {
538+
private func stopAndRemoveVPNIfNotAuthenticated() async {
539+
// Only remove the VPN if the user is not authenticated, and it's installed:
540+
guard !accountManager.isUserAuthenticated, await AppDependencyProvider.shared.networkProtectionTunnelController.isInstalled else {
553541
return
554542
}
555543

556544
await AppDependencyProvider.shared.networkProtectionTunnelController.stop()
557-
await AppDependencyProvider.shared.networkProtectionTunnelController.removeVPN()
545+
await AppDependencyProvider.shared.networkProtectionTunnelController.removeVPN(reason: .didBecomeActiveCheck)
558546
}
559547

560548
func applicationWillResignActive(_ application: UIApplication) {

DuckDuckGo/MainViewController.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -1503,15 +1503,15 @@ class MainViewController: UIViewController {
15031503
}
15041504

15051505
await networkProtectionTunnelController.stop()
1506-
await networkProtectionTunnelController.removeVPN()
1506+
await networkProtectionTunnelController.removeVPN(reason: .entitlementCheck)
15071507
}
15081508
}
15091509

15101510
@objc
15111511
private func onNetworkProtectionAccountSignOut(_ notification: Notification) {
15121512
Task {
15131513
await networkProtectionTunnelController.stop()
1514-
await networkProtectionTunnelController.removeVPN()
1514+
await networkProtectionTunnelController.removeVPN(reason: .signedOut)
15151515
}
15161516
}
15171517
#endif

DuckDuckGo/NetworkProtectionDebugViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ shouldShowVPNShortcut: \(vpnVisibility.shouldShowVPNShortcut() ? "YES" : "NO")
700700
private func deleteVPNConfiguration() {
701701
Task {
702702
await AppDependencyProvider.shared.networkProtectionTunnelController.stop()
703-
await AppDependencyProvider.shared.networkProtectionTunnelController.removeVPN()
703+
await AppDependencyProvider.shared.networkProtectionTunnelController.removeVPN(reason: .debugMenu)
704704
}
705705
}
706706
}

DuckDuckGo/NetworkProtectionTunnelController.swift

+19-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ import NetworkExtension
2626
import NetworkProtection
2727
import Subscription
2828

29+
enum VPNConfigurationRemovalReason: String {
30+
case didBecomeActiveCheck
31+
case entitlementCheck
32+
case signedOut
33+
case debugMenu
34+
}
35+
2936
final class NetworkProtectionTunnelController: TunnelController {
3037
static var shouldSimulateFailure: Bool = false
3138

@@ -114,8 +121,18 @@ final class NetworkProtectionTunnelController: TunnelController {
114121
tunnelManager.connection.stopVPNTunnel()
115122
}
116123

117-
func removeVPN() async {
118-
try? await tunnelManager?.removeFromPreferences()
124+
func removeVPN(reason: VPNConfigurationRemovalReason) async {
125+
do {
126+
try await tunnelManager?.removeFromPreferences()
127+
128+
DailyPixel.fireDailyAndCount(pixel: .networkProtectionVPNConfigurationRemoved, withAdditionalParameters: [
129+
PixelParameters.reason: reason.rawValue
130+
])
131+
} catch {
132+
DailyPixel.fireDailyAndCount(pixel: .networkProtectionVPNConfigurationRemovalFailed, error: error, withAdditionalParameters: [
133+
PixelParameters.reason: reason.rawValue
134+
])
135+
}
119136
}
120137

121138
// MARK: - Connection Status Querying

0 commit comments

Comments
 (0)