diff --git a/iphone/Maps/Common/Statistics/StatisticsStrings.h b/iphone/Maps/Common/Statistics/StatisticsStrings.h index 10ed41aa0b..d498d228a1 100644 --- a/iphone/Maps/Common/Statistics/StatisticsStrings.h +++ b/iphone/Maps/Common/Statistics/StatisticsStrings.h @@ -163,6 +163,16 @@ static NSString * const kStatHotel = @"hotel"; static NSString * const kStatHotelLocation = @"hotel_location"; static NSString * const kStatImport = @"Import"; static NSString * const kStatIn = @"In"; +static NSString * const kStatInappBannerClose = @"Placepage_Banner_close"; +static NSString * const kStatInappCancel = @"InAppPurchase_Preview_cancel"; +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 kStatInappSelect = @"InAppPurchase_Preview_select"; +static NSString * const kStatInappShow = @"InAppPurchase_Preview_show"; +static NSString * const kStatInappValidationSuccess = @"InAppPurchase_Validation_success"; +static NSString * const kStatInappValidationError = @"InAppPurchase_Validation_error"; static NSString * const kStatInvalidCall = @"invalid_call"; static NSString * const kStatIsAuthenticated = @"is_authenticated"; static NSString * const kStatIsAuto = @"is_auto"; @@ -255,6 +265,7 @@ static NSString * const kStatPortrait = @"Portrait"; static NSString * const kStatPosition = @"position"; static NSString * const kStatPriceCategory = @"price_category"; static NSString * const kStatProblem = @"Problem"; +static NSString * const kStatProduct = @"product"; static NSString * const kStatProfile = @"Profile"; static NSString * const kStatProgress = @"Progress"; static NSString * const kStatProvider = @"Provider"; @@ -376,6 +387,7 @@ static NSString * const kStatUpdateAll = @"update_all"; static NSString * const kStatUserInterrupted = @"user_interrupted"; static NSString * const kStatValue = @"Value"; static NSString * const kStatVehicle = @"Vehicle"; +static NSString * const kStatVendor = @"vendor"; static NSString * const kStatViator = @"Viator.com"; static NSString * const kStatVisible = @"Visible"; static NSString * const kStatWhatsNew = @"What's New"; @@ -386,6 +398,7 @@ static NSString * const kStatZoom = @"Zoom"; static NSString * const kStatiPad = @"iPad"; static NSString * const kStatiPhone = @"iPhone"; + static inline NSString * const kStatEventName(NSString * component, NSString * action) { return [NSString stringWithFormat:@"%@ %@", component, action]; diff --git a/iphone/Maps/Core/Subscriptions/MWMPurchaseManager.h b/iphone/Maps/Core/Subscriptions/MWMPurchaseManager.h index fe1e2f3a12..4ebd675327 100644 --- a/iphone/Maps/Core/Subscriptions/MWMPurchaseManager.h +++ b/iphone/Maps/Core/Subscriptions/MWMPurchaseManager.h @@ -12,6 +12,7 @@ typedef void (^ValidateReceiptCallback)(NSString * _Nonnull serverId, MWMValidat @interface MWMPurchaseManager : NSObject + (NSString * _Nonnull)adsRemovalServerId; ++ (NSString * _Nonnull)adsRemovalVendorId; + (NSArray * _Nonnull)productIds; + (MWMPurchaseManager * _Nonnull)sharedManager; diff --git a/iphone/Maps/Core/Subscriptions/MWMPurchaseManager.mm b/iphone/Maps/Core/Subscriptions/MWMPurchaseManager.mm index 1f89c53153..929cd7d68d 100644 --- a/iphone/Maps/Core/Subscriptions/MWMPurchaseManager.mm +++ b/iphone/Maps/Core/Subscriptions/MWMPurchaseManager.mm @@ -21,6 +21,11 @@ return @(ADS_REMOVAL_SERVER_ID); } ++ (NSString *)adsRemovalVendorId +{ + return @(ADS_REMOVAL_VENDOR); +} + + (NSArray *)productIds { return @[@(ADS_REMOVAL_WEEKLY_PRODUCT_ID), diff --git a/iphone/Maps/Core/Subscriptions/SubscriptionManager.swift b/iphone/Maps/Core/Subscriptions/SubscriptionManager.swift index e6b8862a21..fe729ed189 100644 --- a/iphone/Maps/Core/Subscriptions/SubscriptionManager.swift +++ b/iphone/Maps/Core/Subscriptions/SubscriptionManager.swift @@ -57,8 +57,16 @@ class SubscriptionManager: NSObject { MWMPurchaseManager.shared() .validateReceipt(MWMPurchaseManager.adsRemovalServerId()) { (serverId, validationResult) in if validationResult == .error { + Statistics.logEvent(kStatInappValidationError, withParameters: [kStatErrorCode : 2]) return } else { + if validationResult == .valid { + Statistics.logEvent(kStatInappValidationSuccess) + Statistics.logEvent(kStatInappProductDelivered, + withParameters: [kStatVendor : MWMPurchaseManager.adsRemovalVendorId()]) + } else { + Statistics.logEvent(kStatInappValidationError, withParameters: [kStatErrorCode : 0]) + } MWMPurchaseManager.shared().setAdsDisabled(validationResult == .valid) self.paymentQueue.transactions .filter { $0.transactionState == .purchased || $0.transactionState == .restored } @@ -70,6 +78,8 @@ class SubscriptionManager: NSObject { extension SubscriptionManager: SKProductsRequestDelegate { func request(_ request: SKRequest, didFailWithError error: Error) { + Statistics.logEvent(kStatInappPaymentError, + withParameters: [kStatError : error.localizedDescription]) subscriptionsComplection?(nil, error) subscriptionsComplection = nil productsRequest = nil @@ -121,6 +131,7 @@ extension SubscriptionManager: SKPaymentTransactionObserver { MWMPurchaseManager.shared().setAdsDisabled(true) paymentQueue.finishTransaction(transaction) if let ps = pendingSubscription, transaction.payment.productIdentifier == ps.productId { + Statistics.logEvent(kStatInappPaymentSuccess) listeners.allObjects.forEach { $0.didSubsribe(ps) } } } @@ -136,6 +147,8 @@ extension SubscriptionManager: SKPaymentTransactionObserver { private func processFailed(_ transaction: SKPaymentTransaction, error: Error?) { paymentQueue.finishTransaction(transaction) if let ps = pendingSubscription, transaction.payment.productIdentifier == ps.productId { + Statistics.logEvent(kStatInappPaymentError, + withParameters: [kStatError : error?.localizedDescription ?? ""]) listeners.allObjects.forEach { $0.didFailToSubscribe(ps, error: error) } } } diff --git a/iphone/Maps/UI/Ads/AdBanner.swift b/iphone/Maps/UI/Ads/AdBanner.swift index 3b4726bc40..d1abe353ab 100644 --- a/iphone/Maps/UI/Ads/AdBanner.swift +++ b/iphone/Maps/UI/Ads/AdBanner.swift @@ -139,7 +139,10 @@ final class AdBanner: UITableViewCell { } @IBAction - private func removeAction() { + private func removeAction(_ sender: UIButton) { + Statistics.logEvent(kStatInappBannerClose, withParameters: [ + kStatBanner : state == .detailed ? 1 : 0, + kStatButton : sender == removeAdsLargeButton ? 1 : 0]) onRemoveAds?() } diff --git a/iphone/Maps/UI/Ads/AdBanner.xib b/iphone/Maps/UI/Ads/AdBanner.xib index e54e6c4970..1617ca02aa 100644 --- a/iphone/Maps/UI/Ads/AdBanner.xib +++ b/iphone/Maps/UI/Ads/AdBanner.xib @@ -146,7 +146,7 @@ - + diff --git a/iphone/Maps/UI/Ads/RemoveAdsViewController.swift b/iphone/Maps/UI/Ads/RemoveAdsViewController.swift index 173522558d..ba3b6df8a1 100644 --- a/iphone/Maps/UI/Ads/RemoveAdsViewController.swift +++ b/iphone/Maps/UI/Ads/RemoveAdsViewController.swift @@ -95,6 +95,8 @@ 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) + Statistics.logEvent(kStatInappShow, withParameters: [kStatVendor : MWMPurchaseManager.adsRemovalVendorId(), + kStatProduct : subscriptions[0].productId]) } } @@ -107,6 +109,7 @@ } @IBAction func onClose(_ sender: Any) { + Statistics.logEvent(kStatInappCancel) delegate?.didCancelSubscribtion(self) } @@ -147,6 +150,8 @@ self.delegate?.didCancelSubscribtion(self) return } + Statistics.logEvent(kStatInappSelect, withParameters: [kStatProduct : subscription.productId]) + Statistics.logEvent(kStatInappPay) showPurchaseProgress() SubscriptionManager.shared.subscribe(to: subscription) }