Skip to content

Commit

Permalink
Add pixel to check if in between double background willEnterForegroun…
Browse files Browse the repository at this point in the history
…d is called
  • Loading branch information
jaceklyp committed Jan 10, 2025
1 parent faa179b commit 5740f12
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Core/Pixel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions Core/PixelEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,8 @@ extension Pixel {

// MARK: Lifecycle
case appDidTransitionToUnexpectedState
case appDidConsecutivelyBackground

}

}
Expand Down Expand Up @@ -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"

}
}
Expand Down
4 changes: 4 additions & 0 deletions DuckDuckGo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ protocol DDGApp {
}
}()

var didCallWillEnterForeground: Bool = false

override init() {
super.init()
realDelegate.initialize()
Expand All @@ -77,6 +79,7 @@ protocol DDGApp {
}

func applicationDidBecomeActive(_ application: UIApplication) {
didCallWillEnterForeground = false
realDelegate.applicationDidBecomeActive?(application)
}

Expand All @@ -85,6 +88,7 @@ protocol DDGApp {
}

func applicationWillEnterForeground(_ application: UIApplication) {
didCallWillEnterForeground = true
realDelegate.applicationWillEnterForeground?(application)
}

Expand Down
6 changes: 6 additions & 0 deletions DuckDuckGo/AppLifecycle/AppStateTransitions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 5740f12

Please sign in to comment.