From bbd5cd904e2591696a0140b7c535704808fec72b Mon Sep 17 00:00:00 2001 From: Aleksey Belouosv Date: Tue, 13 Aug 2019 13:16:41 +0300 Subject: [PATCH] [iOS] Bookmarks subscription stats https://jira.mail.ru/browse/MAPSME-10946 --- .../BookmarksSubscriptionViewController.swift | 23 ++++++++++++++++++- .../Catalog/PaidRouteViewController.swift | 7 ++++++ .../Impl/PaidRouteStatistics.swift | 2 +- .../Subscriptions/SubscriptionManager.swift | 17 +++++++------- .../Maps/UI/Ads/RemoveAdsViewController.swift | 14 ++++++----- 5 files changed, 47 insertions(+), 16 deletions(-) diff --git a/iphone/Maps/Bookmarks/Catalog/BookmarksSubscriptionViewController.swift b/iphone/Maps/Bookmarks/Catalog/BookmarksSubscriptionViewController.swift index 3ca39e28a9..71fe1582ee 100644 --- a/iphone/Maps/Bookmarks/Catalog/BookmarksSubscriptionViewController.swift +++ b/iphone/Maps/Bookmarks/Catalog/BookmarksSubscriptionViewController.swift @@ -24,6 +24,19 @@ class BookmarksSubscriptionViewController: MWMViewController { get { return UIColor.isNightMode() ? .lightContent : .default } } + override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { + super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) + InAppPurchase.bookmarksSubscriptionManager.addListener(self) + } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + deinit { + InAppPurchase.bookmarksSubscriptionManager.removeListener(self) + } + override func viewDidLoad() { super.viewDidLoad() @@ -49,7 +62,9 @@ class BookmarksSubscriptionViewController: MWMViewController { image: UIImage(named: "bookmarksSubscriptionMonth")!) annualViewController.setSelected(true, animated: false) continueButton.setTitle(L("current_location_unknown_continue_button").uppercased(), for: .normal) - InAppPurchase.bookmarksSubscriptionManager.addListener(self) + + Statistics.logEvent(kStatInappShow, withParameters: [kStatVendor: MWMPurchaseManager.bookmarksSubscriptionVendorId(), + kStatPurchase: MWMPurchaseManager.bookmarksSubscriptionServerId()]) InAppPurchase.bookmarksSubscriptionManager.getAvailableSubscriptions { [weak self] (subscriptions, error) in guard let subscriptions = subscriptions, subscriptions.count == 2 else { // TODO: hande error @@ -90,6 +105,8 @@ class BookmarksSubscriptionViewController: MWMViewController { annualViewController.setSelected(true, animated: true) monthlyViewController.setSelected(false, animated: true) scrollView.scrollRectToVisible(annualView.convert(annualView.bounds, to: scrollView), animated: true) + Statistics.logEvent(kStatInappSelect, withParameters: [kStatProduct: selectedSubscription!.productId, + kStatPurchase: MWMPurchaseManager.bookmarksSubscriptionServerId()]) } @IBAction func onMonthlyViewTap(_ sender: UITapGestureRecognizer) { @@ -100,6 +117,8 @@ class BookmarksSubscriptionViewController: MWMViewController { annualViewController.setSelected(false, animated: true) monthlyViewController.setSelected(true, animated: true) scrollView.scrollRectToVisible(monthlyView.convert(monthlyView.bounds, to: scrollView), animated: true) + Statistics.logEvent(kStatInappSelect, withParameters: [kStatProduct: selectedSubscription!.productId, + kStatPurchase: MWMPurchaseManager.bookmarksSubscriptionServerId()]) } @IBAction func onContinue(_ sender: UIButton) { @@ -120,10 +139,12 @@ class BookmarksSubscriptionViewController: MWMViewController { InAppPurchase.bookmarksSubscriptionManager.subscribe(to: subscription) } + Statistics.logEvent(kStatInappPay, withParameters: [kStatPurchase: MWMPurchaseManager.bookmarksSubscriptionServerId()]) } @IBAction func onClose(_ sender: UIButton) { onCancel?() + Statistics.logEvent(kStatInappCancel, withParameters: [kStatPurchase: MWMPurchaseManager.bookmarksSubscriptionServerId()]) } } diff --git a/iphone/Maps/Bookmarks/Catalog/PaidRouteViewController.swift b/iphone/Maps/Bookmarks/Catalog/PaidRouteViewController.swift index 44202ce0e5..a8b9367089 100644 --- a/iphone/Maps/Bookmarks/Catalog/PaidRouteViewController.swift +++ b/iphone/Maps/Bookmarks/Catalog/PaidRouteViewController.swift @@ -105,6 +105,9 @@ class PaidRouteViewController: MWMViewController { self?.subscribeButton.setTitle(title, for: .normal) self?.subscribeButton.isEnabled = true self?.subscription = s + Statistics.logEvent(kStatInappShow, withParameters: [kStatVendor : MWMPurchaseManager.bookmarksSubscriptionVendorId(), + kStatProduct : s.productId, + kStatPurchase : MWMPurchaseManager.bookmarksSubscriptionServerId()]) } statistics.logPreviewShow() @@ -181,12 +184,16 @@ class PaidRouteViewController: MWMViewController { return } + Statistics.logEvent(kStatInappSelect, withParameters: [kStatProduct : subscription.productId, + kStatPurchase : MWMPurchaseManager.bookmarksSubscriptionServerId()]) + Statistics.logEvent(kStatInappPay, withParameters: [kStatPurchase : MWMPurchaseManager.bookmarksSubscriptionServerId()]) self?.subscriptionManager.subscribe(to: subscription) } } @IBAction func onCancel(_ sender: UIButton) { statistics.logCancel() + Statistics.logEvent(kStatInappCancel, withParameters: [kStatPurchase : MWMPurchaseManager.bookmarksSubscriptionServerId()]) delegate?.didCancelPurchase(self) } diff --git a/iphone/Maps/Core/InappPurchase/Impl/PaidRouteStatistics.swift b/iphone/Maps/Core/InappPurchase/Impl/PaidRouteStatistics.swift index 2ab27a5943..70ac83168a 100644 --- a/iphone/Maps/Core/InappPurchase/Impl/PaidRouteStatistics.swift +++ b/iphone/Maps/Core/InappPurchase/Impl/PaidRouteStatistics.swift @@ -16,7 +16,7 @@ class PaidRouteStatistics: IPaidRouteStatistics { } func logPay() { - logEvent(kStatInappSelect, withParameters: [kStatPurchase: serverId]) + logEvent(kStatInappSelect, withParameters: [kStatPurchase: serverId, kStatProduct: productId]) logEvent(kStatInappPay, withParameters: [kStatPurchase: serverId]) } diff --git a/iphone/Maps/Core/Subscriptions/SubscriptionManager.swift b/iphone/Maps/Core/Subscriptions/SubscriptionManager.swift index 025db3116c..18cce1d0a3 100644 --- a/iphone/Maps/Core/Subscriptions/SubscriptionManager.swift +++ b/iphone/Maps/Core/Subscriptions/SubscriptionManager.swift @@ -94,15 +94,15 @@ class SubscriptionManager: NSObject { private func logEvents(_ validationResult: MWMValidationResult) { switch validationResult { case .valid: - Statistics.logEvent(kStatInappValidationSuccess) + Statistics.logEvent(kStatInappValidationSuccess, withParameters: [kStatPurchase : serverId]) Statistics.logEvent(kStatInappProductDelivered, - withParameters: [kStatVendor : vendorId]) + withParameters: [kStatVendor : vendorId, kStatPurchase : serverId]) case .notValid: - Statistics.logEvent(kStatInappValidationError, withParameters: [kStatErrorCode : 0]) + Statistics.logEvent(kStatInappValidationError, withParameters: [kStatErrorCode : 0, kStatPurchase : serverId]) case .serverError: - Statistics.logEvent(kStatInappValidationError, withParameters: [kStatErrorCode : 2]) + Statistics.logEvent(kStatInappValidationError, withParameters: [kStatErrorCode : 2, kStatPurchase : serverId]) case .authError: - Statistics.logEvent(kStatInappValidationError, withParameters: [kStatErrorCode : 1]) + Statistics.logEvent(kStatInappValidationError, withParameters: [kStatErrorCode : 1, kStatPurchase : serverId]) } } } @@ -110,7 +110,7 @@ class SubscriptionManager: NSObject { extension SubscriptionManager: SKProductsRequestDelegate { func request(_ request: SKRequest, didFailWithError error: Error) { Statistics.logEvent(kStatInappPaymentError, - withParameters: [kStatError : error.localizedDescription]) + withParameters: [kStatError : error.localizedDescription, kStatPurchase : serverId]) subscriptionsComplection?(nil, error) subscriptionsComplection = nil productsRequest = nil @@ -167,7 +167,7 @@ extension SubscriptionManager: SKPaymentTransactionObserver { private func processPurchased(_ transaction: SKPaymentTransaction) { paymentQueue.finishTransaction(transaction) if let ps = pendingSubscription, transaction.payment.productIdentifier == ps.productId { - Statistics.logEvent(kStatInappPaymentSuccess) + Statistics.logEvent(kStatInappPaymentSuccess, withParameters: [kStatPurchase : serverId]) listeners.allObjects.forEach { $0.didSubsribe(ps) } } } @@ -182,8 +182,9 @@ extension SubscriptionManager: SKPaymentTransactionObserver { private func processFailed(_ transaction: SKPaymentTransaction, error: Error?) { paymentQueue.finishTransaction(transaction) if let ps = pendingSubscription, transaction.payment.productIdentifier == ps.productId { + let errorText = error?.localizedDescription ?? "" Statistics.logEvent(kStatInappPaymentError, - withParameters: [kStatError : error?.localizedDescription ?? ""]) + withParameters: [kStatPurchase : serverId, kStatError : errorText]) listeners.allObjects.forEach { $0.didFailToSubscribe(ps, error: error) } } } diff --git a/iphone/Maps/UI/Ads/RemoveAdsViewController.swift b/iphone/Maps/UI/Ads/RemoveAdsViewController.swift index fb0d928b3e..6a45062710 100644 --- a/iphone/Maps/UI/Ads/RemoveAdsViewController.swift +++ b/iphone/Maps/UI/Ads/RemoveAdsViewController.swift @@ -113,12 +113,13 @@ import SafariServices arguments: [VC.formatPrice(yearlyDiscount, locale: locale)]) self.monthButton.setTitle(String(coreFormat: L("options_dropdown_item1"), - arguments: [VC.formatPrice(monthlyPrice ?? 0, locale: locale), + arguments: [VC.formatPrice(monthlyPrice, locale: locale), VC.formatPrice(monthlyDiscount, locale: locale)]), for: .normal) self.weekButton.setTitle(String(coreFormat: L("options_dropdown_item2"), - arguments: [VC.formatPrice(weeklyPrice ?? 0, locale: locale)]), for: .normal) + arguments: [VC.formatPrice(weeklyPrice, locale: locale)]), for: .normal) Statistics.logEvent(kStatInappShow, withParameters: [kStatVendor : MWMPurchaseManager.adsRemovalVendorId(), - kStatProduct : subscriptions[0].productId]) + kStatProduct : subscriptions[0].productId, + kStatPurchase : MWMPurchaseManager.adsRemovalServerId()]) } } @@ -131,7 +132,7 @@ import SafariServices } @IBAction func onClose(_ sender: Any) { - Statistics.logEvent(kStatInappCancel) + Statistics.logEvent(kStatInappCancel, withParameters: [kStatPurchase : MWMPurchaseManager.adsRemovalServerId()]) delegate?.didCancelSubscribtion(self) } @@ -185,8 +186,9 @@ import SafariServices self.delegate?.didCancelSubscribtion(self) return } - Statistics.logEvent(kStatInappSelect, withParameters: [kStatProduct : subscription.productId]) - Statistics.logEvent(kStatInappPay) + Statistics.logEvent(kStatInappSelect, withParameters: [kStatProduct : subscription.productId, + kStatPurchase : MWMPurchaseManager.adsRemovalServerId()]) + Statistics.logEvent(kStatInappPay, withParameters: [kStatPurchase : MWMPurchaseManager.adsRemovalServerId()]) showPurchaseProgress() InAppPurchase.adsRemovalSubscriptionManager.subscribe(to: subscription) }