Skip to content

Commit

Permalink
Clean up pixels.
Browse files Browse the repository at this point in the history
  • Loading branch information
samsymons committed May 24, 2024
1 parent 30a0819 commit ca90535
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
1 change: 1 addition & 0 deletions DuckDuckGo/Common/Surveys/SurveyRemoteMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
19 changes: 17 additions & 2 deletions DuckDuckGo/Common/Surveys/SurveyRemoteMessaging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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) {
Expand All @@ -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(
Expand Down Expand Up @@ -171,6 +185,7 @@ final class DefaultSurveyRemoteMessaging: SurveyRemoteMessaging {

}
}
// swiftlint:enable cyclomatic_complexity

func presentableRemoteMessages() -> [SurveyRemoteMessage] {
let dismissedMessageIDs = messageStorage.dismissedMessageIDs()
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/HomePage/Model/HomePageContinueSetUpModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 4 additions & 20 deletions DuckDuckGo/Statistics/GeneralPixel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ca90535

Please sign in to comment.