iOS SDK (Swift)

Full reference for the OnRamp Swift SDK. Works with UIKit and SwiftUI on iOS 14+.


Installation

Swift Package Manager

In Xcode: File → Add Package Dependencies, paste the repository URL, and add the OnRamp library to your target.

https://github.com/getonramp/onramp-swift

Then import the module wherever you need it:

swift
import OnRamp

Setup

Call OnRamp.initialize() once at app launch before any OnRamp.step() calls.

UIKit - AppDelegate

swift
import UIKit
import OnRamp

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        OnRamp.initialize(
            apiKey: "onr_YOUR_API_KEY",
            host: "https://ingest.getonramp.dev",
            appVersion: Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
        )
        return true
    }
}

SwiftUI - @main App struct

swift
import SwiftUI
import OnRamp

@main
struct MyApp: App {
    init() {
        OnRamp.initialize(
            apiKey: "onr_YOUR_API_KEY",
            host: "https://ingest.getonramp.dev",
            appVersion: Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
        )
    }

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

Your API key is on the Settings page of each app in the dashboard.

OnRamp.initialize() options

OptionTypeRequiredDefaultDescription
apiKeyStringYes-Your API key from Settings
hostStringYes-Ingestion endpoint. Use https://ingest.getonramp.dev for production
appVersionString?NonilApp version string, e.g. "2.4.1" - shows in version breakdown

Tracking steps

OnRamp.step(_:properties:)

Records a funnel milestone. Safe to call from any thread or SwiftUI view. The SDK fires events asynchronously via URLSession.

swift
import OnRamp

// Basic
OnRamp.step("account_created")

// With custom properties
OnRamp.step("subscription_started", properties: [
    "plan": "pro",
    "billing_period": "annual",
    "price_usd": 79.99,
])

Options

OptionTypeDescription
properties[String: Any]?Custom key-value data attached to the event

Property values must be primitives - strings, numbers, or booleans. Nested dictionaries are not supported. Numeric values become queryable as custom metrics in the funnel chart.


Identifying users

OnRamp.identify(_:)

Associates the current anonymous user with known identity traits. Call once after sign-in so integrations (Stripe, RevenueCat) can match the user to external records.

swift
// After the user signs in
OnRamp.identify([
    "email": user.email,
    "userId": user.id,
])

identify() is entirely optional. All funnel and retention features work without it. Only call it if you have an integration connected and want to correlate OnRamp sessions with external revenue data.


Session management

OnRamp.newSession()

Force-starts a new session. Call after sign-out so the next user gets a clean session.

swift
func handleLogout() {
    signOut()
    OnRamp.newSession()
}

Privacy

The SDK uses UserDefaults (not HTTP cookies) to persist the anonymous ID across app launches. No personal data is collected unless you explicitly call identify(). All events are sent to EU servers.

If your app targets the EU market, analytics storage (including UserDefaults) may require user consent under EU ePrivacy rules. OnRamp does not replace a consent banner.


Requirements

Minimum
iOS14.0
Swift5.7
Xcode14