iOS

MetaRouter iOS SDK

Capture behavioral data directly from your iOS app and route it through MetaRouter to any destination — without juggling multiple vendor SDKs.

View on GitHub GitHub release

Why use the Mobile SDK?

One integration, unlimited destinations
Stop embedding separate SDKs for analytics, marketing, and data warehouses. Collect once, route everywhere through MetaRouter.

Update routing without app releases
Add or remove destinations server-side. No code changes, no App Store review cycles.

Reliable delivery, even offline
Events are queued locally and delivered automatically when connectivity returns. Built-in retry logic handles transient failures.

Automatic identity resolution
Track users from first app open through sign-up and beyond. The SDK manages anonymous IDs, persists identity across sessions, and connects pre-login activity to known users.

Privacy-ready by design
Built-in support for IDFA consent via App Tracking Transparency, easy opt-out handling, and clean user data reset for GDPR/CCPA compliance.

Lightweight footprint
Zero external dependencies. Minimal impact on app size and startup time.

Quick start

1) Add the SDK

Add the package via Swift Package Manager in Xcode:

File → Add Package Dependencies

Enter:

https://github.com/metarouterio/ios-sdk.git

Or add it directly to your Package.swift:

dependencies: [
    .package(url: "https://github.com/metarouterio/ios-sdk.git", from: "1.2.2")
]

2) Initialize

Add this to your AppDelegate or app entry point:

import MetaRouter

let analytics = MetaRouter.Analytics.initialize(
    with: InitOptions(
        writeKey: "YOUR_WRITE_KEY",
        ingestionHost: "https://YOUR_CLUSTER.YOUR_SITE.com"
    )
)

Your writeKey and ingestionHost are available in the MetaRouter dashboard.

3) Start tracking

// Track user actions
analytics.track("Product Viewed", properties: [
    "sku": "SHOE-123",
    "price": 89.99
])

// Identify known users
analytics.identify("user-456", traits: [
    "email": "[email protected]",
    "plan": "premium"
])

// Track screen views
analytics.screen("Product Detail", properties: [
    "category": "Footwear"
])

Events are batched and delivered automatically. No additional setup required.


Core capabilities

Event tracking

MethodPurpose
track(_:properties:)Capture user actions — purchases, clicks, feature usage
screen(_:properties:)Record screen views for navigation analytics
page(_:properties:)Record page views (web semantics, if applicable)

User identity

MethodPurpose
identify(_:traits:)Associate events with a known user
group(_:traits:)Associate users with a company, team, or account
alias(_:)Link anonymous activity to a newly identified user

Lifecycle & privacy

MethodPurpose
flush()Send queued events immediately
reset()Clear all user data (use on logout)
setAdvertisingId(_:)Set IDFA for attribution (with user consent)
clearAdvertisingId()Remove IDFA when user opts out

Identity that just works

The SDK automatically handles the complexity of user identity:

Before login — Users are assigned a stable anonymous ID
On login — Call identify() to attach a known user ID
Across sessions — Identity persists through app restarts
On logout — Call reset() to clear everything and start fresh

Connect anonymous browsing to authenticated users with alias():

// User browses anonymously, then signs up
analytics.track(
    "Product Viewed",
    properties: ["sku": "ABC"]
) // tracked as anonymous

// User creates account
analytics.alias("new-user-789") // links anonymous → known
analytics.identify(
    "new-user-789",
    traits: ["email": "[email protected]"]
)

// Full journey is now connected in your downstream tools

Advertising & attribution

For ad attribution, you can include the Identifier for Advertisers (IDFA):

import AppTrackingTransparency
import AdSupport

// Request permission (required on iOS 14.5+)
ATTrackingManager.requestTrackingAuthorization { status in
    if status == .authorized {
        let idfa = ASIdentifierManager.shared()
            .advertisingIdentifier
            .uuidString
        analytics.setAdvertisingId(idfa)
    }
}
// When user opts out
analytics.clearAdvertisingId()

Privacy note:
iOS requires explicit user consent via App Tracking Transparency before collecting the IDFA.
Add NSUserTrackingUsageDescription to your Info.plist with a clear explanation of why you’re requesting tracking permission.

See the GitHub docs for full implementation details:
https://github.com/metarouterio/ios-sdk


Requirements

ComponentVersion
iOS15.0+
macOS12.0+
Swift5.5+