Skip to main content

Basic Configuration

Configure SpendOwl once during app launch with your API key:
import SwiftUI
import SpendOwl

@main
struct MyApp: App {
    init() {
        SpendOwl.configure(apiKey: "spendowl_live_xxx")
    }

    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}
Call configure() only once. Subsequent calls are ignored.

What Happens on Configure

When you call configure(), SpendOwl automatically:
  1. Fetches attribution — Gets the Apple Search Ads attribution token and sends it to SpendOwl servers
  2. Starts purchase tracking — Observes StoreKit 2 transactions for ROAS calculation
  3. Initializes networking — Sets up the API client with retry logic
Both attribution and purchase tracking are required for accurate ROAS calculation.

Advanced Configuration

For more control, use SpendOwlConfiguration:
let config = SpendOwlConfiguration(
    apiKey: "spendowl_live_xxx",
    timeoutInterval: 30,  // seconds
    maxRetries: 5
)
SpendOwl.configure(config)

Configuration Options

apiKey
String
required
Your SpendOwl API key from the dashboard.
baseURL
URL
default:"https://spendowl.io/api"
The API base URL. Only change this for testing or if instructed by SpendOwl support.
timeoutInterval
TimeInterval
default:"10"
Network request timeout in seconds. Increase for slow networks.
maxRetries
Int
default:"3"
Maximum retry attempts for failed requests. Client errors (4xx) are not retried.

Check Configuration Status

Verify the SDK is configured before using other methods:
if SpendOwl.isConfigured {
    // SDK is ready
    let attribution = try await SpendOwl.attribution()
}

API Key Best Practices

Don’t hardcode API keys in source code. Use environment variables or a configuration file:
let apiKey = ProcessInfo.processInfo.environment["SPENDOWL_API_KEY"] ?? ""
SpendOwl.configure(apiKey: apiKey)
Use different API keys for development and production:
#if DEBUG
let apiKey = "spendowl_test_xxx"
#else
let apiKey = "spendowl_live_xxx"
#endif

SpendOwl.configure(apiKey: apiKey)
Add your config file to .gitignore to prevent accidentally committing API keys.

Thread Safety

SpendOwl is thread-safe. You can call configure() from any thread, though calling from the main thread during app launch is recommended.

Next Steps