From 417c6f3d38912d23f2cf8427794217a4462c0db9 Mon Sep 17 00:00:00 2001
From: Anton Shepetuha <antonshepetuha@gmail.com>
Date: Fri, 21 Feb 2025 13:26:23 +0200
Subject: [PATCH] Overloaded track function injection

---
 Package.resolved             | 18 ------------------
 Sources/Segment/Events.swift | 20 ++++++++++++++++++++
 Sources/Segment/Types.swift  |  5 +++--
 3 files changed, 23 insertions(+), 20 deletions(-)

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()