diff --git a/Core/Pixel.swift b/Core/Pixel.swift index 0434329098..ffe7b063cc 100644 --- a/Core/Pixel.swift +++ b/Core/Pixel.swift @@ -166,6 +166,8 @@ public struct PixelParameters { public static let appState = "state" public static let appEvent = "event" + + public static let didCallWillEnterForeground = "didCallWillEnterForeground" } public struct PixelValues { diff --git a/Core/PixelEvent.swift b/Core/PixelEvent.swift index cc50325dc0..fe7fbcd154 100644 --- a/Core/PixelEvent.swift +++ b/Core/PixelEvent.swift @@ -974,6 +974,8 @@ extension Pixel { // MARK: Lifecycle case appDidTransitionToUnexpectedState + case appDidConsecutivelyBackground + } } @@ -1945,6 +1947,7 @@ extension Pixel.Event { // MARK: Lifecycle case .appDidTransitionToUnexpectedState: return "m_debug_app-did-transition-to-unexpected-state-2" + case .appDidConsecutivelyBackground: return "m_debug_app-did-consecutively-background-2" } } diff --git a/DuckDuckGo/AppDelegate.swift b/DuckDuckGo/AppDelegate.swift index 2f420be64f..64f735503f 100644 --- a/DuckDuckGo/AppDelegate.swift +++ b/DuckDuckGo/AppDelegate.swift @@ -67,6 +67,8 @@ protocol DDGApp { } }() + var didCallWillEnterForeground: Bool = false + override init() { super.init() realDelegate.initialize() @@ -77,6 +79,7 @@ protocol DDGApp { } func applicationDidBecomeActive(_ application: UIApplication) { + didCallWillEnterForeground = false realDelegate.applicationDidBecomeActive?(application) } @@ -85,6 +88,7 @@ protocol DDGApp { } func applicationWillEnterForeground(_ application: UIApplication) { + didCallWillEnterForeground = true realDelegate.applicationWillEnterForeground?(application) } diff --git a/DuckDuckGo/AppLifecycle/AppStateTransitions.swift b/DuckDuckGo/AppLifecycle/AppStateTransitions.swift index 1d6fe1e89a..d3213f7884 100644 --- a/DuckDuckGo/AppLifecycle/AppStateTransitions.swift +++ b/DuckDuckGo/AppLifecycle/AppStateTransitions.swift @@ -104,6 +104,12 @@ extension Background { urlToOpen = url return self case .backgrounding: + if let appDelegate = UIApplication.shared.delegate as? AppDelegate { + Pixel.fire(pixel: .appDidConsecutivelyBackground, withAdditionalParameters: [ + PixelParameters.didCallWillEnterForeground: appDelegate.didCallWillEnterForeground.description + ]) + appDelegate.didCallWillEnterForeground = false + } run() return self case .handleShortcutItem(let shortcutItem):