Skip to content

Commit

Permalink
Adds pixels to track CC usage for the VPN
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoreymendez committed Dec 16, 2024
1 parent c5704a9 commit b57e2a5
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 12 deletions.
20 changes: 20 additions & 0 deletions Core/PixelEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,16 @@ extension Pixel {
case networkProtectionWidgetDisconnectCancelled
case networkProtectionWidgetDisconnectFailure

case vpnControlCenterConnectAttempt
case vpnControlCenterConnectSuccess
case vpnControlCenterConnectCancelled
case vpnControlCenterConnectFailure

case vpnControlCenterDisconnectAttempt
case vpnControlCenterDisconnectSuccess
case vpnControlCenterDisconnectCancelled
case vpnControlCenterDisconnectFailure

case networkProtectionDNSUpdateCustom
case networkProtectionDNSUpdateDefault

Expand Down Expand Up @@ -1671,6 +1681,16 @@ extension Pixel.Event {
case .networkProtectionWidgetDisconnectCancelled: return "m_netp_widget_disconnect_cancelled"
case .networkProtectionWidgetDisconnectFailure: return "m_netp_widget_disconnect_failure"

case .vpnControlCenterConnectAttempt: return "m_vpn_control-center_connect_attempt"
case .vpnControlCenterConnectSuccess: return "m_vpn_control-center_connect_success"
case .vpnControlCenterConnectCancelled: return "m_vpn_control-center_connect_cancelled"
case .vpnControlCenterConnectFailure: return "m_vpn_control-center_connect_failure"

case .vpnControlCenterDisconnectAttempt: return "m_vpn_control-center_disconnect_attempt"
case .vpnControlCenterDisconnectSuccess: return "m_vpn_control-center_disconnect_success"
case .vpnControlCenterDisconnectCancelled: return "m_vpn_control-center_disconnect_cancelled"
case .vpnControlCenterDisconnectFailure: return "m_vpn_control-center_disconnect_failure"

// MARK: Secure Vault
case .secureVaultL1KeyMigration: return "m_secure-vault_keystore_event_l1-key-migration"
case .secureVaultL2KeyMigration: return "m_secure-vault_keystore_event_l2-key-migration"
Expand Down
47 changes: 35 additions & 12 deletions DuckDuckGo/VPNToggleIntent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import NetworkExtension
import NetworkProtection
import WidgetKit
import Core
import OSLog

// MARK: - Toggle

Expand All @@ -45,30 +46,52 @@ extension VPNToggleIntent: SetValueIntent & ForegroundContinuableIntent {

@MainActor
func perform() async throws -> some IntentResult {
do {
//DailyPixel.fireDailyAndCount(pixel: .networkProtectionWidgetConnectAttempt)
if value {
try await startVPN()
} else {
try await stopVPN()
}

let controller = VPNIntentTunnelController()
return .result()
}

if value {
try await controller.start()
} else {
try await controller.stop()
}
private func startVPN() async throws {
do {
DailyPixel.fireDailyAndCount(pixel: .vpnControlCenterConnectAttempt)

return .result()
let controller = VPNIntentTunnelController()
try await controller.start()
DailyPixel.fireDailyAndCount(pixel: .vpnControlCenterConnectSuccess)
} catch {
switch error {
case VPNIntentTunnelController.StartFailure.vpnNotConfigured:
//DailyPixel.fireDailyAndCount(pixel: .networkProtectionWidgetConnectCancelled)
DailyPixel.fireDailyAndCount(pixel: .vpnControlCenterConnectCancelled)

let dialog = IntentDialog(stringLiteral: UserText.vpnNeedsToBeEnabledFromApp)
throw needsToContinueInForegroundError() {
throw needsToContinueInForegroundError(dialog) {
await UIApplication.shared.open(AppDeepLinkSchemes.openVPN.url)
}
default:
//DailyPixel.fireDailyAndCount(pixel: .networkProtectionWidgetConnectFailure, error: error)
DailyPixel.fireDailyAndCount(pixel: .vpnControlCenterConnectFailure, error: error)
throw error
}
}
}

private func stopVPN() async throws {
do {
DailyPixel.fireDailyAndCount(pixel: .vpnControlCenterDisconnectAttempt)

let controller = VPNIntentTunnelController()
try await controller.stop()
DailyPixel.fireDailyAndCount(pixel: .vpnControlCenterDisconnectSuccess)
} catch {
switch error {
case VPNIntentTunnelController.StopFailure.vpnNotConfigured:
DailyPixel.fireDailyAndCount(pixel: .vpnControlCenterDisconnectCancelled)
throw error
default:
DailyPixel.fireDailyAndCount(pixel: .vpnControlCenterDisconnectFailure, error: error)
throw error
}
}
Expand Down

0 comments on commit b57e2a5

Please sign in to comment.