[iOS] Changed staistics for authorization

https://jira.mail.ru/browse/MAPSME-13631
This commit is contained in:
Alexander Boriskov 2020-05-25 12:31:46 +03:00 committed by Aleksey Belousov
parent 7080752c7c
commit e8eb98ab2c
13 changed files with 60 additions and 51 deletions

View file

@ -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

View file

@ -31,7 +31,6 @@
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 @@
}
auto s = std::make_unique<User::Subscriber>();
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);
});

View file

@ -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() }
}
}

View file

@ -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

View file

@ -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:

View file

@ -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 {

View file

@ -131,7 +131,7 @@ final class EditOnWebViewController: MWMViewController {
}
private func authError() {
signup(anchor: sendMeLinkButton) {
signup(anchor: sendMeLinkButton, source: .exportBookmarks) {
if ($0) {
self.uploadCategory()
}

View file

@ -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) })

View file

@ -486,10 +486,9 @@ NSString *const kPP2BookmarkEditingSegue = @"PP2BookmarkEditing";
}
- (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 @@ NSString *const kPP2BookmarkEditingSegue = @"PP2BookmarkEditing";
}
auto controller = [[MWMAuthorizationViewController alloc] initWithBarButtonItem:nil
sourceComponent:MWMAuthorizationSourceUGC
source:AuthorizationSourceAfterSaveReview
successHandler:nil
errorHandler:nil
completionHandler:nil];

View file

@ -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";

View file

@ -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 : ""])
}
}
}

View file

@ -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()})

View file

@ -365,7 +365,7 @@ using namespace power_management;
{
[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];
}