diff --git a/Package.resolved b/Package.resolved index 319773e..6cf82b7 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,14 +1,5 @@ { "pins" : [ - { - "identity" : "analytics-swift-mixpanel", - "kind" : "remoteSourceControl", - "location" : "https://github.com/segment-integrations/analytics-swift-mixpanel", - "state" : { - "revision" : "bc6a9628af225e679a581cc9ac2316eaf42f23a8", - "version" : "1.1.7" - } - }, { "identity" : "jsonsafeencoding-swift", "kind" : "remoteSourceControl", @@ -18,15 +9,6 @@ "version" : "2.0.0" } }, - { - "identity" : "mixpanel-swift", - "kind" : "remoteSourceControl", - "location" : "https://github.com/mixpanel/mixpanel-swift", - "state" : { - "revision" : "48d6668ceaaefc338f94e2b084c3cf77b90182f8", - "version" : "4.3.0" - } - }, { "identity" : "sovran-swift", "kind" : "remoteSourceControl", diff --git a/Sources/Segment/Events.swift b/Sources/Segment/Events.swift index 77c5db5..c769848 100644 --- a/Sources/Segment/Events.swift +++ b/Sources/Segment/Events.swift @@ -141,6 +141,26 @@ extension Analytics { // MARK: - Untyped Event Signatures extension Analytics { + /// Tracks an event performed by a user, including some additional event properties. + /// - Parameters: + /// - messageId: The unique identifier for the TrackEvent + /// - name: Name of the action, e.g., 'Purchased a T-Shirt' + /// - properties: A dictionary or properties specific to the named event. + /// For example, an event with the name 'Purchased a Shirt' might have properties + /// like revenue or size. + public func track(messageId: String, name: String, properties: [String: Any]? = nil) { + var props: JSON? = nil + if let properties = properties { + do { + props = try JSON(properties) + } catch { + reportInternalError(error, fatal: true) + } + } + let event = TrackEvent(messageId: messageId, event: name, properties: props) + process(incomingEvent: event) + } + /// Tracks an event performed by a user, including some additional event properties. /// - Parameters: /// - name: Name of the action, e.g., 'Purchased a T-Shirt' diff --git a/Sources/Segment/Types.swift b/Sources/Segment/Types.swift index 549d0cf..ce6ce96 100644 --- a/Sources/Segment/Types.swift +++ b/Sources/Segment/Types.swift @@ -47,7 +47,8 @@ public struct TrackEvent: RawEvent { public var event: String public var properties: JSON? - public init(event: String, properties: JSON?) { + public init(messageId: String? = nil, event: String, properties: JSON?) { + self.messageId = messageId self.event = event self.properties = properties } @@ -303,7 +304,7 @@ extension RawEvent { result.enrichments = enrichments result.anonymousId = userInfo.anonymousId result.userId = userInfo.userId - result.messageId = UUID().uuidString + result.messageId = result.messageId ?? UUID().uuidString result.timestamp = Date().iso8601() result.integrations = try? JSON([String: Any]()) result._metadata = DestinationMetadata()