Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pixel to check if in between double background willEnterForeground is called #3788

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 static let appState = "state"
public static let appEvent = "event"

public static let didCallWillEnterForeground = "didCallWillEnterForeground"
}

public struct PixelValues {
Expand Down Expand Up @@ -273,7 +275,7 @@
allowedQueryReservedCharacters: allowedQueryReservedCharacters,
headers: headers)
let request = APIRequest(configuration: configuration, urlSession: .session(useMainThreadCallbackQueue: true))
request.fetch { _, error in

Check warning on line 278 in Core/Pixel.swift

View workflow job for this annotation

GitHub Actions / Make Release Build

'fetch(completion:)' is deprecated: Please use 'APIService' instead.

Check warning on line 278 in Core/Pixel.swift

View workflow job for this annotation

GitHub Actions / Make Release Build

'fetch(completion:)' is deprecated: Please use 'APIService' instead.

Check warning on line 278 in Core/Pixel.swift

View workflow job for this annotation

GitHub Actions / Unit Tests

'fetch(completion:)' is deprecated: Please use 'APIService' instead.
Logger.general.debug("Pixel fired \(pixelName, privacy: .public) \(params, privacy: .public)")
onComplete(error)
}
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
Loading