iOS SDK

Tracking Events

Send events from your app to power segments, campaigns, and analytics

Tracking Events

Events are the foundation of Nuxie's targeting and analytics. Track user actions to trigger campaigns, build segments, and measure performance.

The trigger method

Use trigger() to send an event. It works as a fire-and-forget call, but also returns a TriggerHandle you can observe for campaign decisions and entitlement updates.

swift
// Fire-and-forget
NuxieSDK.shared.trigger("item_added_to_cart", properties: [
    "item_id": "sku_999",
    "price": 29.99
])

Method signature

swift
@discardableResult
public func trigger(
    _ event: String,
    properties: [String: Any]? = nil,
    userProperties: [String: Any]? = nil,
    userPropertiesSetOnce: [String: Any]? = nil,
    handler: ((TriggerUpdate) -> Void)? = nil
) -> TriggerHandle
ParameterDescription
eventThe event name. Use a descriptive string like "checkout_started". System events use a $ prefix.
propertiesKey-value pairs attached to this specific event.
userPropertiesProperties to set on the user profile (mapped to $set).
userPropertiesSetOnceProperties to set only if not already present (mapped to $set_once).
handlerAn optional callback that receives progressive TriggerUpdate values as the event is processed.

Observing trigger outcomes

The returned TriggerHandle conforms to AsyncSequence and delivers TriggerUpdate values:

swift
let handle = NuxieSDK.shared.trigger("paywall_trigger")
 
for await update in handle {
    switch update {
    case .decision(let decision):
        print("Decision: \(decision)")
    case .entitlement(let entitlement):
        print("Entitlement: \(entitlement)")
    case .journey(let journey):
        print("Journey: \(journey)")
    case .error(let error):
        print("Error: \(error)")
    }
}

You can also use the callback parameter for the same updates:

swift
NuxieSDK.shared.trigger("paywall_trigger") { update in
    // Called on the main thread
    switch update {
    case .decision(.flowShown):
        print("Flow is now visible")
    default:
        break
    }
}

Event properties

Attach structured data to any event:

swift
NuxieSDK.shared.trigger("purchase_started", properties: [
    "product_id": "com.app.premium",
    "price": 9.99,
    "currency": "USD",
    "source": "settings_screen"
])

Properties are stored locally and delivered to the server in batches. They are available in segments, campaign conditions, and analytics.

System events

The SDK automatically tracks system events prefixed with $. These events are used internally for campaign triggers, segment evaluation, and analytics.

EventWhen trackedDescription
$app_installedFirst launchThe app launched for the first time on this device.
$app_updatedLaunch after version changeThe app launched with a different version than the previous session.
$app_openedEvery launchThe app opened, including first launch, updates, and foreground returns.
$app_backgroundedApp enters backgroundThe app moved to the background.
$identifyidentify() calledA user identity was linked. Includes distinct_id and $anon_distinct_id.
$journey_startCampaign triggersA campaign journey started for the user.
$journey_completedJourney finishesA campaign journey completed (goal met, expired, or cancelled).
$flow_shownFlow presentedA flow was displayed to the user.
$purchase_completedPurchase succeedsA StoreKit purchase completed.
$purchase_syncedTransaction syncedA transaction was verified and synced to the server.
$restore_completedRestore succeedsA purchase restore completed.
$feature_useduseFeature() calledFeature usage was reported.

Tip: Name your custom events without the $ prefix. The $ prefix is reserved for SDK system events.

How events are processed

When you call trigger(), the event flows through these stages:

  1. Snapshot -- the current distinct ID and session ID are captured at call time.
  2. Enrich -- device context (OS version, app version, device model) is attached.
  3. Sanitize -- data types are normalized and any configured sanitizer is applied.
  4. Store -- the event is persisted to a local database for segment evaluation and history.
  5. Route -- the event is forwarded to the campaign engine for trigger matching.
  6. Deliver -- the event is added to the network queue for batch delivery to the server.

If a beforeSend hook is configured, it runs between step 3 and step 4. Returning nil from beforeSend drops the event entirely.

Batching and delivery

Events are delivered to the server in batches for efficiency:

  • The queue flushes automatically when it reaches the flushAt threshold (default: 20 events).
  • A periodic timer flushes remaining events every flushInterval seconds (default: 30).
  • When the app enters the foreground, the queue flushes immediately.
  • When the app enters the background, automatic flushing pauses.

To flush manually:

swift
await NuxieSDK.shared.flushEvents()

Storage limits

Events are stored locally in a database for segment evaluation and campaign matching:

  • Maximum stored events: 10,000
  • Retention period: 30 days

Events beyond these limits are automatically cleaned up. Network delivery is handled separately through the in-memory batch queue.

Next steps