SwiftUI
Add Fload's attribution SDK to a SwiftUI app. It takes one package and two lines in your App.
What you need
- iOS 15 or later as your deployment target.
- Your app's write key.
- RevenueCat in your app, if you want revenue per keyword. The SDK doesn't depend on it.
1. Add the package
In Xcode, choose File → Add Package Dependencies. Enter this URL:
https://github.com/fload-ai/fload-attribution-ios.gitChoose Up to Next Major Version from 1.0.0, and add the FloadAttribution product to your app target.
Using a Package.swift instead? Add it there:
dependencies: [
.package(url: "https://github.com/fload-ai/fload-attribution-ios.git", from: "1.0.0"),
],
targets: [
.target(
name: "PocketBudget",
dependencies: [
.product(name: "FloadAttribution", package: "fload-attribution-ios"),
]
),
]The package has no other dependencies.
2. Start it when the app launches
Call Fload.configure(key:) once, in your App's initializer. It returns at once and does its work in the background, so it never slows your launch.
import SwiftUI
import FloadAttribution
import RevenueCat
@main
struct PocketBudgetApp: App {
init() {
Purchases.configure(withAPIKey: "appl_…")
Fload.configure(key: "fload_pk_…")
Fload.setUserId(Purchases.shared.appUserID)
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}On the first launch, the SDK asks Apple for the attribution token and sends the install to Fload. Later launches send nothing new.
3. Link the user after login
setUserId links this install to your user, so Fload can match it to RevenueCat's revenue. Pass RevenueCat's app user id, anonymous or logged in.
When a user logs in, RevenueCat's id changes. Send the new one too:
_ = try await Purchases.shared.logIn("user_123")
Fload.setUserId(Purchases.shared.appUserID)Fload keeps every id an install has had, so the anonymous purchases and the logged-in ones both count. Calling setUserId again with the same id sends nothing.
4. Check it works
Turn on debug logs while you test:
Fload.configure(key: "fload_pk_…", options: FloadOptions(logLevel: .debug))Run the app on a real device. The SDK logs to the unified log under the subsystem com.fload.attribution. You can read it in Xcode's console or in the Console app.
- The Simulator has no AdServices token, so installs from it arrive without attribution.
- Apple sends test data to builds in developer mode. Fload sees it and leaves those installs out of your numbers.
Remove the debug option before you ship. By default the SDK logs warnings and errors only.
5. Ship it
Ship the update. Installs start to arrive as people open the new version. Fill in your App Store privacy answers from Privacy.
Reference
| Call | What it does |
|---|---|
Fload.configure(key:options:) | Starts the SDK. Call once, early in launch |
Fload.setUserId(_:) | Links your user id to this install. Safe to call before configure and on every launch |
Fload.installReference | This install's random reference, for support questions. nil before configure |
FloadOptions(logLevel:) | .none, .error, .warning (the default), .info or .debug |
Source code and changelog: github.com/fload-ai/fload-attribution-ios.