From e8eb98ab2c52966fcafa4f1b0648e8239e55ac91 Mon Sep 17 00:00:00 2001 From: Alexander Boriskov Date: Mon, 25 May 2020 12:31:46 +0300 Subject: [PATCH] [iOS] Changed staistics for authorization https://jira.mail.ru/browse/MAPSME-13631 --- iphone/CoreApi/CoreApi/User/MWMUser.h | 6 -- iphone/CoreApi/CoreApi/User/MWMUser.mm | 3 +- .../Catalog/CatalogWebViewController.swift | 4 +- .../BaseSubscriptionViewController.swift | 4 +- .../BMCView/BMCViewController.swift | 2 +- .../BookmarksSharingViewController.swift | 2 +- .../Sharing/EditOnWebViewController.swift | 2 +- .../UIViewController+Authorization.swift | 4 +- iphone/Maps/Classes/MapViewController.mm | 5 +- .../Common/Statistics/StatisticsStrings.h | 17 ++++-- .../AuthorizationViewController.swift | 57 ++++++++++++------- .../UGCAddReview/UGCAddReviewController.swift | 3 +- .../UI/Settings/MWMSettingsViewController.mm | 2 +- 13 files changed, 60 insertions(+), 51 deletions(-) diff --git a/iphone/CoreApi/CoreApi/User/MWMUser.h b/iphone/CoreApi/CoreApi/User/MWMUser.h index e08ba1e5c81..f6241fc8cb4 100644 --- a/iphone/CoreApi/CoreApi/User/MWMUser.h +++ b/iphone/CoreApi/CoreApi/User/MWMUser.h @@ -9,11 +9,6 @@ typedef NS_ENUM(NSInteger, MWMSocialTokenType) { MWMSocialTokenTypeApple } NS_SWIFT_NAME(SocialTokenType); -typedef NS_ENUM(NSInteger, MWMAuthorizationSource) { - MWMAuthorizationSourceUGC, - MWMAuthorizationSourceBookmarks -} NS_SWIFT_NAME(AuthorizationSource); - NS_ASSUME_NONNULL_BEGIN NS_SWIFT_NAME(User) @@ -32,7 +27,6 @@ NS_SWIFT_NAME(User) promoAccepted:(BOOL)promoAccepted firstName:(NSString *)firstName lastName:(NSString *)lastName - source:(MWMAuthorizationSource)source onComplete:(MWMBoolBlock)onComplete; @end diff --git a/iphone/CoreApi/CoreApi/User/MWMUser.mm b/iphone/CoreApi/CoreApi/User/MWMUser.mm index 544f4c6e73f..eef2a411d91 100644 --- a/iphone/CoreApi/CoreApi/User/MWMUser.mm +++ b/iphone/CoreApi/CoreApi/User/MWMUser.mm @@ -31,7 +31,6 @@ + (void)authenticateWithToken:(NSString *)token promoAccepted:(BOOL)promoAccepted firstName:(NSString *)firstName lastName:(NSString *)lastName - source:(MWMAuthorizationSource)source onComplete:(MWMBoolBlock)onComplete { auto &user = GetFramework().GetUser(); User::SocialTokenType socialTokenType; @@ -52,7 +51,7 @@ + (void)authenticateWithToken:(NSString *)token } auto s = std::make_unique(); s->m_postCallAction = User::Subscriber::Action::RemoveSubscriber; - s->m_onAuthenticate = [provider, source, onComplete](bool success) { + s->m_onAuthenticate = [provider, onComplete](bool success) { dispatch_async(dispatch_get_main_queue(), ^{ onComplete(success); }); diff --git a/iphone/Maps/Bookmarks/Catalog/CatalogWebViewController.swift b/iphone/Maps/Bookmarks/Catalog/CatalogWebViewController.swift index 62c81b31b09..8985984ba56 100644 --- a/iphone/Maps/Bookmarks/Catalog/CatalogWebViewController.swift +++ b/iphone/Maps/Bookmarks/Catalog/CatalogWebViewController.swift @@ -252,7 +252,7 @@ final class CatalogWebViewController: WebViewController { self?.loadingIndicator.stopAnimating() case .needAuth: if let s = self, let navBar = s.navigationController?.navigationBar { - s.signup(anchor: navBar, onComplete: { + s.signup(anchor: navBar, source: .guideCatalogue, onComplete: { if $0 { s.handlePendingTransactions(completion: completion) } else { @@ -319,7 +319,7 @@ final class CatalogWebViewController: WebViewController { switch (status) { case .needAuth: if let s = self, let navBar = s.navigationController?.navigationBar{ - s.signup(anchor: navBar) { + s.signup(anchor: navBar, source: .guideCatalogue) { if $0 { s.download() } } } diff --git a/iphone/Maps/Bookmarks/Catalog/Subscription/BaseSubscriptionViewController.swift b/iphone/Maps/Bookmarks/Catalog/Subscription/BaseSubscriptionViewController.swift index dce0388f13a..5c74040846f 100644 --- a/iphone/Maps/Bookmarks/Catalog/Subscription/BaseSubscriptionViewController.swift +++ b/iphone/Maps/Bookmarks/Catalog/Subscription/BaseSubscriptionViewController.swift @@ -83,7 +83,7 @@ class BaseSubscriptionViewController: MWMViewController { guard let subscription = subscriptionGroup?[period]?.subscription else{ return } - signup(anchor: sender) { [weak self] success in + signup(anchor: sender, source: .subscription) { [weak self] success in guard success else { return } self?.loadingView.isHidden = false self?.bookmarksManager.ping { success in @@ -104,7 +104,7 @@ class BaseSubscriptionViewController: MWMViewController { @IBAction func onRestore(_ sender: UIButton) { Statistics.logEvent(kStatInappRestore, withParameters: [kStatPurchase: subscriptionManager?.serverId ?? ""]) - signup(anchor: sender) { [weak self] (success) in + signup(anchor: sender, source: .subscription) { [weak self] (success) in guard success else { return } self?.loadingView.isHidden = false self?.subscriptionManager?.restore { result in diff --git a/iphone/Maps/Bookmarks/Categories/BMCView/BMCViewController.swift b/iphone/Maps/Bookmarks/Categories/BMCView/BMCViewController.swift index 29bfdde3e5b..016b29bc063 100644 --- a/iphone/Maps/Bookmarks/Categories/BMCView/BMCViewController.swift +++ b/iphone/Maps/Bookmarks/Categories/BMCView/BMCViewController.swift @@ -305,7 +305,7 @@ extension BMCViewController: BMCPermissionsCellDelegate { switch permission { case .signup: viewModel.pendingPermission(isPending: true) - signup(anchor: anchor, onComplete: { [viewModel] success in + signup(anchor: anchor, source: .bookmarksBackup, onComplete: { [viewModel] success in viewModel!.grant(permission: success ? .backup : nil) }) case .backup: diff --git a/iphone/Maps/Bookmarks/Categories/Sharing/BookmarksSharingViewController.swift b/iphone/Maps/Bookmarks/Categories/Sharing/BookmarksSharingViewController.swift index 2a68433e217..9e2ddbb7ca2 100644 --- a/iphone/Maps/Bookmarks/Categories/Sharing/BookmarksSharingViewController.swift +++ b/iphone/Maps/Bookmarks/Categories/Sharing/BookmarksSharingViewController.swift @@ -298,7 +298,7 @@ final class BookmarksSharingViewController: MWMTableViewController { private func performAfterValidation(anchor: UIView, action: @escaping MWMVoidBlock) { if FrameworkHelper.isNetworkConnected() { - signup(anchor: anchor, onComplete: { success in + signup(anchor: anchor, source: .exportBookmarks, onComplete: { success in if success { action() } else { diff --git a/iphone/Maps/Bookmarks/Categories/Sharing/EditOnWebViewController.swift b/iphone/Maps/Bookmarks/Categories/Sharing/EditOnWebViewController.swift index 5245879e93b..72db7e0dad6 100644 --- a/iphone/Maps/Bookmarks/Categories/Sharing/EditOnWebViewController.swift +++ b/iphone/Maps/Bookmarks/Categories/Sharing/EditOnWebViewController.swift @@ -131,7 +131,7 @@ final class EditOnWebViewController: MWMViewController { } private func authError() { - signup(anchor: sendMeLinkButton) { + signup(anchor: sendMeLinkButton, source: .exportBookmarks) { if ($0) { self.uploadCategory() } diff --git a/iphone/Maps/Categories/UIViewController+Authorization.swift b/iphone/Maps/Categories/UIViewController+Authorization.swift index 0d51319b7e1..03dbf787139 100644 --- a/iphone/Maps/Categories/UIViewController+Authorization.swift +++ b/iphone/Maps/Categories/UIViewController+Authorization.swift @@ -1,10 +1,10 @@ extension UIViewController { - @objc func signup(anchor: UIView, onComplete: @escaping (Bool) -> Void) { + @objc func signup(anchor: UIView, source: AuthorizationSource, onComplete: @escaping (Bool) -> Void) { if User.isAuthenticated() { onComplete(true) } else { let authVC = AuthorizationViewController(popoverSourceView: anchor, - sourceComponent: .bookmarks, + source: source, permittedArrowDirections: .any, successHandler: { _ in onComplete(true) }, errorHandler: { _ in onComplete(false) }) diff --git a/iphone/Maps/Classes/MapViewController.mm b/iphone/Maps/Classes/MapViewController.mm index d575cb02f69..92e1fc0ffba 100644 --- a/iphone/Maps/Classes/MapViewController.mm +++ b/iphone/Maps/Classes/MapViewController.mm @@ -486,10 +486,9 @@ - (void)openFullPlaceDescriptionWithHtml:(NSString *)htmlString { } - (void)showUGCAuth { - [Statistics logEvent:kStatUGCReviewAuthShown]; if (IPAD) { auto controller = [[MWMAuthorizationViewController alloc] initWithPopoverSourceView:self.controlsManager.anchorView - sourceComponent:MWMAuthorizationSourceUGC + source:AuthorizationSourceAfterSaveReview permittedArrowDirections:UIPopoverArrowDirectionDown successHandler:nil errorHandler:nil @@ -500,7 +499,7 @@ - (void)showUGCAuth { } auto controller = [[MWMAuthorizationViewController alloc] initWithBarButtonItem:nil - sourceComponent:MWMAuthorizationSourceUGC + source:AuthorizationSourceAfterSaveReview successHandler:nil errorHandler:nil completionHandler:nil]; diff --git a/iphone/Maps/Common/Statistics/StatisticsStrings.h b/iphone/Maps/Common/Statistics/StatisticsStrings.h index ffe75971285..b32c6a27621 100644 --- a/iphone/Maps/Common/Statistics/StatisticsStrings.h +++ b/iphone/Maps/Common/Statistics/StatisticsStrings.h @@ -33,6 +33,17 @@ static NSString * const kStatApply = @"Apply"; static NSString * const kStatAsk = @"Ask"; static NSString * const kStatAttractions = @"Attractions"; static NSString * const kStatAuth = @"auth"; +static NSString * const kStatAuthFromAfterSaveReview = @"after_save_review"; +static NSString * const kStatAuthFromBookmarksBackup = @"bookmarks_backup"; +static NSString * const kStatAuthFromGuideCatalogue = @"guide_catalogue"; +static NSString * const kStatAuthFromExportBookmarks = @"export_bookmarks"; +static NSString * const kStatAuthFromSubscription = @"subscription"; +static NSString * const kStatAuthShown = @"Auth_shown"; +static NSString * const kStatAuthDeclined = @"Auth_declined"; +static NSString * const kStatAuthStart = @"Auth_start"; +static NSString * const kStatAuthExternalRequestSuccess = @"Auth_external_request_success"; +static NSString * const kStatAuthRequestSucces = @"Auth_request_success"; +static NSString * const kStatAuthError = @"Auth_error"; static NSString * const kStatAuthorization = @"Authorization"; static NSString * const kStatAutoDownload = @"Auto download"; static NSString * const kStatAutoZoom = @"Autozoom"; @@ -512,12 +523,6 @@ static NSString * const kStatTracks = @"tracks"; static NSString * const kStatTraffic = @"Traffic"; static NSString * const kStatType = @"type"; static NSString * const kStatTypes = @"types"; -static NSString * const kStatUGCReviewAuthDeclined = @"UGC_Auth_declined"; -static NSString * const kStatUGCReviewAuthError = @"UGC_Auth_error"; -static NSString * const kStatUGCReviewAuthExternalRequestSuccess = - @"UGC_Auth_external_request_success"; -static NSString * const kStatUGCReviewAuthRequestSuccess = @"UGC_Auth_request_success"; -static NSString * const kStatUGCReviewAuthShown = @"UGC_Auth_shown"; static NSString * const kStatUGCReviewCancel = @"UGC_Review_cancel"; static NSString * const kStatUGCReviewError = @"UGC_Review_error"; static NSString * const kStatUGCReviewNotificationClicked = @"UGC_ReviewNotification_clicked"; diff --git a/iphone/Maps/UI/Authorization/AuthorizationViewController.swift b/iphone/Maps/UI/Authorization/AuthorizationViewController.swift index d901c4921c2..8033b229929 100644 --- a/iphone/Maps/UI/Authorization/AuthorizationViewController.swift +++ b/iphone/Maps/UI/Authorization/AuthorizationViewController.swift @@ -9,6 +9,29 @@ import AuthenticationServices case passportError } +@objc enum AuthorizationSource: Int { + case afterSaveReview + case bookmarksBackup + case guideCatalogue + case exportBookmarks + case subscription + + var stat: String { + switch self { + case .afterSaveReview: + return kStatAuthFromAfterSaveReview + case .bookmarksBackup: + return kStatAuthFromBookmarksBackup + case .guideCatalogue: + return kStatAuthFromGuideCatalogue + case .exportBookmarks: + return kStatAuthFromExportBookmarks + case .subscription: + return kStatAuthFromSubscription + } + } +} + @objc(MWMAuthorizationViewController) final class AuthorizationViewController: MWMViewController { @@ -134,14 +157,14 @@ final class AuthorizationViewController: MWMViewController { typealias ErrorHandler = (AuthorizationError) -> Void typealias CompletionHandler = (AuthorizationViewController) -> Void - private let sourceComponent: AuthorizationSource + private let source: AuthorizationSource private let successHandler: SuccessHandler? private let errorHandler: ErrorHandler? private let completionHandler: CompletionHandler? @objc - init(barButtonItem: UIBarButtonItem?, sourceComponent: AuthorizationSource, successHandler: SuccessHandler? = nil, errorHandler: ErrorHandler? = nil, completionHandler: CompletionHandler? = nil) { - self.sourceComponent = sourceComponent + init(barButtonItem: UIBarButtonItem?, source: AuthorizationSource, successHandler: SuccessHandler? = nil, errorHandler: ErrorHandler? = nil, completionHandler: CompletionHandler? = nil) { + self.source = source self.successHandler = successHandler self.errorHandler = errorHandler self.completionHandler = completionHandler @@ -152,8 +175,8 @@ final class AuthorizationViewController: MWMViewController { } @objc - init(popoverSourceView: UIView? = nil, sourceComponent: AuthorizationSource, permittedArrowDirections: UIPopoverArrowDirection = .unknown, successHandler: SuccessHandler? = nil, errorHandler: ErrorHandler? = nil, completionHandler: CompletionHandler? = nil) { - self.sourceComponent = sourceComponent + init(popoverSourceView: UIView? = nil, source: AuthorizationSource, permittedArrowDirections: UIPopoverArrowDirection = .unknown, successHandler: SuccessHandler? = nil, errorHandler: ErrorHandler? = nil, completionHandler: CompletionHandler? = nil) { + self.source = source self.successHandler = successHandler self.errorHandler = errorHandler self.completionHandler = completionHandler @@ -187,6 +210,7 @@ final class AuthorizationViewController: MWMViewController { override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) + Statistics.logEvent(kStatAuthShown, withParameters: [kStatFrom: source.stat]) } override func viewDidLayoutSubviews() { @@ -209,7 +233,7 @@ final class AuthorizationViewController: MWMViewController { } @IBAction func onCancel() { - Statistics.logEvent(kStatUGCReviewAuthDeclined) + Statistics.logEvent(kStatAuthDeclined, withParameters: [kStatFrom: source.stat]) errorHandler?(.cancelled) onClose() } @@ -231,7 +255,7 @@ final class AuthorizationViewController: MWMViewController { } private func process(error: Error, type: SocialTokenType) { - Statistics.logEvent(kStatUGCReviewAuthError, withParameters: [ + Statistics.logEvent(kStatAuthError, withParameters: [ kStatProvider: getProviderStatStr(type: type), kStatError: error.localizedDescription, ]) @@ -243,7 +267,7 @@ final class AuthorizationViewController: MWMViewController { type: SocialTokenType, firstName: String = "", lastName: String = "") { - Statistics.logEvent(kStatUGCReviewAuthExternalRequestSuccess, + Statistics.logEvent(kStatAuthExternalRequestSuccess, withParameters: [kStatProvider: getProviderStatStr(type: type)]) User.authenticate(withToken: token, type: type, @@ -251,8 +275,7 @@ final class AuthorizationViewController: MWMViewController { termsAccepted: termsOfUseCheck.isChecked, promoAccepted: latestNewsCheck.isChecked, firstName: firstName, - lastName: lastName, - source: sourceComponent) { success in + lastName: lastName) { success in self.logStats(type: type, success: success) if success { self.successHandler?(type) @@ -278,20 +301,10 @@ final class AuthorizationViewController: MWMViewController { fatalError() } - let event: String? - switch self.sourceComponent { - case .UGC: - event = success ? kStatUGCReviewAuthRequestSuccess : kStatUGCReviewAuthError - case .bookmarks: - event = success ? kStatBookmarksAuthRequestSuccess : kStatBookmarksAuthRequestError - @unknown default: - fatalError() - } - if success { - Statistics.logEvent(event, withParameters: [kStatProvider : provider]) + Statistics.logEvent(kStatAuthRequestSucces, withParameters: [kStatProvider : provider]) } else { - Statistics.logEvent(event, withParameters: [kStatProvider : provider, kStatError : ""]) + Statistics.logEvent(kStatAuthError, withParameters: [kStatProvider : provider, kStatError : ""]) } } } diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCAddReview/UGCAddReviewController.swift b/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCAddReview/UGCAddReviewController.swift index bf8d6967e61..e351031eab5 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCAddReview/UGCAddReviewController.swift +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/UGC/UGCAddReview/UGCAddReviewController.swift @@ -92,9 +92,8 @@ final class UGCAddReviewController: MWMTableViewController { } nc.popViewController(animated: true) } else { - Statistics.logEvent(kStatUGCReviewAuthShown, withParameters: [kStatFrom: kStatAfterSave]) let authVC = AuthorizationViewController(barButtonItem: self.navigationItem.rightBarButtonItem!, - sourceComponent: .UGC, + source: .afterSaveReview, successHandler: {_ in onSuccess()}, errorHandler: {_ in onError()}, completionHandler: {_ in onComplete()}) diff --git a/iphone/Maps/UI/Settings/MWMSettingsViewController.mm b/iphone/Maps/UI/Settings/MWMSettingsViewController.mm index 87bf637cc84..482fc3c72cd 100644 --- a/iphone/Maps/UI/Settings/MWMSettingsViewController.mm +++ b/iphone/Maps/UI/Settings/MWMSettingsViewController.mm @@ -365,7 +365,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; __weak auto s = self; - [self signupWithAnchor:self.restoreSubscriptionCell.progress onComplete:^(BOOL success) { + [self signupWithAnchor:self.restoreSubscriptionCell.progress source:AuthorizationSourceSubscription onComplete:^(BOOL success) { if (success) { [s restoreSubscription]; }