Skip to content

Commit

Permalink
[iOS] Changed staistics for authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
Polas authored and beloal committed May 26, 2020
1 parent 7080752 commit e8eb98a
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 51 deletions.
6 changes: 0 additions & 6 deletions iphone/CoreApi/CoreApi/User/MWMUser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -32,7 +27,6 @@ NS_SWIFT_NAME(User)
promoAccepted:(BOOL)promoAccepted
firstName:(NSString *)firstName
lastName:(NSString *)lastName
source:(MWMAuthorizationSource)source
onComplete:(MWMBoolBlock)onComplete;

@end
Expand Down
3 changes: 1 addition & 2 deletions iphone/CoreApi/CoreApi/User/MWMUser.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -52,7 +51,7 @@ + (void)authenticateWithToken:(NSString *)token
}
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);
});
Expand Down
4 changes: 2 additions & 2 deletions iphone/Maps/Bookmarks/Catalog/CatalogWebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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() }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ final class EditOnWebViewController: MWMViewController {
}

private func authError() {
signup(anchor: sendMeLinkButton) {
signup(anchor: sendMeLinkButton, source: .exportBookmarks) {
if ($0) {
self.uploadCategory()
}
Expand Down
4 changes: 2 additions & 2 deletions iphone/Maps/Categories/UIViewController+Authorization.swift
Original file line number Diff line number Diff line change
@@ -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) })
Expand Down
5 changes: 2 additions & 3 deletions iphone/Maps/Classes/MapViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -500,7 +499,7 @@ - (void)showUGCAuth {
}

auto controller = [[MWMAuthorizationViewController alloc] initWithBarButtonItem:nil
sourceComponent:MWMAuthorizationSourceUGC
source:AuthorizationSourceAfterSaveReview
successHandler:nil
errorHandler:nil
completionHandler:nil];
Expand Down
17 changes: 11 additions & 6 deletions iphone/Maps/Common/Statistics/StatisticsStrings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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";
Expand Down
57 changes: 35 additions & 22 deletions iphone/Maps/UI/Authorization/AuthorizationViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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() {
Expand All @@ -209,7 +233,7 @@ final class AuthorizationViewController: MWMViewController {
}

@IBAction func onCancel() {
Statistics.logEvent(kStatUGCReviewAuthDeclined)
Statistics.logEvent(kStatAuthDeclined, withParameters: [kStatFrom: source.stat])
errorHandler?(.cancelled)
onClose()
}
Expand All @@ -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,
])
Expand All @@ -243,16 +267,15 @@ 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,
privacyAccepted: privacyPolicyCheck.isChecked,
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)
Expand All @@ -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 : ""])
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()})
Expand Down
2 changes: 1 addition & 1 deletion iphone/Maps/UI/Settings/MWMSettingsViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down

0 comments on commit e8eb98a

Please sign in to comment.