Analytics.swift (URLSession, no deps) · open source (MIT) · ask in plain English

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.

Analytics.swift (URLSession, no deps)
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 requests

No 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.

questions

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.
Do I need a cookie banner?
Not in cookieless mode. smolanalytics can run without storing anything on the device, so there is no consent banner to add. You still get visitors, referrers, funnels, retention, and paths, and AI-assistant referrals (chatgpt.com, claude.ai, perplexity.ai) show up as their own channel.
Is it enough for a real product, or just page counts?
It does funnels, retention, paths, cohorts, and a daily verdict on what to fix, from the same events, and you ask it in plain English. It deliberately skips session replay, feature flags, and experiments. If you want a straight answer on what to fix, that you own and can self-host free, it fits.

keep reading