Skip to main content
The iOS SDK supports iOS 13 and later.

Install with Swift Package Manager

In Xcode, select File → Add Package Dependencies and add:
https://github.com/datalyr/swift
Add the DatalyrSDK product to your app target.

Initialize

import DatalyrSDK

Task {
    try await DatalyrSDK.configure(
        apiKey: "dk_your_api_key"
    )
}

Track an event

await datalyrTrack("signup_completed", properties: [
    "plan": "pro"
])

Identify a user

await datalyrIdentify("user_123", properties: [
    "email": "[email protected]"
])

Track a screen

PricingView()
    .datalyrScreen("Pricing")

Core methods

MethodUse it to
DatalyrSDK.configure(...)Initialize the shared SDK.
datalyrTrack(...)Track an event.
datalyrScreen(...)Track a screen view.
datalyrIdentify(...)Identify a user.
datalyrAlias(...)Link two IDs for the same user.
datalyrReset()Clear identity on logout.
datalyrFlush()Send queued events immediately.
datalyrGetAnonymousId()Read the persistent anonymous ID.
datalyrTrackPurchase(...)Track purchase revenue.
datalyrTrackSubscription(...)Track subscription revenue.
Call datalyrReset() when a user signs out.

CocoaPods

pod 'DatalyrSDK', '~> 2.1.8'
Then run pod install and open the generated workspace.

Configuration

let config = DatalyrConfig(
    apiKey: "dk_your_api_key",
    debug: false,
    maxRetries: 3,
    timeout: 15,
    batchSize: 10,
    flushInterval: 10,
    maxQueueSize: 1000,
    enableAutoEvents: true,
    enableAttribution: true
)

try await DatalyrSDK.shared.initialize(config: config)
OptionDefaultWhat it controls
apiKeyRequiredWorkspace API key.
debugfalseDevelopment logging.
maxRetries3Delivery retries.
retryDelay1Delay between retries in seconds.
timeout15Request timeout in seconds.
batchSize10Events sent in each batch.
flushInterval10Automatic flush interval in seconds.
maxQueueSize1000Maximum queued events.
enableAutoEventstrueApp lifecycle and session events.
enableAttributiontrueDeep-link and campaign attribution.
autoEventConfigFine-grained automatic event settings.
skadTemplateSKAdNetwork template for conversion values.

Automatic events

let autoEvents = AutoEventConfig(
    trackSessions: true,
    trackScreenViews: true,
    trackAppUpdates: true,
    trackPerformance: false,
    autoTrackScreenViews: false
)
Automatic UIKit screen tracking is opt-in. For SwiftUI, use the .datalyrScreen() modifier.

Identity

await datalyrIdentify("user_123", properties: [
    "email": "[email protected]",
    "plan": "pro"
])

let anonymousId = datalyrGetAnonymousId()
Use datalyrAlias only to join two IDs for the same person. Call datalyrReset() on logout or account switching.

Revenue and subscriptions

await datalyrTrackPurchase(
    value: 99.99,
    currency: "USD",
    productId: "pro_yearly"
)

await datalyrTrackSubscription(
    value: 19.99,
    currency: "USD",
    plan: "pro_monthly"
)
The SDK also includes helpers for add to cart, content views, checkout, registration, search, leads, and payment information. Pass incoming links to the SDK:
await DatalyrSDK.shared.handleDeepLink(url)
Read the current state when you need it:
let attribution = DatalyrSDK.shared.getAttributionData()
let journey = DatalyrSDK.shared.getJourney()
let summary = DatalyrSDK.shared.getJourneySummary()

App Tracking Transparency

let status = await DatalyrSDK.shared.requestTrackingAuthorization()
let idfa = DatalyrSDK.shared.getIDFA()
ATT controls access to advertising identifiers. It is not a complete analytics-consent system. Your app remains responsible for consent handling and accurate App Store privacy disclosures.

RevenueCat and Superwall

let revenueCat = DatalyrSDK.shared.getRevenueCatAttributes()
let superwall = DatalyrSDK.shared.getSuperwallAttributes()
Pass these attributes to the matching SDK when you need Datalyr identity available in subscription events.

Diagnostics

let status = DatalyrSDK.shared.getStatus()
await datalyrFlush()
Use getStatus() during setup verification and datalyrFlush() before a controlled shutdown or background transition when immediate delivery matters.