Skip to main content
7 min read

How to Add Affiliate Tracking to Your SwiftUI App

Step-by-step guide to adding creator and affiliate install attribution to a SwiftUI app using the Appfiliate SDK. Track which creators drive installs and revenue.

A
Appfiliate
How to Add Affiliate Tracking to Your SwiftUI App

You want to know which creators and affiliates are actually driving installs for your SwiftUI app. Not at the campaign level. At the individual person level. Creator Sarah sent 40 installs last week, and 12 of those converted to paid subscribers. That level of detail.

This guide walks through adding affiliate tracking to a SwiftUI app using the Appfiliate iOS SDK. The full integration is three lines of code, takes about ten minutes, and requires no IDFA or App Tracking Transparency prompt.

Why affiliate tracking matters for iOS apps

Most iOS developers run some form of creator or influencer marketing. A YouTuber mentions your app, a TikTok creator posts a tutorial, an Instagram account shares a recommendation. The problem is that once the user taps through to the App Store, the connection between the creator's link and the eventual install is severed. There's no referrer header, no cookie, no query parameter that survives the App Store redirect.

Without attribution, you're paying creators based on trust. Or screenshots. Or not paying them at all because you can't prove what they drove. That's a problem for you and for the creators you're trying to recruit.

An affiliate tracking SDK solves this by matching the link click to the app install using device signals, without requiring any special permissions from the user. On iOS, this works through fingerprint matching of standard device information (device model, OS version, locale, timezone). No IDFA. No ATT prompt. The user never sees a "Allow this app to track you?" dialog.

The SDK is under 200KB, has zero external dependencies, and requires iOS 15.0+ with Swift 5.9+.

Step 1: Add the Appfiliate Swift Package

Open your SwiftUI project in Xcode and add the package dependency:

    • Go to File > Add Package Dependencies
    • Paste the repository URL:
https://github.com/Appfiliate-sdk/appfiliate-ios-sdk
    • Select version 1.0.0 or later
    • Click Add Package
That's the only dependency. No CocoaPods, no Carthage, no additional configuration.

Step 2: Configure the SDK and track installs

Find your app's entry point. In a SwiftUI app, this is the struct marked with @main. Add the SDK configuration to the init() method:

import SwiftUI
import Appfiliate

@main
struct MyApp: App {
    init() {
        Appfiliate.configure(appId: "APP_ID_HERE", apiKey: "API_KEY_HERE")
        Appfiliate.trackInstall()
    }

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

Replace APP_ID_HERE and API_KEY_HERE with the credentials from your Appfiliate dashboard. You can find these under your app's settings.

Two things to know about trackInstall(): it only runs once per install, so you can safely call it every time your app starts. If it has already run, it short-circuits immediately. It also runs asynchronously in the background, so it will not block your app's startup or UI thread.

If your app uses an AppDelegate rather than the SwiftUI app life-cycle, you can add the two lines to your application function in the applicationDidFinishLaunchingWithOptions method:

import Appfiliate

func application(_ application: UIApplication,
                 didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    Appfiliate.configure(appId: "APP_ID_HERE", apiKey: "API_KEY_HERE")
    Appfiliate.trackInstall()
    return true
}

That's it for install tracking. Every install from a creator's tracking link will now be matched and attributed in your dashboard.

Step 3: Attribute purchases (optional)

If you want to attribute revenue to the creator who drove the install, you'll need to add purchase tracking. Find the point where your app handles a successful in-app purchase (usually something like StoreKit 2's Product.purchase() or the older SKPaymentQueue) and add:

Appfiliate.trackPurchase(
    productId: product.id,
    revenue: price,
    currency: "USD",
    transactionId: transaction.id
)

You should call this after every successful purchase. The SDK will attribute the revenue to the creator who drove the install, so you can see exactly how much revenue each affiliate is driving.

With StoreKit 2 this might look something like this:

