Skip to content

Commit

Permalink
Restore VPN pixels in main browser (#2129)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/0/1206461359050575/f
Tech Design URL:
CC:

Description:

This PR fixes an issue where some pixels weren't sending properly from the main browser.
  • Loading branch information
samsymons authored Jan 30, 2024
1 parent 5d44c9d commit cc11057
Show file tree
Hide file tree
Showing 15 changed files with 57 additions and 12 deletions.
2 changes: 1 addition & 1 deletion DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13121,7 +13121,7 @@
repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 103.0.2;
version = 104.0.0;
};
};
AA06B6B52672AF8100F541C5 /* XCRemoteSwiftPackageReference "Sparkle" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/BrowserServicesKit",
"state" : {
"revision" : "1f7a1b5fe1c404d331fe34e55c99296828107c1d",
"version" : "103.0.2"
"revision" : "872090e651ad8e26ca9903a95f3d094b21d48e23",
"version" : "104.0.0"
}
},
{
Expand Down
30 changes: 30 additions & 0 deletions DuckDuckGo/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import DDGSync
import ServiceManagement
import SyncDataProviders
import UserNotifications
import PixelKit

#if NETWORK_PROTECTION
import NetworkProtection
Expand Down Expand Up @@ -117,8 +118,10 @@ final class AppDelegate: NSObject, NSApplicationDelegate, FileDownloadManagerDel
if NSApplication.runType.requiresEnvironment {
#if DEBUG
Pixel.setUp(dryRun: true)
Self.setUpPixelKit(dryRun: true)
#else
Pixel.setUp()
Self.setUpPixelKit(dryRun: false)
#endif

Database.shared.loadStore { _, error in
Expand Down Expand Up @@ -360,6 +363,33 @@ final class AppDelegate: NSObject, NSApplicationDelegate, FileDownloadManagerDel
appearancePreferences.updateUserInterfaceStyle()
}

private static func setUpPixelKit(dryRun: Bool) {
#if NETWORK_PROTECTION
#if APPSTORE
let source = "browser-appstore"
#else
let source = "browser-dmg"
#endif

PixelKit.setUp(dryRun: dryRun,
appVersion: AppVersion.shared.versionNumber,
source: source,
defaultHeaders: [:],
log: .networkProtectionPixel,
defaults: .netP) { (pixelName: String, headers: [String: String], parameters: [String: String], _, _, onComplete: @escaping PixelKit.CompletionBlock) in

let url = URL.pixelUrl(forPixelNamed: pixelName)
let apiHeaders = APIRequest.Headers(additionalHeaders: headers)
let configuration = APIRequest.Configuration(url: url, method: .get, queryParameters: parameters, headers: apiHeaders)
let request = APIRequest(configuration: configuration)

request.fetch { _, error in
onComplete(error == nil, error)
}
}
#endif
}

// MARK: - Sync

private func startupSync() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ enum NetworkProtectionPixelEvent: PixelKitEvent {
case networkProtectionKeychainErrorFailedToCastKeychainValueToData(field: String)
case networkProtectionKeychainReadError(field: String, status: Int32)
case networkProtectionKeychainWriteError(field: String, status: Int32)
case networkProtectionKeychainUpdateError(field: String, status: Int32)
case networkProtectionKeychainDeleteError(status: Int32)

case networkProtectionWireguardErrorCannotLocateTunnelFileDescriptor
Expand Down Expand Up @@ -190,6 +191,9 @@ enum NetworkProtectionPixelEvent: PixelKitEvent {
case .networkProtectionKeychainWriteError:
return "m_mac_netp_keychain_error_write_failed"

case .networkProtectionKeychainUpdateError:
return "m_mac_netp_keychain_error_update_failed"

case .networkProtectionKeychainDeleteError:
return "m_mac_netp_keychain_error_delete_failed"

Expand Down Expand Up @@ -239,6 +243,12 @@ enum NetworkProtectionPixelEvent: PixelKitEvent {
PixelKit.Parameters.errorCode: String(status)
]

case .networkProtectionKeychainUpdateError(let field, let status):
return [
PixelKit.Parameters.keychainFieldName: field,
PixelKit.Parameters.errorCode: String(status)
]

case .networkProtectionKeychainDeleteError(let status):
return [
PixelKit.Parameters.errorCode: String(status)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ extension EventMapping where Event == NetworkProtectionError {
case .keychainWriteError(field: let field, status: let status):
domainEvent = .networkProtectionKeychainWriteError(field: field, status: status)
frequency = .standard
case .keychainUpdateError(field: let field, status: let status):
domainEvent = .networkProtectionKeychainUpdateError(field: field, status: status)
frequency = .standard
case .keychainDeleteError(status: let status):
domainEvent = .networkProtectionKeychainDeleteError(status: status)
frequency = .standard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ final class MacPacketTunnelProvider: PacketTunnelProvider {
domainEvent = .networkProtectionKeychainReadError(field: field, status: status)
case .keychainWriteError(let field, let status):
domainEvent = .networkProtectionKeychainWriteError(field: field, status: status)
case .keychainUpdateError(let field, let status):
domainEvent = .networkProtectionKeychainUpdateError(field: field, status: status)
case .keychainDeleteError(let status):
domainEvent = .networkProtectionKeychainDeleteError(status: status)
case .wireGuardCannotLocateTunnelFileDescriptor:
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: "103.0.2"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "104.0.0"),
.package(path: "../PixelKit"),
.package(path: "../SwiftUIExtensions"),
.package(path: "../XPCHelper")
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/LoginItems/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let package = Package(
),
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "103.0.2"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "104.0.0"),
],
targets: [
.target(
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/NetworkProtectionMac/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ let package = Package(
.library(name: "NetworkProtectionUI", targets: ["NetworkProtectionUI"])
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "103.0.2"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "104.0.0"),
.package(path: "../XPCHelper"),
.package(path: "../SwiftUIExtensions")
],
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/PixelKit/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let package = Package(
)
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "103.0.2"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "104.0.0"),
],
targets: [
.target(
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/Subscription/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let package = Package(
targets: ["Subscription"]),
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "103.0.2"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "104.0.0"),
],
targets: [
.target(
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/SwiftUIExtensions/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let package = Package(
.library(name: "PreferencesViews", targets: ["PreferencesViews"]),
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "103.0.2"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "104.0.0"),
],
targets: [
.target(
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/SyncUI/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let package = Package(
],
dependencies: [
.package(path: "../SwiftUIExtensions"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "103.0.2"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "104.0.0"),
],
targets: [
.target(
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/SystemExtensionManager/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let package = Package(
),
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "103.0.2"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "104.0.0"),
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/XPCHelper/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ let package = Package(
.library(name: "XPCHelper", targets: ["XPCHelper"]),
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "103.0.2"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "104.0.0"),
],
targets: [
.target(
Expand Down

0 comments on commit cc11057

Please sign in to comment.