# iOS and Mac

A Swift Package for iOS and macOS. Events queue on disk and upload in batches, so nothing is lost offline. No IDFA or IDFV is read or sent.

## Install

In Xcode, choose File, Add Package Dependencies, and add the Pagebee package. Then configure it once at launch.

```swift title="TallyApp.swift"
import Pagebee
import SwiftUI

@main
struct TallyApp: App {
    init() {
        Pagebee.configure(
            siteKey: "pb_pk_your_site_key",
            apiURL: URL(string: "https://api.pagebee.ai")!
        )
    }
    var body: some Scene { WindowGroup { ContentView() } }
}
```

## Screens, events and revenue

```swift
Pagebee.screen("Settings")   // counts as a pageview for /Settings
Pagebee.track("Exported PDF", props: ["pages": 12])
Pagebee.track("Upgraded", props: ["plan": "pro"],
              revenue: Revenue(amount: 999, currency: "GBP"))   // minor units
```

For SwiftUI, call `Pagebee.screen` in `.onAppear`.

## Environments

DEBUG builds are sent as staging. Pass `environment: .production` (or `.staging`, `.preview`) to `configure` to override it.

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `trackLifecycle` | `true` | Records install, update, open and background |
| `flushInterval` | 30 seconds | Time between uploads; backs off while offline |
| `maxBatchSize` | 20 | Upload as soon as this many are waiting (max 50) |
| `userIdSalt` | none | Needed only for `identify`; the user id is hashed on the device |

The queue holds up to 1,000 events and drops the oldest first.
