@@ -24,6 +24,9 @@ public class Analytics {
2424
2525 public var timeline : Timeline
2626
27+ /// Initialize this instance of Analytics with a given configuration setup.
28+ /// - Parameters:
29+ /// - configuration: The configuration to use
2730 public init ( configuration: Configuration ) {
2831 self . configuration = configuration
2932
@@ -44,6 +47,9 @@ public class Analytics {
4447 _ = timeline. process ( incomingEvent: event)
4548 }
4649
50+ /// Process a raw event through the system. Useful when one needs to queue and replay events at a later time.
51+ /// - Parameters:
52+ /// - event: An event conforming to RawEvent that will be processed.
4753 public func process( event: RawEvent ) {
4854 switch event {
4955 case let e as TrackEvent :
@@ -65,27 +71,32 @@ public class Analytics {
6571// MARK: - System Modifiers
6672
6773extension Analytics {
74+ /// Returns the anonymousId currently in use.
6875 public var anonymousId : String {
6976 if let userInfo: UserInfo = store. currentState ( ) {
7077 return userInfo. anonymousId
7178 }
7279 return " "
7380 }
7481
82+ /// Returns the userId that was specified in the last identify call.
7583 public var userId : String ? {
7684 if let userInfo: UserInfo = store. currentState ( ) {
7785 return userInfo. userId
7886 }
7987 return nil
8088 }
8189
90+ /// Returns the traits that were specified in the last identify call.
8291 public func traits< T: Codable > ( ) -> T ? {
8392 if let userInfo: UserInfo = store. currentState ( ) {
8493 return userInfo. traits? . codableValue ( )
8594 }
8695 return nil
8796 }
8897
98+ /// Tells this instance of Analytics to flush any queued events up to Segment.com. This command will also
99+ /// be sent to each plugin present in the system.
89100 public func flush( ) {
90101 apply { plugin in
91102 if let p = plugin as? EventPlugin {
@@ -94,6 +105,8 @@ extension Analytics {
94105 }
95106 }
96107
108+ /// Resets this instance of Analytics to a clean slate. Traits, UserID's, anonymousId, etc are all cleared or reset. This
109+ /// command will also be sent to each plugin present in the system.
97110 public func reset( ) {
98111 store. dispatch ( action: UserInfo . ResetAction ( ) )
99112 apply { plugin in
@@ -103,6 +116,22 @@ extension Analytics {
103116 }
104117 }
105118
119+ /// Retrieve the version of this library in use.
120+ /// - Returns: A string representing the version in "BREAKING.FEATURE.FIX" format.
121+ public func version( ) -> String {
122+ return Analytics . version ( )
123+ }
124+
125+ /// Retrieve the version of this library in use.
126+ /// - Returns: A string representing the version in "BREAKING.FEATURE.FIX" format.
127+ public static func version( ) -> String {
128+ return __segment_version
129+ }
130+ }
131+
132+ extension Analytics {
133+ /// Manually retrieve the settings that were supplied from Segment.com.
134+ /// - Returns: A Settings object containing integration settings, tracking plan, etc.
106135 public func settings( ) -> Settings ? {
107136 var settings : Settings ?
108137 if let system: System = store. currentState ( ) {
@@ -111,11 +140,12 @@ extension Analytics {
111140 return settings
112141 }
113142
114- public func version ( ) -> String {
115- return Analytics . version ( )
116- }
117-
118- public static func version ( ) -> String {
119- return __segment_version
143+ /// Manually enable a destination plugin. This is useful when a given DestinationPlugin doesn't have any Segment tie-ins at all.
144+ /// This will allow the destination to be processed in the same way within this library.
145+ /// - Parameters:
146+ /// - plugin: The destination plugin to enable.
147+ public func manuallyEnableDestination ( plugin : DestinationPlugin ) {
148+ self . store . dispatch ( action : System . AddDestinationToSettingsAction ( key : plugin . key ) )
120149 }
150+
121151}
0 commit comments