Skip to content

Commit

Permalink
[MOC-762] Add MoneyAuth SDK metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
oltv00 committed Oct 16, 2020
1 parent ae8ba74 commit e2c5278
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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)
}
}
}
Expand All @@ -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()
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -159,6 +180,13 @@ final class AnalyticsService: AnalyticsProcessing {
case actionLogout
case actionChangePaymentMethod
case actionAuthWithoutWallet

// MARK: - Authorization

case userStartAuthorization
case userCancelAuthorization
case userSuccessAuthorization
case userFailedAuthorization
}
}

Expand Down

0 comments on commit e2c5278

Please sign in to comment.