Attribution
Retrieve install attribution metadata from OnsideKit, including the referring browser URL tied to a prior web session.
Attribution tells you where a user came from before installing your app. OnsideKit links the install to a prior browser session and returns a referer describing the source page.
Requirements
Call Onside.initialize() as early as possible at app launch, before any other OnsideKit API. The earlier you initialize, the sooner the install can be correlated with the originating session. See Initializing the SDK.
Getting attribution metadata
@MainActor static func getAttributionMetadata(
completion: @escaping @MainActor (Result<OnsideAttributionMetadata, OnsideAttributionMetadataError>) -> Void
)OnsideAttributionMetadata contains a single optional field:
struct OnsideAttributionMetadata {
var referer: String?
}referer != nil— the install was attributed to a browser session. The value is the full URL loaded in the user's browser when the install started (typically your landing page), including any ad-network query parameters such as UTM tags and click IDs. It is aStringpassed through exactly as the Onside backend returned it — OnsideKit does not parse or normalize it, so construct aURLyourself if you need one.referer == nil— the install was organic, or attribution wasn't possible. For apps not installed from Onside (App Store, unknown source, the simulator) the SDK returnsnilright away, without a network request.
Example
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 referer = metadata.referer {
print("Onside referer: \(referer)")
// Send referer to your analytics / backend if needed.
} else {
print("No referer. Organic install or attribution unavailable.")
}
case .failure(let error):
print("Failed to fetch attribution metadata: \(error)")
}
}
return true
}
}Errors
OnsideAttributionMetadataError:
.connectionError
Network failure.
Retry later.
.serviceUnavailable
Server returned 5xx.
Retry later.
.appNotRegistered
The app/install isn't recognized by Onside (HTTP 404).
Check your app registration/configuration.
.internalError
Parsing or other unexpected error, including OnsideKit's internal core being unavailable.
Report if persistent.
Next
Building funnels with event tracking — track what users do after they arrive
Last updated
Was this helpful?