Skip to content

Commit

Permalink
Add Geoswitching pixels (#2235)
Browse files Browse the repository at this point in the history
  • Loading branch information
graeme authored Dec 6, 2023
1 parent c8e767d commit 315a147
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
10 changes: 10 additions & 0 deletions Core/PixelEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,11 @@ extension Pixel {
case networkProtectionWaitlistNotificationShown
case networkProtectionWaitlistNotificationLaunched

case networkProtectionGeoswitchingOpened
case networkProtectionGeoswitchingSetNearest
case networkProtectionGeoswitchingSetCustom
case networkProtectionGeoswitchingNoLocations

// MARK: remote messaging pixels

case remoteMessageShown
Expand Down Expand Up @@ -889,6 +894,11 @@ extension Pixel.Event {
case .networkProtectionWaitlistNotificationShown: return "m_netp_waitlist_notification_shown"
case .networkProtectionWaitlistNotificationLaunched: return "m_netp_waitlist_notification_launched"

case .networkProtectionGeoswitchingOpened: return "m_netp_imp_geoswitching"
case .networkProtectionGeoswitchingSetNearest: return "m_netp_ev_geoswitching_set_nearest"
case .networkProtectionGeoswitchingSetCustom: return "m_netp_ev_geoswitching_set_custom"
case .networkProtectionGeoswitchingNoLocations: return "m_netp_ev_geoswitching_no_locations"

// MARK: remote messaging pixels

case .remoteMessageShown: return "m_remote_message_shown"
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9157,7 +9157,7 @@
repositoryURL = "https://github.com/DuckDuckGo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 91.0.2;
version = 92.0.0;
};
};
C14882EB27F211A000D59F0C /* XCRemoteSwiftPackageReference "SwiftSoup" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"repositoryURL": "https://github.com/DuckDuckGo/BrowserServicesKit",
"state": {
"branch": null,
"revision": "c871e62fd8d07f9e3136948614003fbe7e582963",
"version": "91.0.2"
"revision": "11a5fb5e7bf1f4fb4e2a79ce8dbe2eb39b583495",
"version": "92.0.0"
}
},
{
Expand Down
3 changes: 2 additions & 1 deletion DuckDuckGo/NetworkProtectionConvenienceInitialisers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ extension NetworkProtectionLocationListCompositeRepository {
let settings = VPNSettings(defaults: .networkProtectionGroupDefaults)
self.init(
environment: settings.selectedEnvironment,
tokenStore: NetworkProtectionKeychainTokenStore()
tokenStore: NetworkProtectionKeychainTokenStore(),
errorEvents: .networkProtectionAppDebugEvents
)
}
}
Expand Down
7 changes: 7 additions & 0 deletions DuckDuckGo/NetworkProtectionVPNLocationViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import Foundation
import Combine
import NetworkProtection
import Core

final class NetworkProtectionVPNLocationViewModel: ObservableObject {
private let locationListRepository: NetworkProtectionLocationListRepository
Expand Down Expand Up @@ -51,15 +52,18 @@ final class NetworkProtectionVPNLocationViewModel: ObservableObject {
}

func onViewAppeared() async {
Pixel.fire(pixel: .networkProtectionGeoswitchingOpened)
await reloadList()
}

func onNearestItemSelection() async {
DailyPixel.fireDailyAndCount(pixel: .networkProtectionGeoswitchingSetNearest)
settings.selectedLocation = .nearest
await reloadList()
}

func onCountryItemSelection(id: String, cityId: String? = nil) async {
DailyPixel.fireDailyAndCount(pixel: .networkProtectionGeoswitchingSetCustom)
let location = NetworkProtectionSelectedLocation(country: id, city: cityId)
settings.selectedLocation = .location(location)
await reloadList()
Expand All @@ -68,6 +72,9 @@ final class NetworkProtectionVPNLocationViewModel: ObservableObject {
@MainActor
private func reloadList() async {
guard let list = try? await locationListRepository.fetchLocationList() else { return }
if list.isEmpty {
DailyPixel.fireDailyAndCount(pixel: .networkProtectionGeoswitchingNoLocations)
}
let selectedLocation = self.settings.selectedLocation
let isNearestSelected = selectedLocation == .nearest

Expand Down

0 comments on commit 315a147

Please sign in to comment.