Add analytics to iOS (Swift) iOS (Swift).
iOS analytics means logging screen appearances and taps from your native Swift app. smolanalytics has no iOS SDK. You send events with URLSession to /v1/events, a handful of lines with no dependency to vet or ship. Batch them to spare the battery, then ask your numbers in plain English from the dashboard or your editor.
import Foundation
enum Analytics {
static let host = "https://YOUR-INSTANCE"
static let key = "WRITE_KEY"
static func track(_ name: String, distinctId: String, properties: [String: Any] = [:]) {
var req = URLRequest(url: URL(string: "\(host)/v1/events")!)
req.httpMethod = "POST"
req.setValue("Bearer \(key)", forHTTPHeaderField: "Authorization")
req.setValue("application/json", forHTTPHeaderField: "Content-Type")
req.httpBody = try? JSONSerialization.data(
withJSONObject: ["name": name, "distinct_id": distinctId, "properties": properties])
URLSession.shared.dataTask(with: req).resume()
}
}
// batch: POST a JSON array to /v1/events to cut requestsNo native SDK. This is stock URLSession with zero packages. Call track from viewDidAppear (UIKit) or onAppear (SwiftUI) and from your key IBActions.
how do I add analytics to ios (swift)?
iOS analytics means logging screen appearances and taps from your native Swift app. smolanalytics has no iOS SDK. You send events with URLSession to /v1/events, a handful of lines with no dependency to vet or ship. Batch them to spare the battery, then ask your numbers in plain English from the dashboard or your editor.
Fire track() from viewDidAppear or a SwiftUI onAppear so each screen logs a screen_view with the view name in properties, and call it on the actions you care about (subscribe, purchase, complete onboarding). Use a stable distinct_id, the user id post login or an identifierForVendor before, so sessions and funnels stitch to one person.
Each call is a network request, so batch on device. Append events to an array, then flush a single JSON-array POST to /v1/events on a timer or when the app enters background via a scene lifecycle hook. It is the same endpoint and write key your web and server use, so you can open the dashboard and ask, in plain words, where the funnel leaks, with a CI test proving the answer is computed not guessed.
Honest pricing: 14-day full trial, no credit card. Then Solo $29/mo, never metered on seats or sites. Overage is $5/million with an emailed receipt, the dashboard never locks, and self-hosting the single Go binary is free forever (MIT).
Add analytics to iOS (Swift) tonight.
One snippet, or one endpoint. Tomorrow morning the verdict tells you which part of the funnel to fix.