@@ -47,11 +47,53 @@ public enum StorageMode {
4747
4848// MARK: - Internal Configuration
4949
50+ @objc ( SEGTrackedLifecycleEvent)
51+ public final class TrackedLifecycleEvent : NSObject , OptionSet {
52+ public let rawValue : Int
53+
54+ public init ( rawValue: Int ) {
55+ self . rawValue = rawValue
56+ }
57+
58+ @objc public static let none = TrackedLifecycleEvent ( )
59+ @objc public static let applicationInstalled = TrackedLifecycleEvent ( rawValue: 0b00000001 )
60+ @objc public static let applicationUpdated = TrackedLifecycleEvent ( rawValue: 0b00000010 )
61+ @objc public static let applicationOpened = TrackedLifecycleEvent ( rawValue: 0b00000100 )
62+ @objc public static let applicationBackgrounded = TrackedLifecycleEvent ( rawValue: 0b00001000 )
63+ @objc public static let applicationForegrounded = TrackedLifecycleEvent ( rawValue: 0b00010000 )
64+ #if os(macOS)
65+ @objc public static let applicationUnhidden = TrackedLifecycleEvent ( rawValue: 0b00100000 )
66+ @objc public static let applicationHidden = TrackedLifecycleEvent ( rawValue: 0b01000000 )
67+ @objc public static let applicationTerminated = TrackedLifecycleEvent ( rawValue: 0b10000000 )
68+
69+ @objc public static let all = TrackedLifecycleEvent ( [
70+ applicationInstalled,
71+ applicationUpdated,
72+ applicationOpened,
73+ applicationBackgrounded,
74+ applicationForegrounded,
75+ applicationUnhidden,
76+ applicationHidden,
77+ applicationTerminated,
78+ ] )
79+ #elseif os(iOS) || os(tvOS) || os(visionOS) || targetEnvironment(macCatalyst)
80+ @objc public static let all = TrackedLifecycleEvent ( [
81+ applicationInstalled,
82+ applicationUpdated,
83+ applicationOpened,
84+ applicationBackgrounded,
85+ applicationForegrounded,
86+ ] )
87+ #else
88+ @objc public static let all = TrackedLifecycleEvent . none
89+ #endif
90+ }
91+
5092public class Configuration {
5193 internal struct Values {
5294 var writeKey : String
5395 var application : Any ? = nil
54- var trackApplicationLifecycleEvents : Bool = true
96+ var trackedApplicationLifecycleEvents = TrackedLifecycleEvent . all
5597 var flushAt : Int = 20
5698 var flushInterval : TimeInterval = 30
5799 var defaultSettings : Settings ? = nil
@@ -110,8 +152,19 @@ public extension Configuration {
110152 /// - Parameter enabled: A bool value
111153 /// - Returns: The current Configuration.
112154 @discardableResult
155+ @available ( * , deprecated, message: " Use `setTrackedApplicationLifecycleEvents(_:)` for more granular control " )
113156 func trackApplicationLifecycleEvents( _ enabled: Bool ) -> Configuration {
114- values. trackApplicationLifecycleEvents = enabled
157+ values. trackedApplicationLifecycleEvents = enabled ? . all : . none
158+ return self
159+ }
160+
161+ /// Opt-in/out of tracking lifecycle events. The default value is `.none`.
162+ ///
163+ /// - Parameter events: An option set of the events to track.
164+ /// - Returns: The current Configuration.
165+ @discardableResult
166+ func setTrackedApplicationLifecycleEvents( _ events: TrackedLifecycleEvent ) -> Configuration {
167+ values. trackedApplicationLifecycleEvents = events
115168 return self
116169 }
117170
0 commit comments