From e2c527815bdb42472b024b97e17ea54da87cac16 Mon Sep 17 00:00:00 2001 From: Oleg Tverdokhleb Date: Fri, 16 Oct 2020 14:27:20 +0300 Subject: [PATCH] [MOC-762] Add MoneyAuth SDK metrics --- .../Presenter/YandexAuthPresenter.swift | 27 +++++++++++++++++ .../Services/Analytics/AnalyticsEvent.swift | 19 ++++++++++++ .../Services/Analytics/AnalyticsService.swift | 30 ++++++++++++++++++- 3 files changed, 75 insertions(+), 1 deletion(-) diff --git a/YandexCheckoutPayments/Private/Modules/YandexAuth/Presenter/YandexAuthPresenter.swift b/YandexCheckoutPayments/Private/Modules/YandexAuth/Presenter/YandexAuthPresenter.swift index 21ea9cc9..aaabf41c 100644 --- a/YandexCheckoutPayments/Private/Modules/YandexAuth/Presenter/YandexAuthPresenter.swift +++ b/YandexCheckoutPayments/Private/Modules/YandexAuth/Presenter/YandexAuthPresenter.swift @@ -68,8 +68,12 @@ extension YandexAuthPresenter: PaymentMethodsViewOutput { kassaPaymentsCustomization: self.kassaPaymentsCustomization, output: self ) + let event = AnalyticsEvent.userStartAuthorization + self.interactor.trackEvent(event) } catch { self.moduleOutput?.didCancelAuthorizeInYandex(on: self) + let event = AnalyticsEvent.userCancelAuthorization + self.interactor.trackEvent(event) } } } @@ -170,6 +174,19 @@ extension YandexAuthPresenter: AuthorizationCoordinatorDelegate { moneyCenterAuthToken: token, walletDisplayName: account.displayName.title ) + + let event: AnalyticsEvent + switch authorizationProcess { + case .login: + event = .userSuccessAuthorization(.login) + case .enrollment: + event = .userSuccessAuthorization(.enrollment) + case .migration: + event = .userSuccessAuthorization(.migration) + case .none: + event = .userSuccessAuthorization(.unknown) + } + self.interactor.trackEvent(event) } } } @@ -178,6 +195,10 @@ extension YandexAuthPresenter: AuthorizationCoordinatorDelegate { _ coordinator: AuthorizationCoordinator ) { self.moneyAuthCoordinator = nil + + let event = AnalyticsEvent.userCancelAuthorization + interactor.trackEvent(event) + DispatchQueue.main.async { [weak self] in guard let self = self else { return } self.router.closeAuthorizationModule() @@ -190,6 +211,12 @@ extension YandexAuthPresenter: AuthorizationCoordinatorDelegate { didFailureWith error: Error ) { self.moneyAuthCoordinator = nil + + let event = AnalyticsEvent.userFailedAuthorization( + error.localizedDescription + ) + interactor.trackEvent(event) + DispatchQueue.main.async { [weak self] in guard let self = self else { return } self.router.closeAuthorizationModule() diff --git a/YandexCheckoutPayments/Private/Services/Analytics/AnalyticsEvent.swift b/YandexCheckoutPayments/Private/Services/Analytics/AnalyticsEvent.swift index 87c6ae8b..0863553c 100644 --- a/YandexCheckoutPayments/Private/Services/Analytics/AnalyticsEvent.swift +++ b/YandexCheckoutPayments/Private/Services/Analytics/AnalyticsEvent.swift @@ -118,5 +118,24 @@ enum AnalyticsEvent { case authTokenType case authYaLoginStatus case authPaymentStatus + case moneyAuthProcessType } + + // MARK: - Authorization + + enum MoneyAuthProcessType: String { + case enrollment + case login + case migration + case unknown + + var key: String { + return Key.moneyAuthProcessType.rawValue + } + } + + case userStartAuthorization + case userCancelAuthorization + case userSuccessAuthorization(MoneyAuthProcessType) + case userFailedAuthorization(String) } diff --git a/YandexCheckoutPayments/Private/Services/Analytics/AnalyticsService.swift b/YandexCheckoutPayments/Private/Services/Analytics/AnalyticsService.swift index 18b1d431..1f865f70 100644 --- a/YandexCheckoutPayments/Private/Services/Analytics/AnalyticsService.swift +++ b/YandexCheckoutPayments/Private/Services/Analytics/AnalyticsService.swift @@ -69,7 +69,15 @@ final class AnalyticsService: AnalyticsProcessing { eventName = EventKey.actionChangePaymentMethod.rawValue case .actionAuthWithoutWallet: eventName = EventKey.actionAuthWithoutWallet.rawValue -} + case .userStartAuthorization: + eventName = EventKey.userStartAuthorization.rawValue + case .userCancelAuthorization: + eventName = EventKey.userCancelAuthorization.rawValue + case .userSuccessAuthorization: + eventName = EventKey.userSuccessAuthorization.rawValue + case .userFailedAuthorization: + eventName = EventKey.userFailedAuthorization.rawValue + } return eventName } // swiftlint:enable cyclomatic_complexity @@ -139,6 +147,19 @@ final class AnalyticsService: AnalyticsProcessing { case .actionAuthWithoutWallet: parameters = nil + + case .userStartAuthorization: + parameters = nil + case .userCancelAuthorization: + parameters = nil + case .userSuccessAuthorization(let moneyAuthProcessType): + parameters = [ + moneyAuthProcessType.key: moneyAuthProcessType.rawValue, + ] + case .userFailedAuthorization(let errorLocalizedDescription): + parameters = [ + "error": errorLocalizedDescription, + ] } return parameters @@ -159,6 +180,13 @@ final class AnalyticsService: AnalyticsProcessing { case actionLogout case actionChangePaymentMethod case actionAuthWithoutWallet + + // MARK: - Authorization + + case userStartAuthorization + case userCancelAuthorization + case userSuccessAuthorization + case userFailedAuthorization } }