Skip to content

Commit 417c6f3

Browse files
committed
Overloaded track function injection
1 parent 59ae167 commit 417c6f3

File tree

3 files changed

+23
-20
lines changed

3 files changed

+23
-20
lines changed

Package.resolved

-18
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
{
22
"pins" : [
3-
{
4-
"identity" : "analytics-swift-mixpanel",
5-
"kind" : "remoteSourceControl",
6-
"location" : "https://github.com/segment-integrations/analytics-swift-mixpanel",
7-
"state" : {
8-
"revision" : "bc6a9628af225e679a581cc9ac2316eaf42f23a8",
9-
"version" : "1.1.7"
10-
}
11-
},
123
{
134
"identity" : "jsonsafeencoding-swift",
145
"kind" : "remoteSourceControl",
@@ -18,15 +9,6 @@
189
"version" : "2.0.0"
1910
}
2011
},
21-
{
22-
"identity" : "mixpanel-swift",
23-
"kind" : "remoteSourceControl",
24-
"location" : "https://github.com/mixpanel/mixpanel-swift",
25-
"state" : {
26-
"revision" : "48d6668ceaaefc338f94e2b084c3cf77b90182f8",
27-
"version" : "4.3.0"
28-
}
29-
},
3012
{
3113
"identity" : "sovran-swift",
3214
"kind" : "remoteSourceControl",

Sources/Segment/Events.swift

+20
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,26 @@ extension Analytics {
141141
// MARK: - Untyped Event Signatures
142142

143143
extension Analytics {
144+
/// Tracks an event performed by a user, including some additional event properties.
145+
/// - Parameters:
146+
/// - messageId: The unique identifier for the TrackEvent
147+
/// - name: Name of the action, e.g., 'Purchased a T-Shirt'
148+
/// - properties: A dictionary or properties specific to the named event.
149+
/// For example, an event with the name 'Purchased a Shirt' might have properties
150+
/// like revenue or size.
151+
public func track(messageId: String, name: String, properties: [String: Any]? = nil) {
152+
var props: JSON? = nil
153+
if let properties = properties {
154+
do {
155+
props = try JSON(properties)
156+
} catch {
157+
reportInternalError(error, fatal: true)
158+
}
159+
}
160+
let event = TrackEvent(messageId: messageId, event: name, properties: props)
161+
process(incomingEvent: event)
162+
}
163+
144164
/// Tracks an event performed by a user, including some additional event properties.
145165
/// - Parameters:
146166
/// - name: Name of the action, e.g., 'Purchased a T-Shirt'

Sources/Segment/Types.swift

+3-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public struct TrackEvent: RawEvent {
4747
public var event: String
4848
public var properties: JSON?
4949

50-
public init(event: String, properties: JSON?) {
50+
public init(messageId: String? = nil, event: String, properties: JSON?) {
51+
self.messageId = messageId
5152
self.event = event
5253
self.properties = properties
5354
}
@@ -303,7 +304,7 @@ extension RawEvent {
303304
result.enrichments = enrichments
304305
result.anonymousId = userInfo.anonymousId
305306
result.userId = userInfo.userId
306-
result.messageId = UUID().uuidString
307+
result.messageId = result.messageId ?? UUID().uuidString
307308
result.timestamp = Date().iso8601()
308309
result.integrations = try? JSON([String: Any]())
309310
result._metadata = DestinationMetadata()

0 commit comments

Comments
 (0)