Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web pixels (handlers + pixels) #2611

Merged
merged 3 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ disabled_rules:
- todo
- unused_capture_list
- trailing_comma
- cyclomatic_complexity
miasma13 marked this conversation as resolved.
Show resolved Hide resolved

opt_in_rules:
- closure_end_indentation
Expand Down
10 changes: 10 additions & 0 deletions Core/PixelEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,11 @@ extension Pixel {
case privacyProSubscriptionManagementEmail
case privacyProSubscriptionManagementPlanBilling
case privacyProSubscriptionManagementRemoval
// Web pixels
case privacyProOfferMonthlyPriceClick // m.privacy-pro.offer.monthly-price.click.c.ios
case privacyProOfferYearlyPriceClick // m.privacy-pro.offer.yearly-price.click.c.ios
case privacyProAddEmailSuccess // m.privacy-pro.app.add-email.success.u.ios
case privacyProWelcomeFAQClieck // m.privacy-pro.welcome.faq.click.u.ios
}

}
Expand Down Expand Up @@ -1174,6 +1179,11 @@ extension Pixel.Event {
case .privacyProSubscriptionManagementEmail: return "m_privacy-pro_manage-email_edit_click"
case .privacyProSubscriptionManagementPlanBilling: return "m_privacy-pro_settings_change-plan-or-billing_click"
case .privacyProSubscriptionManagementRemoval: return "m_privacy-pro_settings_remove-from-device_click"
// Web
case .privacyProOfferMonthlyPriceClick: return "m_privacy-pro_offer_monthly-price_click"
case .privacyProOfferYearlyPriceClick: return "m_privacy-pro_offer_yearly-price_click"
case .privacyProAddEmailSuccess: return "m_privacy-pro_app_add-email_success_u"
case .privacyProWelcomeFAQClieck: return "m_privacy-pro_welcome_faq_click_u"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
// limitations under the License.
//

// swiftlint:disable file_length

#if SUBSCRIPTION
import BrowserServicesKit
import Common
Expand Down Expand Up @@ -55,6 +57,12 @@ final class SubscriptionPagesUseSubscriptionFeature: Subfeature, ObservableObjec
static let subscriptionSelected = "subscriptionSelected"
static let activateSubscription = "activateSubscription"
static let featureSelected = "featureSelected"
// Pixels related events
static let subscriptionsMonthlyPriceClicked = "subscriptionsMonthlyPriceClicked"
static let subscriptionsYearlyPriceClicked = "subscriptionsYearlyPriceClicked"
static let subscriptionsUnknownPriceClicked = "subscriptionsUnknownPriceClicked"
static let subscriptionsAddEmailSuccess = "subscriptionsAddEmailSuccess"
static let subscriptionsWelcomeFaqClicked = "subscriptionsWelcomeFaqClicked"
}

struct ProductIDs {
Expand Down Expand Up @@ -123,7 +131,14 @@ final class SubscriptionPagesUseSubscriptionFeature: Subfeature, ObservableObjec
case Handlers.activateSubscription: return activateSubscription
case Handlers.featureSelected: return featureSelected
case Handlers.backToSettings: return backToSettings
// Pixel related events
case Handlers.subscriptionsMonthlyPriceClicked: return subscriptionsMonthlyPriceClicked
case Handlers.subscriptionsYearlyPriceClicked: return subscriptionsYearlyPriceClicked
case Handlers.subscriptionsUnknownPriceClicked: return subscriptionsUnknownPriceClicked
case Handlers.subscriptionsAddEmailSuccess: return subscriptionsAddEmailSuccess
case Handlers.subscriptionsWelcomeFaqClicked: return subscriptionsWelcomeFaqClicked
default:
os_log("Unhandled web message: %s", log: .subscription, type: .error, methodName)
return nil
}
}
Expand Down Expand Up @@ -298,28 +313,55 @@ final class SubscriptionPagesUseSubscriptionFeature: Subfeature, ObservableObjec

return nil
}

func backToSettings(params: Any, original: WKScriptMessage) async -> Encodable? {
let accountManager = AccountManager()
if let accessToken = accountManager.accessToken,
case let .success(accountDetails) = await accountManager.fetchAccountDetails(with: accessToken) {
switch await SubscriptionService.getSubscription(accessToken: accessToken) {

case .success:
accountManager.storeAccount(token: accessToken,
email: accountDetails.email,
externalID: accountDetails.externalID)
onBackToSettings?()
default:
break
}

} else {
os_log("General error. Could not get account Details", log: .subscription, type: .error)
setTransactionError(.generalError)
}
return nil
}
let accountManager = AccountManager()
if let accessToken = accountManager.accessToken,
case let .success(accountDetails) = await accountManager.fetchAccountDetails(with: accessToken) {
switch await SubscriptionService.getSubscription(accessToken: accessToken) {

case .success:
accountManager.storeAccount(token: accessToken,
email: accountDetails.email,
externalID: accountDetails.externalID)
onBackToSettings?()
default:
break
}

} else {
os_log("General error. Could not get account Details", log: .subscription, type: .error)
setTransactionError(.generalError)
}
return nil
}

// MARK: Pixel related actions

func subscriptionsMonthlyPriceClicked(params: Any, original: WKScriptMessage) async -> Encodable? {
Pixel.fire(pixel: .privacyProOfferMonthlyPriceClick)
return nil
}

func subscriptionsYearlyPriceClicked(params: Any, original: WKScriptMessage) async -> Encodable? {
Pixel.fire(pixel: .privacyProOfferYearlyPriceClick)
return nil
}

func subscriptionsUnknownPriceClicked(params: Any, original: WKScriptMessage) async -> Encodable? {
// Not used
return nil
}

func subscriptionsAddEmailSuccess(params: Any, original: WKScriptMessage) async -> Encodable? {
UniquePixel.fire(pixel: .privacyProAddEmailSuccess)
return nil
}

func subscriptionsWelcomeFaqClicked(params: Any, original: WKScriptMessage) async -> Encodable? {
UniquePixel.fire(pixel: .privacyProWelcomeFAQClieck)
return nil
}

// MARK: Push actions (Push Data back to WebViews)
enum SubscribeActionName: String {
Expand Down Expand Up @@ -373,3 +415,5 @@ final class SubscriptionPagesUseSubscriptionFeature: Subfeature, ObservableObjec
}

#endif

// swiftlint:enable file_length
Loading