How to Integrate Affiliate Tracking into a Native iOS (Swift) App

How to Integrate Affiliate Tracking into a Native iOS (Swift) App

Technical tutorial for adding affiliate tracking to your iOS app using Insert Affiliate Swift SDK.

Add Affiliate Tracking to Your iOS App with Swift Package Manager

Integrating affiliate tracking into a native iOS app built with Swift takes three steps: add the InsertAffiliateSwiftSDK via Swift Package Manager, configure deep linking to capture affiliate referrals, and connect a purchase verification platform to automate commission payouts. Most developers complete the integration in a single sitting.

With the App Store generating over $60 billion in US consumer spending in 2025 according to Sensor Tower, subscription-based iOS apps have a clear financial incentive to tap into affiliate-driven growth. The Insert Affiliate Swift SDK is purpose-built for this, requiring iOS 13.0+, Swift 5.0+, and Xcode 12.0+.



Step 1: Install the SDK via Swift Package Manager

Open your Xcode project, navigate to File, then Add Packages. In the search field, enter the repository URL:

https://github.com/Insert-Affiliate/InsertAffiliateSwiftSDK.git

Select the branch main and click Add Package. Xcode will resolve the dependency and add InsertAffiliateSwift to your project.



Step 2: Initialize the SDK in AppDelegate

Import the SDK and initialize it in your AppDelegate's application(_:didFinishLaunchingWithOptions:) method. You will need your company code from the Insert Affiliate dashboard under Settings.

import InsertAffiliateSwift

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions:
            [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {

        InsertAffiliateSwift.initialize(
            companyCode: "YOUR_COMPANY_CODE",
            verboseLogging: true,
            insertLinksEnabled: true
        )

        return true
    }
}

For SwiftUI apps using the @main App protocol instead of AppDelegate, you can initialize the SDK in your App struct's init() method or use an AppDelegate adaptor.

The verboseLogging: true flag outputs detailed logs to the console so you can confirm everything is wired correctly during development. Disable it before shipping to production.



Step 3: Configure Deep Linking

Deep linking connects an affiliate's unique URL to a user session in your app. When a user taps an affiliate link, the SDK captures and stores the affiliate identifier locally.

The simplest option is Insert Links, Insert Affiliate's built-in deep linking solution. Enabling insertLinksEnabled: true during initialization activates it with no additional third-party SDK required.

If your app already uses Branch.io, pass the referring link to the Insert Affiliate SDK inside your Branch session handler:

Branch.getInstance().initSession(launchOptions: launchOptions) {
    (params, error) in
    if let referringLink = params?["~referring_link"] as? String {
        InsertAffiliateSwift.setInsertAffiliateIdentifier(
            referringLink: referringLink
        )
    }
}

For AppsFlyer, use the deep linking delegate callback:

func didResolveDeepLink(_ result: DeepLinkResult) {
    if let deepLinkValue = result.deepLink?.deeplinkValue {
        InsertAffiliateSwift.setInsertAffiliateIdentifier(
            referringLink: deepLinkValue
        )
    }
}



Step 4: Connect Purchase Verification

Insert Affiliate requires a purchase verification platform to validate transactions and calculate affiliate commissions. For iOS apps, RevenueCat is the recommended choice for its straightforward webhook-based integration.

After initializing RevenueCat, register a callback so the affiliate identifier is synced to RevenueCat's subscriber attributes:

InsertAffiliateSwift.onAffiliateIdentifierChanged { identifier in
    Purchases.shared.attribution.setAttributes([
        "insert_affiliate": identifier,
        "insert_timedout": ""
    ])
}

InsertAffiliateSwift.returnInsertAffiliateIdentifier()

When a user who arrived through an affiliate link makes a purchase, RevenueCat validates the App Store receipt and sends a webhook to Insert Affiliate. The affiliate's commission is calculated and recorded in your Insert Affiliate dashboard, ready for a one-click payout from your dashboard when you're ready to send.

Other supported verification platforms include Adapty, Apphud, Iaptic, and direct App Store Server Notifications.



Step 5: Adapty Integration (Alternative to RevenueCat)

If your app uses Adapty instead of RevenueCat, set the Insert Affiliate identifier as an Adapty custom attribute:

