caelum0x fba4dba792 feat(analytics): native Swift and Kotlin SDKs for product analytics
RailyardAnalytics (Swift package, iOS/macOS/tvOS/watchOS) and
railyard-analytics-kotlin (Android/JVM, stdlib only): capture, screen,
identify with the anonymous-id link, alias, groups, super properties,
feature flags, batched delivery with retry on network errors, 429 and
5xx, bounded queue, persisted ids and reset. Swift: 6 XCTest cases;
Kotlin: 9 checks including a real HTTP round trip, runnable offline with
the Kotlin compiler bundled in Gradle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 18:47:44 +03:00
..

RailyardAnalytics (Swift)

Native iOS, macOS, tvOS and watchOS client for Railyard product analytics. It speaks the service's PostHog-compatible wire protocol (/batch/, /flags/).

import RailyardAnalytics

let analytics = try Analytics(config: AnalyticsConfig(site: "<site key>"))
await analytics.capture("signed_up", properties: ["plan": "pro"])
await analytics.screen("Home")
await analytics.identify("user_42", set: ["email": "ada@example.com"])
await analytics.group("company", key: "acme")
if await analytics.reloadFeatureFlags(), await analytics.isFeatureEnabled("new-ui") { ... }
await analytics.flush()   // also runs every `flushInterval` seconds and at `flushAt` events
await analytics.reset()   // on log out
  • Events queue in memory (bounded by maxQueue) and go out in batches of up to 100. Network errors, 429 and 5xx keep them for the next flush; other 4xx answers drop them.
  • The anonymous id and the identified id persist in UserDefaults (pass MemoryStorage() to keep nothing on disk).
  • Transport is a protocol, so tests and apps can swap the HTTP layer.

Add it with Swift Package Manager (path or git URL of packages/analytics-swift). Run the tests with swift test.