From 9a5e96db791664f01a311684b07186de03eb56e9 Mon Sep 17 00:00:00 2001 From: Aleksey Belouosv Date: Tue, 20 Aug 2019 18:55:23 +0300 Subject: [PATCH] [iOS] add missing subscription stats --- .../Catalog/BookmarksSubscriptionViewController.swift | 6 +++++- iphone/Maps/Bookmarks/Catalog/PaidRouteViewController.swift | 1 + iphone/Maps/Classes/MapsAppDelegate.mm | 6 +++++- iphone/Maps/Common/Statistics/StatisticsStrings.h | 1 + iphone/Maps/Core/Subscriptions/MWMPurchaseManager.h | 1 + iphone/Maps/Core/Subscriptions/MWMPurchaseManager.mm | 4 ++++ 6 files changed, 17 insertions(+), 2 deletions(-) diff --git a/iphone/Maps/Bookmarks/Catalog/BookmarksSubscriptionViewController.swift b/iphone/Maps/Bookmarks/Catalog/BookmarksSubscriptionViewController.swift index d2366a774b..8885963ccc 100644 --- a/iphone/Maps/Bookmarks/Catalog/BookmarksSubscriptionViewController.swift +++ b/iphone/Maps/Bookmarks/Catalog/BookmarksSubscriptionViewController.swift @@ -69,7 +69,9 @@ class BookmarksSubscriptionViewController: MWMViewController { scrollView.isUserInteractionEnabled = false Statistics.logEvent(kStatInappShow, withParameters: [kStatVendor: MWMPurchaseManager.bookmarksSubscriptionVendorId(), - kStatPurchase: MWMPurchaseManager.bookmarksSubscriptionServerId()]) + kStatPurchase: MWMPurchaseManager.bookmarksSubscriptionServerId(), + kStatProduct: BOOKMARKS_SUBSCRIPTION_YEARLY_PRODUCT_ID, + kStatFrom: kStatBanner]) InAppPurchase.bookmarksSubscriptionManager.getAvailableSubscriptions { [weak self] (subscriptions, error) in guard let subscriptions = subscriptions, subscriptions.count == 2 else { MWMAlertViewController.activeAlert().presentInfoAlert(L("price_error_title"), @@ -154,6 +156,7 @@ class BookmarksSubscriptionViewController: MWMViewController { @IBAction func onRestore(_ sender: UIButton) { loadingView.isHidden = false + Statistics.logEvent(kStatInappRestore, withParameters: [kStatPurchase: MWMPurchaseManager.bookmarksSubscriptionServerId()]) InAppPurchase.bookmarksSubscriptionManager.restore { [weak self] result in self?.loadingView.isHidden = true let alertText: String @@ -215,6 +218,7 @@ extension BookmarksSubscriptionViewController: SubscriptionManagerListener { } func didSubsribe(_ subscription: ISubscription) { + MWMPurchaseManager.setBookmarksSubscriptionActive(true) } func didDefer(_ subscription: ISubscription) { diff --git a/iphone/Maps/Bookmarks/Catalog/PaidRouteViewController.swift b/iphone/Maps/Bookmarks/Catalog/PaidRouteViewController.swift index a8b9367089..79d44ded80 100644 --- a/iphone/Maps/Bookmarks/Catalog/PaidRouteViewController.swift +++ b/iphone/Maps/Bookmarks/Catalog/PaidRouteViewController.swift @@ -238,6 +238,7 @@ extension PaidRouteViewController : SubscriptionManagerListener { } func didSubsribe(_ subscription: ISubscription) { + MWMPurchaseManager.setBookmarksSubscriptionActive(true) } func didDefer(_ subscription: ISubscription) { diff --git a/iphone/Maps/Classes/MapsAppDelegate.mm b/iphone/Maps/Classes/MapsAppDelegate.mm index 2b50871714..817bb353d5 100644 --- a/iphone/Maps/Classes/MapsAppDelegate.mm +++ b/iphone/Maps/Classes/MapsAppDelegate.mm @@ -248,7 +248,11 @@ using namespace osm_auth_ios; [UNUserNotificationCenter currentNotificationCenter].delegate = self.notificationManager; if ([MWMFrameworkHelper isWiFiConnected]) { - [[InAppPurchase bookmarksSubscriptionManager] validateWithCompletion:nil]; + [[InAppPurchase bookmarksSubscriptionManager] validateWithCompletion:^(MWMValidationResult result) { + if (result == MWMValidationResultNotValid) { + [MWMPurchaseManager setBookmarksSubscriptionActive:NO]; + } + }]; [[InAppPurchase adsRemovalSubscriptionManager] validateWithCompletion:^(MWMValidationResult result) { [MWMPurchaseManager setAdsDisabled:result != MWMValidationResultNotValid]; }]; diff --git a/iphone/Maps/Common/Statistics/StatisticsStrings.h b/iphone/Maps/Common/Statistics/StatisticsStrings.h index d6cddf36b4..95fcf96d7e 100644 --- a/iphone/Maps/Common/Statistics/StatisticsStrings.h +++ b/iphone/Maps/Common/Statistics/StatisticsStrings.h @@ -208,6 +208,7 @@ static NSString * const kStatInappPay = @"InAppPurchase_Preview_pay"; static NSString * const kStatInappPaymentError = @"InAppPurchase_Store_error"; static NSString * const kStatInappPaymentSuccess = @"InAppPurchase_Store_success"; static NSString * const kStatInappProductDelivered = @"InAppPurchase_Product_delivered"; +static NSString * const kStatInappRestore = @"InAppPurchase_Preview_restore"; static NSString * const kStatInappSelect = @"InAppPurchase_Preview_select"; static NSString * const kStatInappShow = @"InAppPurchase_Preview_show"; static NSString * const kStatInappValidationSuccess = @"InAppPurchase_Validation_success"; diff --git a/iphone/Maps/Core/Subscriptions/MWMPurchaseManager.h b/iphone/Maps/Core/Subscriptions/MWMPurchaseManager.h index fc4426c515..4ea240f33e 100644 --- a/iphone/Maps/Core/Subscriptions/MWMPurchaseManager.h +++ b/iphone/Maps/Core/Subscriptions/MWMPurchaseManager.h @@ -25,6 +25,7 @@ typedef void (^StartTransactionCallback)(BOOL success, NSString * serverId); + (NSArray *)legacyProductIds; + (NSArray *)bookmarkInappIds; + (void)setAdsDisabled:(BOOL)disabled; ++ (void)setBookmarksSubscriptionActive:(BOOL)active; - (instancetype)initWithVendorId:(NSString *)vendorId; - (void)validateReceipt:(NSString *)serverId diff --git a/iphone/Maps/Core/Subscriptions/MWMPurchaseManager.mm b/iphone/Maps/Core/Subscriptions/MWMPurchaseManager.mm index cf5756ed44..654ffabfb7 100644 --- a/iphone/Maps/Core/Subscriptions/MWMPurchaseManager.mm +++ b/iphone/Maps/Core/Subscriptions/MWMPurchaseManager.mm @@ -177,6 +177,10 @@ GetFramework().GetPurchase()->SetSubscriptionEnabled(SubscriptionType::RemoveAds, disabled); } ++ (void)setBookmarksSubscriptionActive:(BOOL)active { + GetFramework().GetPurchase()->SetSubscriptionEnabled(SubscriptionType::BookmarkCatalog, active); +} + #pragma mark - SKRequestDelegate - (void)requestDidFinish:(SKRequest *)request