Swift: Analytics and performance
Log events and screen views for active users, funnels and retention, and report app start, screen and network timings with the Swift SDK.
Log events and screen views for active users, funnels and retention, and report app start, screen and network timings. Every call runs as the client's signed-in user, so your project's policies and row-level security apply. Types and members are listed in source order; each one links to its HTTP endpoint where it maps to one.
#Types and members
SovariaAnalytics
Product analytics: sovaria.analytics.track("purchase", ["amount": 20]), screen("Home"), identify(["plan": "pro"]), and setEnabled(false) when the user opts out (the server then drops their events on every device). Events are batched (every 10 s or 20 events), kept in the offline store while offline, and the signed-in user comes from the request's token on the server, never from the event.
public final class SovariaAnalytics: @unchecked SendableSovariaAnalytics.appVersion
A property.
public var appVersion: String?SovariaAnalytics.platform
A property.
public var platformSovariaAnalytics.batchSize
A property.
public var batchSizeSovariaAnalytics.flushInterval
A property.
public var flushInterval: TimeIntervalSovariaAnalytics.anonId
The device id sent as anon_id.
public var anonId: StringSovariaAnalytics.configure
Persist the queue, device id and opt-out (pass the same store as offline documents, or a FileOfflineStore).
public func configure(store: OfflineStore?, appVersion: String? = nil, platform: String? = nil) asyncSovariaAnalytics.track
public func track(_ name: String, _ props: [String: Any] = [:]) -> BoolSovariaAnalytics.screen
public func screen(_ name: String, _ props: [String: Any] = [:]) -> BoolSovariaAnalytics.identify
public func identify(_ userProps: [String: Any]) -> BoolSovariaAnalytics.trackExposure
One $exposure per experiment and session (remote config calls this when you read an experiment's value).
public func trackExposure(experiment: String, variant: String)SovariaAnalytics.flush
Send what is queued now.
public func flush() asyncNetwork errors and throttling keep the events; a refused batch is dropped.
SovariaAnalytics.setEnabled
Analytics consent for this user (DPDP / GDPR).
public func setEnabled(_ on: Bool, erase: Bool = false) async throwsOff clears the queue and tells the server; erase also deletes what was stored.
SovariaAnalytics.isEnabled
A property.
public var isEnabled: BoolSovariaAnalytics.pending
A property.
public var pending: IntSovariaRemoteConfig
Remote config and feature flags: setDefaults, fetchAndActivate(), bool/string/number/json(_:) and onUpdate (live after a publish when the plan has realtime config). Only this user's evaluated values come back (never the rules); unchanged config costs a 304; activated values persist for offline starts.
public final class SovariaRemoteConfig: @unchecked SendableSovariaRemoteConfig.minimumFetchInterval
A property.
public var minimumFetchInterval: TimeIntervalSovariaRemoteConfig.attributes
A property.
public var attributes: [String: Any]SovariaRemoteConfig.appVersion
A property.
public var appVersion: String?SovariaRemoteConfig.platform
A property.
public var platformSovariaRemoteConfig.language
A property.
public var language: String?SovariaRemoteConfig.setDefaults
public func setDefaults(_ values: [String: Any])SovariaRemoteConfig.configure
Restore the last activated values (call early with a durable store).
public func configure(store: OfflineStore?) asyncSovariaRemoteConfig.fetchAndActivate
Fetch (respecting minimumFetchInterval unless force) and activate.
public func fetchAndActivate(force: Bool = false) async -> BoolTrue when values changed.
SovariaRemoteConfig.onUpdate
Called with the changed keys whenever new values are activated.
public func onUpdate(_ cb: @escaping @Sendable ([String]) -> Void) -> UUIDReturns a token for removeUpdateListener.
SovariaRemoteConfig.removeUpdateListener
public func removeUpdateListener(_ id: UUID)SovariaRemoteConfig.bool
public func bool(_ key: String, default fallback: Bool = false) -> BoolSovariaRemoteConfig.string
public func string(_ key: String, default fallback: String = "") -> StringSovariaRemoteConfig.number
public func number(_ key: String, default fallback: Double = 0) -> DoubleSovariaRemoteConfig.json
public func json(_ key: String) -> Any?SovariaRemoteConfig.version
A property.
public var version: IntSovariaPerf
Client performance monitoring (Observability › Performance in the console):
- App start — cold start from process launch to the first time the app becomes active (iOS, automatic), or to your own markAppReady() call. - Screens — let t = sov.perf.screen("Checkout") … t.end() (or the SwiftUI .sovariaScreen("Checkout") modifier): time on screen. - Network — every request the SDK makes (method, route, status, duration), with the traceparent it sent, so a slow call opens the server trace for the same request. - Custom traces — try await sov.perf.trace("sync") { … }.
Measurements are batched every 10 s (at most 100 per request) and count against obs.perf_events_month.
public final class SovariaPerf: @unchecked SendableSovariaPerf.install
public func install(release: String? = nil, environment: String? = nil, sampleRate: Double = 1, network: Bool = true,
appStart: Bool = true)SovariaPerf.uninstall
public func uninstall()SovariaPerf.markAppReady
The app is ready (first screen drawn): records the cold start once per launch.
public func markAppReady()SovariaPerf.screen
Start timing a screen; call end() when it goes away.
public func screen(_ name: String) -> PerfTraceSovariaPerf.trace
Time an async block as a custom trace (also when it throws).
public func trace<T>(_ name: String, attributes: [String: Any] = [:], _ body: () async throws -> T) async rethrows -> TSovariaPerf.record
Queue one measurement.
public func record(kind: String, name: String, value: Double, route: String? = nil, traceId: String? = nil,
attributes: [String: Any] = [:]) -> BoolReturns false when not installed or not sampled.
SovariaPerf.flush
Send queued measurements now.
public func flush() asyncPerfTrace
A running screen or custom trace; end() records it once.
public final class PerfTrace: @unchecked SendablePerfTrace.end
public func end()