From ca90535f47dd65aadf81b6140038d6f38e279c23 Mon Sep 17 00:00:00 2001 From: Sam Symons Date: Thu, 23 May 2024 20:52:00 -0700 Subject: [PATCH] Clean up pixels. --- .../Common/Surveys/SurveyRemoteMessage.swift | 1 + .../Surveys/SurveyRemoteMessaging.swift | 19 +++++++++++++-- .../Model/HomePageContinueSetUpModel.swift | 2 +- DuckDuckGo/Statistics/GeneralPixel.swift | 24 ++++--------------- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/DuckDuckGo/Common/Surveys/SurveyRemoteMessage.swift b/DuckDuckGo/Common/Surveys/SurveyRemoteMessage.swift index ad95075070..d33a84a2f8 100644 --- a/DuckDuckGo/Common/Surveys/SurveyRemoteMessage.swift +++ b/DuckDuckGo/Common/Surveys/SurveyRemoteMessage.swift @@ -34,6 +34,7 @@ struct SurveyRemoteMessage: Codable, Equatable, Identifiable, Hashable { struct Attributes: Codable, Equatable, Hashable { let subscriptionStatus: String? + let subscriptionBillingPeriod: String? let minimumDaysSinceSubscriptionStarted: Int? let maximumDaysUntilSubscriptionExpirationOrRenewal: Int? let daysSinceVPNEnabled: Int? diff --git a/DuckDuckGo/Common/Surveys/SurveyRemoteMessaging.swift b/DuckDuckGo/Common/Surveys/SurveyRemoteMessaging.swift index d24d0927b2..a28eb46a0e 100644 --- a/DuckDuckGo/Common/Surveys/SurveyRemoteMessaging.swift +++ b/DuckDuckGo/Common/Surveys/SurveyRemoteMessaging.swift @@ -98,7 +98,7 @@ final class DefaultSurveyRemoteMessaging: SurveyRemoteMessaging { try self.messageStorage.store(messages: processedMessages) self.updateLastRefreshDate() } catch { - PixelKit.fire(DebugEvent(GeneralPixel.networkProtectionRemoteMessageStorageFailed, error: error)) + PixelKit.fire(DebugEvent(GeneralPixel.surveyRemoteMessageStorageFailed, error: error)) } case .failure(let error): // Ignore 403 errors, those happen when a file can't be found on S3 @@ -107,10 +107,11 @@ final class DefaultSurveyRemoteMessaging: SurveyRemoteMessaging { return } - PixelKit.fire(DebugEvent(GeneralPixel.networkProtectionRemoteMessageFetchingFailed, error: error)) + PixelKit.fire(DebugEvent(GeneralPixel.surveyRemoteMessageFetchingFailed, error: error)) } } + // swiftlint:disable cyclomatic_complexity /// Processes the messages received from S3 and returns those which the user is eligible for. This is done by checking each of the attributes against the user's local state. /// Because the result of the message fetch is cached, it means that they won't be immediately updated if the user suddenly qualifies, but the refresh interval for remote messages is only 1 hour so it /// won't take long for the message to appear to the user. @@ -125,6 +126,9 @@ final class DefaultSurveyRemoteMessaging: SurveyRemoteMessaging { return messages.filter { message in + // TODO: Make it so that we check all attributes, not just the first one + var didMatch = false + // Check subscription status: if let messageSubscriptionStatus = message.attributes.subscriptionStatus { if let subscriptionStatus = Subscription.Status(rawValue: messageSubscriptionStatus) { @@ -135,6 +139,16 @@ final class DefaultSurveyRemoteMessaging: SurveyRemoteMessaging { } } + // Check subscription billing period: + if let messageSubscriptionBillingPeriod = message.attributes.subscriptionBillingPeriod { + if let subscriptionBillingPeriod = Subscription.BillingPeriod(rawValue: messageSubscriptionBillingPeriod) { + return subscription.billingPeriod == subscriptionBillingPeriod + } else { + // If we received a subscription billing period but can't map it to a valid type, don't show the message. + return false + } + } + // Check subscription start date: if let messageDaysSinceSubscriptionStarted = message.attributes.minimumDaysSinceSubscriptionStarted { guard let daysSinceSubscriptionStartDate = Calendar.current.dateComponents( @@ -171,6 +185,7 @@ final class DefaultSurveyRemoteMessaging: SurveyRemoteMessaging { } } + // swiftlint:enable cyclomatic_complexity func presentableRemoteMessages() -> [SurveyRemoteMessage] { let dismissedMessageIDs = messageStorage.dismissedMessageIDs() diff --git a/DuckDuckGo/HomePage/Model/HomePageContinueSetUpModel.swift b/DuckDuckGo/HomePage/Model/HomePageContinueSetUpModel.swift index 4a3bb90938..cf4299bce7 100644 --- a/DuckDuckGo/HomePage/Model/HomePageContinueSetUpModel.swift +++ b/DuckDuckGo/HomePage/Model/HomePageContinueSetUpModel.swift @@ -221,7 +221,7 @@ extension HomePage.Models { for message in surveyRemoteMessaging.presentableRemoteMessages() { features.append(.surveyRemoteMessage(message)) - PixelKit.fire(GeneralPixel.dataBrokerProtectionRemoteMessageDisplayed(messageID: message.id), frequency: .daily) + PixelKit.fire(GeneralPixel.surveyRemoteMessageDisplayed(messageID: message.id), frequency: .daily) } appendFeatureCards(&features) diff --git a/DuckDuckGo/Statistics/GeneralPixel.swift b/DuckDuckGo/Statistics/GeneralPixel.swift index 92e27883fa..42fb1feab6 100644 --- a/DuckDuckGo/Statistics/GeneralPixel.swift +++ b/DuckDuckGo/Statistics/GeneralPixel.swift @@ -153,9 +153,6 @@ enum GeneralPixel: PixelKitEventV2 { case dataBrokerProtectionWaitlistCardUITapped case dataBrokerProtectionWaitlistTermsAndConditionsDisplayed case dataBrokerProtectionWaitlistTermsAndConditionsAccepted - case dataBrokerProtectionRemoteMessageDisplayed(messageID: String) - case dataBrokerProtectionRemoteMessageDismissed(messageID: String) - case dataBrokerProtectionRemoteMessageOpened(messageID: String) // Login Item events case dataBrokerEnableLoginItemDaily @@ -344,11 +341,8 @@ enum GeneralPixel: PixelKitEventV2 { case burnerTabMisplaced - case networkProtectionRemoteMessageFetchingFailed - case networkProtectionRemoteMessageStorageFailed - case dataBrokerProtectionRemoteMessageFetchingFailed - case dataBrokerProtectionRemoteMessageStorageFailed - + case surveyRemoteMessageFetchingFailed + case surveyRemoteMessageStorageFailed case loginItemUpdateError(loginItemBundleID: String, action: String, buildType: String, osVersion: String) // Tracks installation without tracking retention. @@ -576,12 +570,6 @@ enum GeneralPixel: PixelKitEventV2 { return "m_mac_dbp_imp_terms" case .dataBrokerProtectionWaitlistTermsAndConditionsAccepted: return "m_mac_dbp_ev_terms_accepted" - case .dataBrokerProtectionRemoteMessageDisplayed(let messageID): - return "m_mac_dbp_remote_message_displayed_\(messageID)" - case .dataBrokerProtectionRemoteMessageDismissed(let messageID): - return "m_mac_dbp_remote_message_dismissed_\(messageID)" - case .dataBrokerProtectionRemoteMessageOpened(let messageID): - return "m_mac_dbp_remote_message_opened_\(messageID)" case .dataBrokerEnableLoginItemDaily: return "m_mac_dbp_daily_login-item_enable" case .dataBrokerDisableLoginItemDaily: return "m_mac_dbp_daily_login-item_disable" @@ -864,12 +852,8 @@ enum GeneralPixel: PixelKitEventV2 { case .burnerTabMisplaced: return "burner_tab_misplaced" - case .networkProtectionRemoteMessageFetchingFailed: return "netp_remote_message_fetching_failed" - case .networkProtectionRemoteMessageStorageFailed: return "netp_remote_message_storage_failed" - - case .dataBrokerProtectionRemoteMessageFetchingFailed: return "dbp_remote_message_fetching_failed" - case .dataBrokerProtectionRemoteMessageStorageFailed: return "dbp_remote_message_storage_failed" - + case .surveyRemoteMessageFetchingFailed: return "survey_remote_message_fetching_failed" + case .surveyRemoteMessageStorageFailed: return "survey_remote_message_storage_failed" case .loginItemUpdateError: return "login-item_update-error" // Installation Attribution