func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions:
        [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {

    Adapty.activate("YOUR_ADAPTY_PUBLIC_SDK_KEY")

    InsertAffiliateSwift.initialize(
        companyCode: "YOUR_COMPANY_CODE",
        verboseLogging: true,
        insertLinksEnabled: true
    )

    InsertAffiliateSwift.onAffiliateIdentifierChanged { identifier in
        let builder = AdaptyProfileParameters.Builder()
            .with(customAttribute: identifier,
                  forKey: "insert_affiliate")
        Adapty.updateProfile(params: builder.build())
    }

    return true
}



Step 6: Advanced Configuration

The SDK supports several optional parameters for controlling attribution behavior:

InsertAffiliateSwift.initialize(
    companyCode: "YOUR_COMPANY_CODE",
    verboseLogging: false,
    insertLinksEnabled: true,
    insertLinksClipboardEnabled: true,
    affiliateAttributionActiveTime: 604800,
    preventAffiliateTransfer: true
)
  • insertLinksClipboardEnabled: Enables clipboard-based attribution as a fallback when standard deep links do not fire.
  • affiliateAttributionActiveTime: Sets the attribution window in seconds. The default of 604800 equals seven days.
  • preventAffiliateTransfer: When true, a new affiliate click will not overwrite an existing attribution, protecting the first referrer.



Step 7: Test the Full Flow

Generate a test affiliate link from your Insert Affiliate dashboard. Tap the link on a physical device (deep links do not work reliably in the iOS Simulator for universal links). Open the app and check the Xcode console for verbose logs confirming the affiliate identifier was captured. Complete a test purchase using a sandbox Apple ID and verify the transaction appears in your Insert Affiliate dashboard.



How the End-to-End Flow Works

After integration, the tracking flow is fully automated. An affiliate shares their unique link. A user taps the link, your app opens, and the SDK stores the affiliate identifier. The user subscribes or makes an in-app purchase. Your verification platform (RevenueCat, Adapty, or another supported service) validates the receipt and notifies Insert Affiliate.

The affiliate's commission is calculated based on your configured rates and recorded in your Insert Affiliate dashboard. Payouts are sent with one click from your dashboard when you're ready.

Affiliates sign up through Insert Affiliate's signup page and generate their own tracking links. You configure commission structures, monitor performance, and manage payouts from the Insert Affiliate dashboard.

The InsertAffiliateSwiftSDK is open source on GitHub at github.com/Insert-Affiliate/InsertAffiliateSwiftSDK. Complete integration guides for each purchase verification platform are at docs.insertaffiliate.com.



Frequently Asked Questions

Does the Insert Affiliate Swift SDK support SwiftUI? Yes. For SwiftUI apps using the @main App protocol, initialise the SDK in your App struct's init() method or use an AppDelegate adaptor. Deep link handling and identifier callbacks work the same way as in UIKit apps.

What's the difference between Insert Links and Branch.io for deep linking? Insert Links is Insert Affiliate's built-in deep linking solution — no additional SDK required, just set insertLinksEnabled: true during initialization. Branch.io and AppsFlyer are also supported if you already have one in your app. For new integrations, Insert Links is the recommended path.

What iOS versions and tools does the SDK require? The SDK requires iOS 13.0 or later and Swift 5.0 or later. Xcode 12.0 or later is needed to install the package via Swift Package Manager.

Can I track one-time in-app purchases as well as subscriptions? Yes. Attribution and commission tracking work for any purchase event your verification platform reports. Your platform (RevenueCat, Adapty, Iaptic, or App Store Server Notifications) sends the event to Insert Affiliate, which records the commission based on your configured rate.

What should I check if affiliate attributions are not appearing in my dashboard? First, enable verboseLogging: true and check the Xcode console for identifier capture after tapping a test link. Then check RevenueCat's customer attributes page for the test subscriber and confirm the insert_affiliate attribute is set before the purchase. Finally, verify the webhook URL in RevenueCat matches exactly the one shown in your Insert Affiliate dashboard settings.

Comments

Ready to grow your app with affiliate marketing?

Join hundreds of app developers who are already tracking affiliate-driven in-app purchases and rewarding their partners.