Skip to content

Commit

Permalink
Remove an array of consecutive backgrounds, keep just 2 but add counter
Browse files Browse the repository at this point in the history
  • Loading branch information
jaceklyp committed Dec 19, 2024
1 parent 5ef686f commit 5f77eec
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
3 changes: 2 additions & 1 deletion Core/Pixel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,13 @@ public struct PixelParameters {
public static let appEvent = "event"

public static let firstBackgroundTimestamp = "firstBackgroundTimestamp"
public static let consecutiveBackgroundTimestamps = "consecutiveBackgroundTimestamps"
public static let secondBackgroundTimestamp = "secondBackgroundTimestamp"
public static let didReceiveMemoryWarningTimestamp = "didReceiveMemoryWarningTimestamp"
public static let didReceiveMXPayloadTimestamp = "didReceiveMXPayloadTimestamp"
public static let didReceiveUNNotification = "didReceiveUNNotification"
public static let didStartRemoteMessagingClientBackgroundTask = "didStartRemoteMessagingClientBackgroundTask"
public static let didStartAppConfigurationFetchBackgroundTask = "didStartAppConfigurationFetchBackgroundTask"
public static let numberOfBackgrounds = "numberOfBackgrounds"
}

public struct PixelValues {
Expand Down
4 changes: 2 additions & 2 deletions DuckDuckGo/AppLifecycle/AppStateTransitions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ extension Background {
case .openURL:
return self
case .backgrounding:
return DoubleBackground(firstTimeBackgroundTimestamp: timestamp, consecutiveTimestamps: [])
return DoubleBackground(firstTimeBackgroundTimestamp: timestamp, counter: 0)
case .launching, .suspending:
return handleUnexpectedEvent(event)
}
Expand All @@ -111,7 +111,7 @@ extension DoubleBackground {
case .suspending(let application):
return Inactive(application: application)
case .backgrounding(let application):
return DoubleBackground(firstTimeBackgroundTimestamp: firstTimeBackgroundTimestamp, consecutiveTimestamps: consecutiveTimestamps)
return DoubleBackground(firstTimeBackgroundTimestamp: firstTimeBackgroundTimestamp, counter: counter)
case .launching, .openURL:
return self
}
Expand Down
22 changes: 11 additions & 11 deletions DuckDuckGo/AppLifecycle/AppStates/Background.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@ struct DoubleBackground: AppState {
}()

let firstTimeBackgroundTimestamp: Date
var consecutiveTimestamps: [Date] = []
var counter: Int

init(firstTimeBackgroundTimestamp: Date, consecutiveTimestamps: [Date]) {
self.firstTimeBackgroundTimestamp = firstTimeBackgroundTimestamp
self.consecutiveTimestamps = consecutiveTimestamps
let lastTimestamp = Date()
self.consecutiveTimestamps.append(lastTimestamp)
init(firstTimeBackgroundTimestamp: Date, counter: Int) {
let secondBackgroundTimestamp = Date()
self.firstTimeBackgroundTimestamp = secondBackgroundTimestamp
self.counter = counter + 1

var parameters = [PixelParameters.firstBackgroundTimestamp: dateFormatter.string(from: firstTimeBackgroundTimestamp)]

let formattedConsecutiveTimestamps = consecutiveTimestamps.map { dateFormatter.string(from: $0) }
parameters[PixelParameters.consecutiveBackgroundTimestamps] = formattedConsecutiveTimestamps.joined(separator: ",")
var parameters = [
PixelParameters.firstBackgroundTimestamp: dateFormatter.string(from: firstTimeBackgroundTimestamp),
PixelParameters.secondBackgroundTimestamp: dateFormatter.string(from: secondBackgroundTimestamp),
PixelParameters.numberOfBackgrounds: String(counter)
]

func isValid(timestamp: Date) -> Bool {
timestamp >= firstTimeBackgroundTimestamp && timestamp <= lastTimestamp
timestamp >= firstTimeBackgroundTimestamp && timestamp <= secondBackgroundTimestamp
}

if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
Expand Down

0 comments on commit 5f77eec

Please sign in to comment.