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.gitSelect 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 cash commission is then calculated and queued for payout.
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 cash commission is calculated based on your configured rates and paid out via Stripe.
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.