func purchase(_ product: Product) async throws {
    let result = try await product.purchase()

    switch result {
    case .success(let verification):
        let transaction = try checkVerified(verification)

        Appfiliate.trackPurchase(
            productId: product.id,
            revenue: Double(truncating: product.price as NSDecimalNumber),
            currency: "USD",
            transactionId: String(transaction.id)
        )

        await transaction.finish()
    case .userCancelled, .pending:
        break
    @unknown default:
        break
    }
}

This works, but there's an easier way if you're using a subscription management platform.

Step 4: Purchase tracking via webhooks

If you're using RevenueCat, Stripe, Superwall, Adapty or Qonversion to manage your subscriptions, you can skip the manual purchase tracking above altogether. Instead of calling trackPurchase() in your app, you can connect your subscription provider to Appfiliate via a webhook. We'll handle all purchases, renewals and cancellations automatically.

To do this, simply add one more line after trackInstall() to attach the user's subscription ID:

RevenueCat:

import Appfiliate
import RevenueCat

// In your App init():
Appfiliate.configure(appId: "APP_ID_HERE", apiKey: "API_KEY_HERE")
Appfiliate.trackInstall()
Appfiliate.setUserId(Purchases.shared.appUserID)

Stripe:

Appfiliate.configure(appId: "APP_ID_HERE", apiKey: "API_KEY_HERE")
Appfiliate.trackInstall()
Appfiliate.setUserId(stripeCustomerId)

You then need to copy and paste the webhook URL into your subscription provider's dashboard. For RevenueCat you can do this in the Dashboard > Integrations > Webhooks screen. You should add the following webhook:

https://us-central1-appfiliate-5a18b.cloudfunctions.net/api/v1/webhooks/revenuecat?secret=YOUR_WEBHOOK_SECRET

The webhook secret can be found in your Appfiliate dashboard, in the Integrations section. Once you've connected your subscription provider, purchases, renewals and cancellations will flow through automatically and be attributed to the creator who drove the install.

This is the recommended method. This means no purchase SDK code in your app, other than the single setUserId() call.

Testing the integration

Once you’ve added the SDK, make sure it works:

    • Build and run your app on a device or simulator. In the Xcode console, you should see log output from Appfiliate indicating that the SDK has initialized.
    • In your Appfiliate dashboard, go to your app’s installs. You should see the test install show up.
    • To test the full attribution flow, create a test tracking link in the dashboard, open it on a device, then install and open your app. The install should show up attributed to the test link.
You can also check attribution status from code:

if Appfiliate.isAttributed {
    print("Attribution ID: \(Appfiliate.attributionId ?? "none")")
}

What the SDK does not do

I want to make this very clear. The Appfiliate SDK does not collect IDFA. It does not trigger the ATT prompt. It does not do cross-app tracking. It does not collect personally identifying information. It uses only standard device signals (model, OS version, locale, timezone) and IDFV for deduplication. It is fully compliant with App Store guidelines. The SDK adds less than 200KB to your binary and has zero external dependencies. It will not affect your app’s launch time in any measurable way.

FAQ

How accurate is affiliate attribution on iOS without IDFA? On iOS, attribution uses fingerprint matching of device signals. It’s not 100% deterministic like Android’s Install Referrer API, but it’s accurate enough for creator-level attribution in practice. Any platform claiming perfect accuracy on iOS without IDFA is overpromising. Appfiliate is transparent about this, and we go into the technical details in our post on how attribution works without IDFA. Does the SDK work with SwiftUI’s new concurrency features? Yes. trackInstall() runs asynchronously and does not block the main thread. You can call it from init() in your @main App struct without worrying about async/await. The SDK handles its own background execution internally. How much does Appfiliate cost? Appfiliate starts at $79/month with no annual commitment. There’s a free tier to get started. See the full breakdown on the pricing page. Can I use this alongside an existing MMP like AppsFlyer or Adjust? Yes. The Appfiliate SDK operates independently and does not conflict with other attribution SDKs. MMPs are designed for paid ad campaign attribution across ad networks. Appfiliate is designed for per-creator attribution. They solve different problems and can coexist in the same app without issues. We wrote a detailed comparison of Appfiliate vs AppsFlyer vs Branch if you want to understand the differences.