Commit e26369f0 by Dmitry Stepanets

[IOS-287]: Finished appear logic, added instrumentation

parent b49a5aba
......@@ -145,6 +145,7 @@ class AppCoordinator: Coordinator {
//Search the TodayCoordinator
let todayCoordinator = (self.childCoordinators.first{ $0 is TodayCoordinator } as? TodayCoordinator)
todayCoordinator?.showOnboardingOrPrivacyNoticeIfNeeded()
self.showPremiumNudgeIfNeeded()
})
}
}
......@@ -207,6 +208,30 @@ class AppCoordinator: Coordinator {
tabBarController.updateTabs()
}
private func openSubscriptionStorePopUp() {
let subscriptionCoordinator = SubscriptionCoordinator(parentViewController: tabBarController)
subscriptionCoordinator.parentCoordinator = self
childCoordinators.append(subscriptionCoordinator)
subscriptionCoordinator.startPopUp()
AppAnalytics.shared.log(event: .ANALYTICS_PREMIUM_NUDGE_VIEW)
}
private func showPremiumNudgeIfNeeded() {
let appLaunchCount = Settings.shared.appLaunchCount
let currentAttemptsCount = Settings.shared.premiumNudgeAttempstCount
let totalAttempts = ConfigManager.shared.config.premiumNudgeTotalTimes
let sessionCount = ConfigManager.shared.config.premiumNudgeSessionShowing
guard appLaunchCount > 1 && currentAttemptsCount < totalAttempts && !StoreManager.shared.hasSubscription else {
return
}
if appLaunchCount % sessionCount == 0 {
Settings.shared.premiumNudgeAttempstCount += 1
self.openSubscriptionStorePopUp()
}
}
func viewControllerDidEnd(controller: UIViewController) {
//do nothing
}
......
......@@ -16,7 +16,6 @@ class TodayCoordinator: Coordinator {
// MARK: - Private
private let navigationController = ColoredNavigationController(nibName: nil, bundle: nil)
private var tabBarController: UITabBarController?
private var waitingForConfig = true
var todayViewController: TodayViewController?
// MARK: - Public
......@@ -36,11 +35,6 @@ class TodayCoordinator: Coordinator {
}
navigationController.viewControllers = [todayViewController]
tabBarController?.add(viewController: navigationController)
ConfigManager.shared.add(delegate: self)
if waitingForConfig == false {
showPremiumNudgeIfNeeded()
}
}
public func showOnboardingOrPrivacyNoticeIfNeeded() {
......@@ -110,32 +104,4 @@ class TodayCoordinator: Coordinator {
}
}
}
public func showPremiumNudgeIfNeeded() {
guard tabBarController?.viewControllers?.isEmpty == false else {
return
}
let appLaunchCount = Settings.shared.appLaunchCount
let currentAttemptsCount = Settings.shared.premiumNudgeAttempstCount
let totalAttempts = ConfigManager.shared.config.premiumNudgeTotalTimes
let sessionCount = ConfigManager.shared.config.premiumNudgeSessionShowing
guard appLaunchCount != 0 && currentAttemptsCount <= totalAttempts && !StoreManager.shared.hasSubscription else {
return
}
if appLaunchCount % sessionCount == 0 {
Settings.shared.premiumNudgeAttempstCount += 1
self.openSubscriptionStorePopUp()
}
}
}
//MARK: - ConfigManager Delegate
extension TodayCoordinator: ConfigManagerDelegate {
func dataUpdated(by configManager: ConfigManager) {
waitingForConfig = false
showPremiumNudgeIfNeeded()
}
}
......@@ -43,6 +43,11 @@ class SubscriptionPopUpViewController: UIViewController {
Settings.shared.initialSubscriptionShown = true
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
AppAnalytics.shared.log(event: .ANALYTICS_PREMIUM_NUDGE_CLOSE)
}
}
private extension SubscriptionPopUpViewController {
......
......@@ -131,6 +131,7 @@ private extension SubscriptionStoreViewController {
}
}
//MARK: - Header Delegate
extension SubscriptionStoreViewController: SubscriptionTopViewDelegate {
func handleCloseButton() {
self.dismiss(animated: true)
......
......@@ -147,6 +147,8 @@ public enum AnalyticsEvent: String {
case ANALYTICS_SUBSCRIPTION_UPGRADE_MONTHLY_CLICK = "UPGRADE_MONTHLY_CLICK"
case ANALYTICS_SUBSCRIPTION_VIEW_PREMIUM_SUCCESS = "VIEW_PREMIUM_SUCCESS"
case ANALYTICS_SUBSCRIPTION_PREMIUM_HAMBURGER_CLICK = "PREMIUM_HAMBURGER_CLICK"
case ANALYTICS_PREMIUM_NUDGE_VIEW = "VIEW_PREMIUM_NUDGE"
case ANALYTICS_PREMIUM_NUDGE_CLOSE = "CLOSE_PREMIUM_NUDGE"
// MARK: Minutely
case ANALYTICS_MINUTELY_PRECIP_TODAY_SEEN = "MINUTELY_PRECIP_TODAY_SEEN"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment