@@ -224,3 +224,57 @@ extension Analytics {
224224 process ( incomingEvent: event)
225225 }
226226}
227+
228+ // MARK: - Enrichment event signatures
229+
230+ extension Analytics {
231+ // Tracks an event performed by a user, including some additional event properties.
232+ /// - Parameters:
233+ /// - name: Name of the action, e.g., 'Purchased a T-Shirt'
234+ /// - properties: Properties specific to the named event. For example, an event with
235+ /// the name 'Purchased a Shirt' might have properties like revenue or size.
236+ /// - enrichments: Enrichments to be applied to this specific event only, or `nil` for none.
237+ public func track< P: Codable > ( name: String , properties: P ? , enrichments: [ EnrichmentClosure ] ? ) {
238+ do {
239+ if let properties = properties {
240+ let jsonProperties = try JSON ( with: properties)
241+ let event = TrackEvent ( event: name, properties: jsonProperties)
242+ process ( incomingEvent: event, enrichments: enrichments)
243+ } else {
244+ let event = TrackEvent ( event: name, properties: nil )
245+ process ( incomingEvent: event, enrichments: enrichments)
246+ }
247+ } catch {
248+ reportInternalError ( error, fatal: true )
249+ }
250+ }
251+
252+ /// Tracks an event performed by a user.
253+ /// - Parameters:
254+ /// - name: Name of the action, e.g., 'Purchased a T-Shirt'
255+ /// - enrichments: Enrichments to be applied to this specific event only, or `nil` for none.
256+ public func track( name: String , enrichments: [ EnrichmentClosure ] ? ) {
257+ track ( name: name, properties: nil as TrackEvent ? , enrichments: enrichments)
258+ }
259+
260+ /// Tracks an event performed by a user, including some additional event properties.
261+ /// - Parameters:
262+ /// - name: Name of the action, e.g., 'Purchased a T-Shirt'
263+ /// - properties: A dictionary or properties specific to the named event.
264+ /// For example, an event with the name 'Purchased a Shirt' might have properties
265+ /// like revenue or size.
266+ /// - enrichments: Enrichments to be applied to this specific event only, or `nil` for none.
267+ public func track( name: String , properties: [ String : Any ] ? , enrichments: [ EnrichmentClosure ] ? ) {
268+ var props : JSON ? = nil
269+ if let properties = properties {
270+ do {
271+ props = try JSON ( properties)
272+ } catch {
273+ reportInternalError ( error, fatal: true )
274+ }
275+ }
276+ let event = TrackEvent ( event: name, properties: props)
277+ process ( incomingEvent: event, enrichments: enrichments)
278+ }
279+
280+ }
0 commit comments