Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore VPN pixels in main browser #2129

Merged
merged 6 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13158,8 +13158,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 102.0.2;
branch = "sam/suppress-noisy-vpn-pixels";
kind = branch;
};
};
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" : "072df96b846e3350b23ab32a61b6c1a0983b5e85",
"version" : "102.0.2"
"branch" : "sam/suppress-noisy-vpn-pixels",
"revision" : "486c3b2f9ea177ac6758c28f6c070b417b9e51de"
}
},
{
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 @@ -116,8 +117,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 @@ -359,6 +362,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
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct NetworkProtectionWaitlistViewControllerPresenter: WaitlistViewControllerP
let viewController = WaitlistModalViewController(viewModel: viewModel, contentView: NetworkProtectionWaitlistRootView())
windowController.mainViewController.beginSheet(viewController) { _ in
// If the user dismissed the waitlist flow without signing up, hide the button.
var waitlist = NetworkProtectionWaitlist()
let waitlist = NetworkProtectionWaitlist()
if !waitlist.waitlistStorage.isOnWaitlist {
waitlist.waitlistSignUpPromptDismissed = true
NotificationCenter.default.post(name: .networkProtectionWaitlistAccessChanged, object: nil)
Expand Down
Loading