@@ -24,6 +24,9 @@ public class Analytics {
24
24
25
25
public var timeline : Timeline
26
26
27
+ /// Initialize this instance of Analytics with a given configuration setup.
28
+ /// - Parameters:
29
+ /// - configuration: The configuration to use
27
30
public init ( configuration: Configuration ) {
28
31
self . configuration = configuration
29
32
@@ -44,6 +47,9 @@ public class Analytics {
44
47
_ = timeline. process ( incomingEvent: event)
45
48
}
46
49
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.
47
53
public func process( event: RawEvent ) {
48
54
switch event {
49
55
case let e as TrackEvent :
@@ -65,27 +71,32 @@ public class Analytics {
65
71
// MARK: - System Modifiers
66
72
67
73
extension Analytics {
74
+ /// Returns the anonymousId currently in use.
68
75
public var anonymousId : String {
69
76
if let userInfo: UserInfo = store. currentState ( ) {
70
77
return userInfo. anonymousId
71
78
}
72
79
return " "
73
80
}
74
81
82
+ /// Returns the userId that was specified in the last identify call.
75
83
public var userId : String ? {
76
84
if let userInfo: UserInfo = store. currentState ( ) {
77
85
return userInfo. userId
78
86
}
79
87
return nil
80
88
}
81
89
90
+ /// Returns the traits that were specified in the last identify call.
82
91
public func traits< T: Codable > ( ) -> T ? {
83
92
if let userInfo: UserInfo = store. currentState ( ) {
84
93
return userInfo. traits? . codableValue ( )
85
94
}
86
95
return nil
87
96
}
88
97
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.
89
100
public func flush( ) {
90
101
apply { plugin in
91
102
if let p = plugin as? EventPlugin {
@@ -94,6 +105,8 @@ extension Analytics {
94
105
}
95
106
}
96
107
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.
97
110
public func reset( ) {
98
111
store. dispatch ( action: UserInfo . ResetAction ( ) )
99
112
apply { plugin in
@@ -103,6 +116,22 @@ extension Analytics {
103
116
}
104
117
}
105
118
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.
106
135
public func settings( ) -> Settings ? {
107
136
var settings : Settings ?
108
137
if let system: System = store. currentState ( ) {
@@ -111,11 +140,12 @@ extension Analytics {
111
140
return settings
112
141
}
113
142
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 ) )
120
149
}
150
+
121
151
}
0 commit comments