[iOS] Bookmarks subscription stats

https://jira.mail.ru/browse/MAPSME-10946
This commit is contained in:
Aleksey Belouosv 2019-08-13 13:16:41 +03:00 committed by Aleksandr Zatsepin
parent 8960887418
commit bbd5cd904e
5 changed files with 47 additions and 16 deletions

View file

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

View file

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

View file

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

View file

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

View file

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