---
title: "Send events from an iOS app"
description: "Add the Swift package, set it up at launch with the test key in debug builds, and get installs, updates and opens with no code."
canonical: "https://www-stage.togohq.ai/docs/ios"
applies_to: "sdk-ios 1.x"
updated: "2026-11-24T00:00:00Z"
---

# Send events from an iOS app

Add the Swift package, set it up at launch with the test key in debug builds, and get installs, updates and opens with no code.

Use the iOS SDK in an iPhone or iPad app written in Swift, with SwiftUI or UIKit. iOS 15 or later;
no dependencies. For what happens on your server — a payment confirmed, a subscription renewed —
also use [the server SDK](/docs/node).

## Add the package

In Xcode, choose **File → Add Package Dependencies…**, enter `https://github.com/togohq/sdk-ios`,
choose **Up to Next Major Version** from `1.0.0`, and add the **Togo** library to your app target.

In a `Package.swift`:

```swift
dependencies: [
  .package(url: "https://github.com/togohq/sdk-ios", from: "1.0.0")
],
targets: [
  .target(name: "MyApp", dependencies: [.product(name: "Togo", package: "sdk-ios")])
]
```

## Set it up at launch, with the test key in debug builds

Call `Togo.setup(_:)` once, as the app starts. Use the **test** key (`togo_pkt_…`) in debug builds,
so `verify_tracking` sees the events from your simulator, and the **live** key (`togo_pkl_…`) in
release builds:

```swift
import SwiftUI
import Togo

@main
struct MyApp: App {
  init() {
    #if DEBUG
      let key = "togo_pkt_…"
    #else
      let key = "togo_pkl_…"
    #endif
    Togo.setup(TogoConfig(writeKey: key))
  }

  var body: some Scene {
    WindowGroup { ContentView() }
  }
}
```

In a UIKit app, call it from your app delegate as the app finishes launching. Every call can be made
from any thread and never waits on the network. No call throws: a refused call logs one `[togo]`
line saying why.

## Track events and name the person

```swift
Togo.track("plan_selected", properties: ["plan_id": "pro", "seats": 5])

// After sign-in: your own account id, the same one your website and server use.
Togo.identify(account.id)
Togo.setPersonProperties(email: account.email, name: account.name)

// At logout: a new anonymous visitor on this device.
Togo.reset()
```

Pass **the same id** to `identify()` that your website and server use, so one person is one person
on every platform. Never put an email address or a name in an event property; they belong in
`setPersonProperties`. [Identify people](/docs/guides/identify) and
[Set person properties](/docs/guides/person-properties) explain both calls.

## What the SDK sends on its own

| Event              | When                                                                          | Properties                                   |
| ------------------ | ----------------------------------------------------------------------------- | -------------------------------------------- |
| `$app_installed`   | The first launch of an install                                                | —                                            |
| `$app_updated`     | The first launch after the app's version or build changed                     | `previous_app_version`, `previous_app_build` |
| `$app_opened`      | The app comes to the foreground: opened by the user, or brought back          | `from_background`                            |
| `$session_started` | The first event of a session: after 30 minutes idle, or once a day has passed | —                                            |

A launch nobody sees — iOS preparing the app in advance, a push notification handled in the
background — opens nothing and starts no session. Every event carries the app's version and build
from your bundle, read as `$app_version` and `$app_build`, so any chart can split by release, along
with the device's OS, OS version and model. Set `appVersion` and `appBuild` in `TogoConfig` when
your bundle's numbers are not your release numbers.

Events wait on the device while it is offline and are sent when it reconnects, even after iOS
kills the app; each keeps the time it happened. Up to 5,000 events, or 8 MiB, wait; past that the
oldest are dropped, and an event still unsent after seven days is dropped, with an error for each
in your logs and in `TogoConfig(onError:)`.

## Expect a one-time spike of installs in your first release with Togo

In the first version of your app that adds the SDK, every existing user's first launch sends
`$app_installed`, because the SDK has no earlier install to find. Expect one spike of installs in
that release, and read installs from the release after it.

A person who withdraws consent and later grants it sends `$app_installed` again: withdrawal deletes
everything the SDK stored, including what would have told it the app was installed before.

## Ask for consent where you need it

```swift
Togo.setup(TogoConfig(writeKey: key, consent: .pending))

// When your consent screen resolves:
Togo.setConsent(.granted)  // or .denied
```

Under `.pending` the SDK holds up to 100 events in memory and stores and sends nothing.
`.granted` sends them; `.denied` drops them and deletes what the SDK stored on the device.
[Connect a consent banner](/docs/guides/consent) explains the four states; whether your app needs
consent is your determination.

## Answer the App Store privacy questions

The package carries a privacy manifest, which Xcode adds to your app's privacy report. For the
data the SDK collects, answer the App Store privacy questions as the manifest does:

- **Device ID, User ID and Product Interaction**, each **linked to the user**, **not used for
  tracking**, for **Analytics**.
- **No tracking.** The SDK never reads the advertising identifier or shows the App Tracking
  Transparency prompt — [The advertising identifier and App Tracking Transparency](/docs/guides/ios-advertising-identifier)
  says what to do instead.

Your app's own answers also cover any personal data you send, such as the email address in
`setPersonProperties`.

## Check it works

Run the app on a simulator with the test key and confirm the events arrived:
[Check that events arrive](/docs/verify).

Every method and option: [Togo for iOS reference](/docs/reference/sdk-ios).
