MCPcopy Create free account
hub / github.com/altic-dev/FluidVoice / capture

Method capture

Sources/Fluid/Analytics/AnalyticsService.swift:207–236  ·  view source on GitHub ↗
(eventName: String, distinctID: String, enabled: Bool, config: AnalyticsConfig, properties: [String: Any])

Source from the content-addressed store, hash-verified

205 }
206
207 func capture(
208 eventName: String,
209 distinctID: String,
210 enabled: Bool,
211 config: AnalyticsConfig,
212 properties: [String: Any]
213 ) async {
214 // Use latest values passed by caller to avoid cross-actor UserDefaults reads.
215 self.enabled = enabled
216 self.config = config
217
218 guard self.enabled, self.config.isConfigured else { return }
219
220 var event: [String: Any] = [:]
221 event["event"] = eventName
222 event["timestamp"] = ISO8601DateFormatter().string(from: Date())
223
224 // PostHog expects distinct_id inside properties.
225 var props = properties
226 props["distinct_id"] = distinctID
227 props["$lib"] = "FluidVoice"
228 props["$lib_version"] = "1"
229 event["properties"] = props
230
231 self.enqueue(event)
232
233 if self.queue.count >= self.flushAt {
234 await self.flushIfNeeded()
235 }
236 }
237
238 private func enqueue(_ event: [String: Any]) {
239 self.queue.append(event)

Calls 2

enqueueMethod · 0.95
flushIfNeededMethod · 0.95

Tested by

no test coverage detected