Skip to content

Add Millimetry to an Apple app

The Swift SDK is a Swift package with no dependencies. It runs on iOS and iPadOS 15, macOS 12, tvOS 15, watchOS 8 and visionOS 1 or later. It is written in Swift 6 with strict concurrency, and every call is safe from any thread.

In the dashboard, choose Add an app or site, name the app, and copy its key (ak_…). The key identifies your app; it is not a secret, so it is fine in your binary.

In Xcode, choose File › Add Package Dependencies… and add the Millimetry package. In a Package.swift:

.package(url: "https://github.com/Pineapple-Eng/millimetry-swift", from: "0.1.0")

Call configure once, as early as possible: in your App’s initializer, or in application(_:didFinishLaunchingWithOptions:).

import Millimetry
@main
struct SlicksApp: App {
init() {
Millimetry.configure(
appKey: "ak_…",
host: URL(string: "https://e.millimetry.app")!
)
}
var body: some Scene { WindowGroup { ContentView() } }
}

By default the SDK sends app_open at launch and whenever the app returns to the foreground. Nothing else is tracked automatically. Turn it off with options: .init(trackAppOpen: false).

Building with an AI app builder or a coding agent’s chat? Paste this, with your key in place of ak_…:

Add Millimetry analytics to this iOS app. Add the Swift package https://github.com/Pineapple-Eng/millimetry-swift
(from 0.1.0), and at launch call:
Millimetry.configure(appKey: "ak_…", host: URL(string: "https://e.millimetry.app")!)
Track the screens that matter with Millimetry.screen("name") and the actions that matter with
Millimetry.track("event_name"), names in snake_case, never a name, email or id in them.
No identifier, no consent prompt: Millimetry stores none. Then tell me which events you added.
Millimetry.track("screen_view", ["screen": "settings"])
Millimetry.track("purchase", ["plan": "pro", "price": 4.99, "trial": false])
  • Names are 1 to 64 characters. Names starting with $ are reserved.
  • Up to 25 properties per event. Values are strings, whole numbers, decimals or Booleans, written as plain literals.
  • Strings longer than 256 characters are cut.

See naming events for names that stay useful. Never put personal data in properties: no names, email addresses, phone numbers or account IDs. The server drops properties that look like those, but that is a safety net, not a guarantee.

Events wait in a small queue on disk and go out in batches:

  • every 30 seconds while the app is in the foreground (every 2 seconds in debug builds);
  • as soon as 50 events are waiting;
  • when the app moves to the background, inside a background task so the upload can finish;
  • when you call await Millimetry.flush().

Offline, or when the server is busy, a batch stays queued and is retried with a growing delay, up to 5 minutes. A batch keeps its ID across retries and relaunches, so it is stored once however many times it arrives. The queue keeps at most 1,000 events and drops events older than 7 days.

Builds with the Debug configuration mark their events as debug data. The dashboard keeps that data apart and deletes it after 30 days. Override with Options(isDebug:).

Millimetry.setEnabled(false) stops tracking and deletes everything queued. The SDK does not remember the choice, because remembering it would mean storing something on the device. Keep your own setting and apply it on every launch, before configuring:

Millimetry.setEnabled(Settings.shared.analyticsAllowed)
Millimetry.configure(appKey: "ak_…", host: URL(string: "https://e.millimetry.app")!)