Skip to content

Commit

Permalink
macOS: Add pixels to track VPN wake and stop attempts (#2694)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/414235014887631/1207099030609186/f

iOS PR:duckduckgo/iOS#2785
BSK PR: duckduckgo/BrowserServicesKit#797

## Description

Adds pixels to track VPN wake and stop attempts.
  • Loading branch information
diegoreymendez authored Apr 26, 2024
1 parent b2a1608 commit 7e629fa
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 44 deletions.
10 changes: 4 additions & 6 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,6 @@
4B2D06292A11C0C900DE1F49 /* Bundle+VPN.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B4D605E2A0B29FA00BCD287 /* Bundle+VPN.swift */; };
4B2D062A2A11C0C900DE1F49 /* NetworkProtectionOptionKeyExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B4D605F2A0B29FA00BCD287 /* NetworkProtectionOptionKeyExtension.swift */; };
4B2D062C2A11C0E100DE1F49 /* Networking in Frameworks */ = {isa = PBXBuildFile; productRef = 4B2D062B2A11C0E100DE1F49 /* Networking */; };
4B2D062D2A11C12300DE1F49 /* Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85799C1725DEBB3F0007EC87 /* Logging.swift */; };
4B2D06322A11C1D300DE1F49 /* NSApplicationExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA5C8F622591021700748EB7 /* NSApplicationExtension.swift */; };
4B2D06332A11C1E300DE1F49 /* OptionalExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = B637273C26CCF0C200C8CB02 /* OptionalExtension.swift */; };
4B2D065B2A11D1FF00DE1F49 /* Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B4BEC322A11B509001D9AC5 /* Logging.swift */; };
Expand Down Expand Up @@ -1494,7 +1493,6 @@
7B97CD5D2B7E0BCE004FEF43 /* BundleExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6106B9D26A565DA0013B453 /* BundleExtension.swift */; };
7B97CD5E2B7E0BEA004FEF43 /* OptionalExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = B637273C26CCF0C200C8CB02 /* OptionalExtension.swift */; };
7B97CD5F2B7E0BF7004FEF43 /* NSApplicationExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA5C8F622591021700748EB7 /* NSApplicationExtension.swift */; };
7B97CD602B7E0C2E004FEF43 /* Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85799C1725DEBB3F0007EC87 /* Logging.swift */; };
7BA076BB2B65D61400D7FB72 /* NetworkProtectionProxy in Frameworks */ = {isa = PBXBuildFile; productRef = 7BA076BA2B65D61400D7FB72 /* NetworkProtectionProxy */; };
7BA4727D26F01BC400EAA165 /* CoreDataTestUtilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B9292C42667104B00AD2C21 /* CoreDataTestUtilities.swift */; };
7BA59C9B2AE18B49009A97B1 /* SystemExtensionManager in Frameworks */ = {isa = PBXBuildFile; productRef = 7BA59C9A2AE18B49009A97B1 /* SystemExtensionManager */; };
Expand Down Expand Up @@ -3279,6 +3277,7 @@
7B2DDCF72A93A8BB0039D884 /* NetworkProtectionAppEvents.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkProtectionAppEvents.swift; sourceTree = "<group>"; };
7B2E52242A5FEC09000C6D39 /* NetworkProtectionAgentNotificationsPresenter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkProtectionAgentNotificationsPresenter.swift; sourceTree = "<group>"; };
7B3618C12ADE75C8000D6154 /* NetworkProtectionNavBarPopoverManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkProtectionNavBarPopoverManager.swift; sourceTree = "<group>"; };
7B427BA82BD81D8C0014AE6C /* BrowserServicesKit */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = BrowserServicesKit; path = ../../BrowserServicesKit; sourceTree = "<group>"; };
7B430EA02A71411A00BAC4A1 /* NetworkProtectionSimulateFailureMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkProtectionSimulateFailureMenu.swift; sourceTree = "<group>"; };
7B4CE8DA26F02108009134B1 /* UI Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "UI Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
7B4CE8E626F02134009134B1 /* TabBarTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabBarTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -4716,6 +4715,7 @@
378E279C2970217400FCADA2 /* LocalPackages */ = {
isa = PBXGroup;
children = (
7B427BA82BD81D8C0014AE6C /* BrowserServicesKit */,
378E279D2970217400FCADA2 /* BuildToolPlugins */,
3192A2702A4C4E330084EA89 /* DataBrokerProtection */,
9DB6E7222AA0DA7A00A17F3C /* LoginItems */,
Expand Down Expand Up @@ -10508,7 +10508,6 @@
4B25377A2A11C01700610219 /* UserText+NetworkProtectionExtensions.swift in Sources */,
B65DA5F42A77D3FA00CBEE8D /* BundleExtension.swift in Sources */,
EE66418D2B9B1981005BCD17 /* NetworkProtectionTokenStore+SubscriptionTokenKeychainStorage.swift in Sources */,
4B2D062D2A11C12300DE1F49 /* Logging.swift in Sources */,
7B2E52252A5FEC09000C6D39 /* NetworkProtectionAgentNotificationsPresenter.swift in Sources */,
B602E8232A1E260E006D261F /* Bundle+NetworkProtectionExtensions.swift in Sources */,
4B2D062A2A11C0C900DE1F49 /* NetworkProtectionOptionKeyExtension.swift in Sources */,
Expand Down Expand Up @@ -10670,7 +10669,6 @@
buildActionMask = 2147483647;
files = (
7B97CD5C2B7E0BBB004FEF43 /* UserDefaultsWrapper.swift in Sources */,
7B97CD602B7E0C2E004FEF43 /* Logging.swift in Sources */,
7B97CD5E2B7E0BEA004FEF43 /* OptionalExtension.swift in Sources */,
7B97CD5F2B7E0BF7004FEF43 /* NSApplicationExtension.swift in Sources */,
7BDA36F52B7E055800AD5388 /* MacTransparentProxyProvider.swift in Sources */,
Expand Down Expand Up @@ -12726,7 +12724,7 @@
repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = "138.0.0-1";
version = 140.0.3;
};
};
4311906792B7676CE9535D76 /* XCRemoteSwiftPackageReference "BrowserServicesKit" */ = {
Expand All @@ -12742,7 +12740,7 @@
repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 140.0.2;
version = 140.0.3;
};
};
9FF521422BAA8FF300B9819B /* XCRemoteSwiftPackageReference "lottie-spm" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@
"version" : "3.0.0"
}
},
{
"identity" : "browserserviceskit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/BrowserServicesKit",
"state" : {
"revision" : "4340e2840f6ca634e61caffd1ced913603ddf0eb",
"version" : "140.0.2"
}
},
{
"identity" : "content-scope-scripts",
"kind" : "remoteSourceControl",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,18 @@ enum NetworkProtectionPixelEvent: PixelKitEventV2 {
case networkProtectionTunnelStartSuccess
case networkProtectionTunnelStartFailure(_ error: Error)

case networkProtectionTunnelStopAttempt
case networkProtectionTunnelStopSuccess
case networkProtectionTunnelStopFailure(_ error: Error)

case networkProtectionTunnelUpdateAttempt
case networkProtectionTunnelUpdateSuccess
case networkProtectionTunnelUpdateFailure(_ error: Error)

case networkProtectionTunnelWakeAttempt
case networkProtectionTunnelWakeSuccess
case networkProtectionTunnelWakeFailure(_ error: Error)

case networkProtectionEnableAttemptConnecting
case networkProtectionEnableAttemptSuccess
case networkProtectionEnableAttemptFailure
Expand Down Expand Up @@ -119,6 +127,15 @@ enum NetworkProtectionPixelEvent: PixelKitEventV2 {
case .networkProtectionTunnelStartFailure:
return "netp_tunnel_start_failure"

case .networkProtectionTunnelStopAttempt:
return "netp_tunnel_stop_attempt"

case .networkProtectionTunnelStopSuccess:
return "netp_tunnel_stop_success"

case .networkProtectionTunnelStopFailure:
return "netp_tunnel_stop_failure"

case .networkProtectionTunnelUpdateAttempt:
return "netp_tunnel_update_attempt"

Expand All @@ -128,6 +145,15 @@ enum NetworkProtectionPixelEvent: PixelKitEventV2 {
case .networkProtectionTunnelUpdateFailure:
return "netp_tunnel_update_failure"

case .networkProtectionTunnelWakeAttempt:
return "netp_tunnel_wake_attempt"

case .networkProtectionTunnelWakeSuccess:
return "netp_tunnel_wake_success"

case .networkProtectionTunnelWakeFailure:
return "netp_tunnel_wake_failure"

case .networkProtectionEnableAttemptConnecting:
return "netp_ev_enable_attempt"

Expand Down Expand Up @@ -300,9 +326,15 @@ enum NetworkProtectionPixelEvent: PixelKitEventV2 {
.networkProtectionTunnelStartAttempt,
.networkProtectionTunnelStartSuccess,
.networkProtectionTunnelStartFailure,
.networkProtectionTunnelStopAttempt,
.networkProtectionTunnelStopSuccess,
.networkProtectionTunnelStopFailure,
.networkProtectionTunnelUpdateAttempt,
.networkProtectionTunnelUpdateSuccess,
.networkProtectionTunnelUpdateFailure,
.networkProtectionTunnelWakeAttempt,
.networkProtectionTunnelWakeSuccess,
.networkProtectionTunnelWakeFailure,
.networkProtectionEnableAttemptConnecting,
.networkProtectionEnableAttemptSuccess,
.networkProtectionEnableAttemptFailure,
Expand Down Expand Up @@ -343,7 +375,9 @@ enum NetworkProtectionPixelEvent: PixelKitEventV2 {
return error
case .networkProtectionControllerStartFailure(let error),
.networkProtectionTunnelStartFailure(let error),
.networkProtectionTunnelStopFailure(let error),
.networkProtectionTunnelUpdateFailure(let error),
.networkProtectionTunnelWakeFailure(let error),
.networkProtectionClientFailedToParseRedeemResponse(let error),
.networkProtectionWireguardErrorCannotSetNetworkSettings(let error),
.networkProtectionRekeyFailure(let error),
Expand All @@ -356,8 +390,12 @@ enum NetworkProtectionPixelEvent: PixelKitEventV2 {
.networkProtectionControllerStartSuccess,
.networkProtectionTunnelStartAttempt,
.networkProtectionTunnelStartSuccess,
.networkProtectionTunnelStopAttempt,
.networkProtectionTunnelStopSuccess,
.networkProtectionTunnelUpdateAttempt,
.networkProtectionTunnelUpdateSuccess,
.networkProtectionTunnelWakeAttempt,
.networkProtectionTunnelWakeSuccess,
.networkProtectionEnableAttemptConnecting,
.networkProtectionEnableAttemptSuccess,
.networkProtectionEnableAttemptFailure,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
//

import Combine
import Common
import Foundation
import Subscription
import NetworkProtection
import NetworkProtectionUI
import Common

final class NetworkProtectionSubscriptionEventHandler {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,24 @@ final class MacPacketTunnelProvider: PacketTunnelProvider {
frequency: .dailyAndCount,
includeAppVersionParameter: true)
}
case .tunnelStopAttempt(let step):
switch step {
case .begin:
PixelKit.fire(
NetworkProtectionPixelEvent.networkProtectionTunnelStopAttempt,
frequency: .standard,
includeAppVersionParameter: true)
case .failure(let error):
PixelKit.fire(
NetworkProtectionPixelEvent.networkProtectionTunnelStopFailure(error),
frequency: .dailyAndCount,
includeAppVersionParameter: true)
case .success:
PixelKit.fire(
NetworkProtectionPixelEvent.networkProtectionTunnelStopSuccess,
frequency: .dailyAndCount,
includeAppVersionParameter: true)
}
case .tunnelUpdateAttempt(let step):
switch step {
case .begin:
Expand All @@ -251,6 +269,24 @@ final class MacPacketTunnelProvider: PacketTunnelProvider {
frequency: .dailyAndCount,
includeAppVersionParameter: true)
}
case .tunnelWakeAttempt(let step):
switch step {
case .begin:
PixelKit.fire(
NetworkProtectionPixelEvent.networkProtectionTunnelWakeAttempt,
frequency: .dailyAndCount,
includeAppVersionParameter: true)
case .failure(let error):
PixelKit.fire(
NetworkProtectionPixelEvent.networkProtectionTunnelWakeFailure(error),
frequency: .dailyAndCount,
includeAppVersionParameter: true)
case .success:
PixelKit.fire(
NetworkProtectionPixelEvent.networkProtectionTunnelWakeSuccess,
frequency: .dailyAndCount,
includeAppVersionParameter: true)
}
}
}

Expand Down Expand Up @@ -421,30 +457,6 @@ final class MacPacketTunnelProvider: PacketTunnelProvider {
try? loadDefaultPixelHeaders(from: options)
}

// MARK: - Start/Stop Tunnel

override func stopTunnel(with reason: NEProviderStopReason, completionHandler: @escaping () -> Void) {
super.stopTunnel(with: reason) {
Task {
completionHandler()

// From what I'm seeing in my tests the next call to start the tunnel is MUCH
// less likely to fail if we force this extension to exit when the tunnel is killed.
//
// Ref: https://app.asana.com/0/72649045549333/1204668639086684/f
//
exit(EXIT_SUCCESS)
}
}
}

override func cancelTunnelWithError(_ error: Error?) {
Task {
super.cancelTunnelWithError(error)
exit(EXIT_SUCCESS)
}
}

// MARK: - Pixels

private func setupPixels(defaultHeaders: [String: String] = [:]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import PixelKit

final class MacTransparentProxyProvider: TransparentProxyProvider {

static var vpnProxyLogger = Logger(subsystem: OSLog.subsystem, category: "VPN Proxy")
static var vpnProxyLogger = Logger(subsystem: Bundle.main.bundleIdentifier ?? "DuckDuckGo", category: "VPN Proxy")

private var cancellables = Set<AnyCancellable>()

Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/DataBrokerProtection/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let package = Package(
targets: ["DataBrokerProtection"])
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "140.0.2"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "140.0.3"),
.package(path: "../SwiftUIExtensions"),
.package(path: "../XPCHelper"),
],
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/NetworkProtectionMac/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ let package = Package(
.library(name: "NetworkProtectionUI", targets: ["NetworkProtectionUI"]),
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "140.0.2"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "140.0.3"),
.package(url: "https://github.com/airbnb/lottie-spm", exact: "4.4.1"),
.package(path: "../XPCHelper"),
.package(path: "../SwiftUIExtensions"),
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/SubscriptionUI/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let package = Package(
targets: ["SubscriptionUI"]),
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "140.0.2"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "140.0.3"),
.package(path: "../SwiftUIExtensions")
],
targets: [
Expand Down

0 comments on commit 7e629fa

Please sign in to comment.