User attribution helps you understand where a user came from before installing your app.
In OnsideKit, attribution links the app install to a prior session in a web browser. The SDK can then return a refererUrl that describes the source page.
Requirements
Attribution depends on early SDK initialization.
Call Onside.initialize() as early as possible at app launch. Do this before any other OnsideKit API calls.
If you skip or delay initialization, attribution may fail or return incomplete metadata. See Installation Guide.
Getting attribution metadata
Call Onside.getAttributionMetadata(completion:).
The completion returns either:
OnsideAttributionMetadata on success.
OnsideAttributionMetadataError on failure.
OnsideAttributionMetadata contains an optional refererUrl.
refererUrl != nil means the SDK attributed the install to a browser session.
refererUrl == nil means the install was organic, or attribution was not possible.
import UIKit
import OnsideKit
@main
final class AppDelegate: UIResponder, UIApplicationDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
// Call as early as possible for reliable attribution.
Onside.initialize()
Onside.getAttributionMetadata { result in
switch result {
case .success(let metadata):
if let refererUrl = metadata.refererUrl {
print("Onside refererUrl: \(refererUrl)")
// Send refererUrl to your analytics / backend if needed.
} else {
print("No refererUrl. Organic install or attribution unavailable.")
}
case .failure(let error):
print("Failed to fetch attribution metadata: \(error)")
}
}
return true
}
}