Skip to content

Commit

Permalink
Subscription pixels refinements (#2472)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/1205842942115003/1205469290776415/f

**Description**:

New pixels for Subscription Pro
  • Loading branch information
federicocappelli authored Mar 22, 2024
1 parent dbf4f36 commit 9c8a825
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions DuckDuckGo/Application/URLEventHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ final class URLEventHandler {
#if SUBSCRIPTION
case AppLaunchCommand.showPrivacyPro.launchURL:
WindowControllersManager.shared.showTab(with: .subscription(.subscriptionPurchase))
Pixel.fire(.privacyProOfferScreenImpression)
#endif
#if !APPSTORE && !DEBUG
case AppLaunchCommand.moveAppToApplications.launchURL:
Expand Down
1 change: 0 additions & 1 deletion DuckDuckGo/NavigationBar/View/MoreOptionsMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ final class MoreOptionsMenu: NSMenu {

#if SUBSCRIPTION
@objc func openSubscriptionPurchasePage(_ sender: NSMenuItem) {
Pixel.fire(.privacyProOfferScreenImpression)
actionDelegate?.optionsButtonMenuRequestedSubscriptionPurchasePage(self)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,7 @@ extension NavigationBarViewController: OptionsButtonMenuDelegate {
#if SUBSCRIPTION
func optionsButtonMenuRequestedSubscriptionPurchasePage(_ menu: NSMenu) {
WindowControllersManager.shared.showTab(with: .subscription(.subscriptionPurchase))
Pixel.fire(.privacyProOfferScreenImpression)
}

func optionsButtonMenuRequestedIdentityTheftRestoration(_ menu: NSMenu) {
Expand Down
2 changes: 2 additions & 0 deletions DuckDuckGo/Statistics/PixelEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ extension Pixel {
case privacyProSubscriptionManagementEmail
case privacyProSubscriptionManagementPlanBilling
case privacyProSubscriptionManagementRemoval
case privacyProPurchaseStripeSuccess
// Web pixels
case privacyProOfferMonthlyPriceClick
case privacyProOfferYearlyPriceClick
Expand Down Expand Up @@ -694,6 +695,7 @@ extension Pixel.Event {
case .privacyProSubscriptionManagementEmail: return "m_mac_\(appDistribution)_privacy-pro_manage-email_edit_click"
case .privacyProSubscriptionManagementPlanBilling: return "m_mac_\(appDistribution)_privacy-pro_settings_change-plan-or-billing_click"
case .privacyProSubscriptionManagementRemoval: return "m_mac_\(appDistribution)_privacy-pro_settings_remove-from-device_click"
case .privacyProPurchaseStripeSuccess: return "m_mac_\(appDistribution)_privacy-pro_app_subscription-purchase_stripe_success"
// Web
case .privacyProOfferMonthlyPriceClick: return "m_mac_\(appDistribution)_privacy-pro_offer_monthly-price_click"
case .privacyProOfferYearlyPriceClick: return "m_mac_\(appDistribution)_privacy-pro_offer_yearly-price_click"
Expand Down
1 change: 1 addition & 0 deletions DuckDuckGo/Statistics/PixelParameters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ extension Pixel.Event {
.privacyProOfferYearlyPriceClick,
.privacyProAddEmailSuccess,
.privacyProWelcomeFAQClick,
.privacyProPurchaseStripeSuccess,
.passwordImportKeychainPrompt,
.passwordImportKeychainPromptDenied:
return nil
Expand Down
11 changes: 6 additions & 5 deletions DuckDuckGo/Tab/UserScripts/SubscriptionPagesUserScript.swift
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,6 @@ final class SubscriptionPagesUseSubscriptionFeature: Subfeature {
if isBackendError {
DailyPixel.fire(pixel: .privacyProPurchaseFailureBackendError, frequency: .dailyAndCount)
}

if subscriptionActivationError != .hasActiveSubscription && subscriptionActivationError != .cancelledByUser {
DailyPixel.fire(pixel: .privacyProPurchaseFailure, frequency: .dailyAndCount)
}
}

func activateSubscription(params: Any, original: WKScriptMessage) async throws -> Encodable? {
Expand Down Expand Up @@ -511,7 +507,9 @@ final class SubscriptionPagesUseSubscriptionFeature: Subfeature {
await StripePurchaseFlow.completeSubscriptionPurchase(subscriptionAppGroup: Bundle.main.appGroup(bundle: .subs))
await mainViewController?.dismiss(progressViewController)

return [String: String]() // cannot be nil
DailyPixel.fire(pixel: .privacyProPurchaseStripeSuccess, frequency: .dailyAndCount)

return [String: String]() // cannot be nil, the web app expect something back before redirecting the user to the final page
}

// MARK: Pixel related actions
Expand Down Expand Up @@ -577,6 +575,7 @@ extension MainWindowController {

@MainActor
func showSomethingWentWrongAlert() {
DailyPixel.fire(pixel: .privacyProPurchaseFailure, frequency: .dailyAndCount)
guard let window else { return }

window.show(.somethingWentWrongAlert())
Expand All @@ -588,6 +587,7 @@ extension MainWindowController {

window.show(.subscriptionNotFoundAlert(), firstButtonAction: {
WindowControllersManager.shared.showTab(with: .subscription(.subscriptionPurchase))
Pixel.fire(.privacyProOfferScreenImpression)
})
}

Expand All @@ -597,6 +597,7 @@ extension MainWindowController {

window.show(.subscriptionInactiveAlert(), firstButtonAction: {
WindowControllersManager.shared.showTab(with: .subscription(.subscriptionPurchase))
Pixel.fire(.privacyProOfferScreenImpression)
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ public final class PreferencesSubscriptionModel: ObservableObject {

@MainActor
func removeFromThisDeviceAction() {
userEventHandler(.removeSubscriptionClick)
accountManager.signOut()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ public struct PreferencesSubscriptionView: View {
}
})
Button(UserText.removeFromThisDeviceButton, action: {
model.userEventHandler(.removeSubscriptionClick)
showingRemoveConfirmationDialog.toggle()
})
} label: {
Expand Down Expand Up @@ -190,7 +189,6 @@ public struct PreferencesSubscriptionView: View {
.buttonStyle(DefaultActionButtonStyle(enabled: true)) */
Menu {
Button(UserText.removeFromThisDeviceButton, action: {
model.userEventHandler(.removeSubscriptionClick)
showingRemoveConfirmationDialog.toggle()
})
} label: {
Expand Down

0 comments on commit 9c8a825

Please sign in to comment.