diff --git a/DuckDuckGo.xcodeproj/project.pbxproj b/DuckDuckGo.xcodeproj/project.pbxproj index 40c1e7526c..d202f5c0cd 100644 --- a/DuckDuckGo.xcodeproj/project.pbxproj +++ b/DuckDuckGo.xcodeproj/project.pbxproj @@ -9770,7 +9770,7 @@ repositoryURL = "https://github.com/DuckDuckGo/BrowserServicesKit"; requirement = { kind = exactVersion; - version = 152.0.1; + version = 153.0.0; }; }; 9F8FE9472BAE50E50071E372 /* XCRemoteSwiftPackageReference "lottie-spm" */ = { diff --git a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index b98b5cde48..d43793703e 100644 --- a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -32,8 +32,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/DuckDuckGo/BrowserServicesKit", "state" : { - "revision" : "43d6c090699ddc1b92c0c016dc31b923fb06f59f", - "version" : "152.0.1" + "revision" : "b78ae617c7fe66244741f489158a1f40e567e674", + "version" : "153.0.0" } }, { diff --git a/DuckDuckGo/HomeMessage.xcassets/RemoteMessage/RemoteMessagePrivacyPro.imageset/Contents.json b/DuckDuckGo/HomeMessage.xcassets/RemoteMessage/RemoteMessagePrivacyShield.imageset/Contents.json similarity index 100% rename from DuckDuckGo/HomeMessage.xcassets/RemoteMessage/RemoteMessagePrivacyPro.imageset/Contents.json rename to DuckDuckGo/HomeMessage.xcassets/RemoteMessage/RemoteMessagePrivacyShield.imageset/Contents.json diff --git a/DuckDuckGo/HomeMessage.xcassets/RemoteMessage/RemoteMessagePrivacyPro.imageset/RemoteMessagePrivacyPro.pdf b/DuckDuckGo/HomeMessage.xcassets/RemoteMessage/RemoteMessagePrivacyShield.imageset/RemoteMessagePrivacyPro.pdf similarity index 100% rename from DuckDuckGo/HomeMessage.xcassets/RemoteMessage/RemoteMessagePrivacyPro.imageset/RemoteMessagePrivacyPro.pdf rename to DuckDuckGo/HomeMessage.xcassets/RemoteMessage/RemoteMessagePrivacyShield.imageset/RemoteMessagePrivacyPro.pdf diff --git a/DuckDuckGo/RemoteMessaging.swift b/DuckDuckGo/RemoteMessaging.swift index 494010a7ad..7dcd862ab4 100644 --- a/DuckDuckGo/RemoteMessaging.swift +++ b/DuckDuckGo/RemoteMessaging.swift @@ -141,6 +141,7 @@ struct RemoteMessaging { isWidgetInstalled: isWidgetInstalled) } + // swiftlint:disable:next function_body_length static private func fetchAndProcess(bookmarksCount: Int, favoritesCount: Int, remoteMessagingStore: RemoteMessagingStore = AppDependencyProvider.shared.remoteMessagingStore, @@ -159,10 +160,10 @@ struct RemoteMessaging { let activationDateStore = DefaultVPNActivationDateStore() let daysSinceNetworkProtectionEnabled = activationDateStore.daysSinceActivation() ?? -1 - let surveyActionMapper = DefaultRemoteMessagingSurveyURLBuilder(statisticsStore: statisticsStore) var privacyProDaysSinceSubscribed: Int = -1 var privacyProDaysUntilExpiry: Int = -1 + let surveyActionMapper: DefaultRemoteMessagingSurveyURLBuilder if let accessToken = AppDependencyProvider.shared.subscriptionManager.accountManager.accessToken { let subscriptionResult = await AppDependencyProvider.shared.subscriptionManager.subscriptionService.getSubscription( @@ -172,7 +173,12 @@ struct RemoteMessaging { if case let .success(subscription) = subscriptionResult { privacyProDaysSinceSubscribed = Calendar.current.numberOfDaysBetween(subscription.startedAt, and: Date()) ?? -1 privacyProDaysUntilExpiry = Calendar.current.numberOfDaysBetween(Date(), and: subscription.expiresOrRenewsAt) ?? -1 + surveyActionMapper = DefaultRemoteMessagingSurveyURLBuilder(statisticsStore: statisticsStore, subscription: subscription) + } else { + surveyActionMapper = DefaultRemoteMessagingSurveyURLBuilder(statisticsStore: statisticsStore, subscription: nil) } + } else { + surveyActionMapper = DefaultRemoteMessagingSurveyURLBuilder(statisticsStore: statisticsStore, subscription: nil) } let remoteMessagingConfigMatcher = RemoteMessagingConfigMatcher( diff --git a/DuckDuckGo/RemoteMessagingSurveyURLBuilder.swift b/DuckDuckGo/RemoteMessagingSurveyURLBuilder.swift index c6034c5e8f..1ea51ddc39 100644 --- a/DuckDuckGo/RemoteMessagingSurveyURLBuilder.swift +++ b/DuckDuckGo/RemoteMessagingSurveyURLBuilder.swift @@ -22,19 +22,23 @@ import BrowserServicesKit import RemoteMessaging import Core import Common +import Subscription struct DefaultRemoteMessagingSurveyURLBuilder: RemoteMessagingSurveyActionMapping { private let statisticsStore: StatisticsStore - private let activationDateStore: VPNActivationDateStore + private let vpnActivationDateStore: VPNActivationDateStore + private let subscription: Subscription? init(statisticsStore: StatisticsStore = StatisticsUserDefaults(), - activationDateStore: VPNActivationDateStore = DefaultVPNActivationDateStore()) { + vpnActivationDateStore: VPNActivationDateStore = DefaultVPNActivationDateStore(), + subscription: Subscription?) { self.statisticsStore = statisticsStore - self.activationDateStore = activationDateStore + self.vpnActivationDateStore = vpnActivationDateStore + self.subscription = subscription } - // swiftlint:disable:next cyclomatic_complexity + // swiftlint:disable:next cyclomatic_complexity function_body_length func add(parameters: [RemoteMessagingSurveyActionParameter], to surveyURL: URL) -> URL { guard var components = URLComponents(string: surveyURL.absoluteString) else { assertionFailure("Could not build URL components from survey URL") @@ -60,15 +64,56 @@ struct DefaultRemoteMessagingSurveyURLBuilder: RemoteMessagingSurveyActionMappin case .hardwareModel: let model = hardwareModel().addingPercentEncoding(withAllowedCharacters: .alphanumerics) queryItems.append(URLQueryItem(name: parameter.rawValue, value: model)) - case .lastActiveDate: - if let daysSinceLastActive = activationDateStore.daysSinceLastActive() { - queryItems.append(URLQueryItem(name: parameter.rawValue, value: String(describing: daysSinceLastActive))) - } case .daysInstalled: if let installDate = statisticsStore.installDate, - let daysSinceInstall = Calendar.current.numberOfDaysBetween(installDate, and: Date()) { + let daysSinceInstall = Calendar.current.numberOfDaysBetween(installDate, and: Date()) { queryItems.append(URLQueryItem(name: parameter.rawValue, value: String(describing: daysSinceInstall))) } + case .privacyProStatus: + switch subscription?.status { + case .autoRenewable: queryItems.append(URLQueryItem(name: parameter.rawValue, value: "auto_renewable")) + case .notAutoRenewable: queryItems.append(URLQueryItem(name: parameter.rawValue, value: "not_auto_renewable")) + case .gracePeriod: queryItems.append(URLQueryItem(name: parameter.rawValue, value: "grace_period")) + case .inactive: queryItems.append(URLQueryItem(name: parameter.rawValue, value: "inactive")) + case .expired: queryItems.append(URLQueryItem(name: parameter.rawValue, value: "expired")) + case .unknown: queryItems.append(URLQueryItem(name: parameter.rawValue, value: "unknown")) + case nil: break + } + case .privacyProPlatform: + + switch subscription?.platform { + case .apple: queryItems.append(URLQueryItem(name: parameter.rawValue, value: "apple")) + case .google: queryItems.append(URLQueryItem(name: parameter.rawValue, value: "google")) + case .stripe: queryItems.append(URLQueryItem(name: parameter.rawValue, value: "stripe")) + case .unknown: queryItems.append(URLQueryItem(name: parameter.rawValue, value: "unknown")) + case nil: break + } + case .privacyProBilling: + switch subscription?.billingPeriod { + case .monthly: queryItems.append(URLQueryItem(name: parameter.rawValue, value: "monthly")) + case .yearly: queryItems.append(URLQueryItem(name: parameter.rawValue, value: "yearly")) + case .unknown: queryItems.append(URLQueryItem(name: parameter.rawValue, value: "unknown")) + case nil: break + } + + case .privacyProDaysSincePurchase: + if let startDate = subscription?.startedAt, + let daysSincePurchase = Calendar.current.numberOfDaysBetween(startDate, and: Date()) { + queryItems.append(URLQueryItem(name: parameter.rawValue, value: String(describing: daysSincePurchase))) + } + case .privacyProDaysUntilExpiry: + if let expiryDate = subscription?.expiresOrRenewsAt, + let daysUntilExpiry = Calendar.current.numberOfDaysBetween(Date(), and: expiryDate) { + queryItems.append(URLQueryItem(name: parameter.rawValue, value: String(describing: daysUntilExpiry))) + } + case .vpnFirstUsed: + if let vpnFirstUsed = vpnActivationDateStore.daysSinceActivation() { + queryItems.append(URLQueryItem(name: parameter.rawValue, value: String(describing: vpnFirstUsed))) + } + case .vpnLastUsed: + if let vpnLastUsed = vpnActivationDateStore.daysSinceLastActive() { + queryItems.append(URLQueryItem(name: parameter.rawValue, value: String(describing: vpnLastUsed))) + } } }