For the complete documentation index, see llms.txt. This page is also available as Markdown.

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 refererUrl 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 refererUrl: URL?
}
  • refererUrl != 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.

  • refererUrl == nil — the install was organic, or attribution wasn't possible.

The result is fetched once over the network and then cached on device, and concurrent calls are de-duplicated — so you can call getAttributionMetadata whenever convenient without extra cost.

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 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
    }
}

Errors

OnsideAttributionMetadataError:

Case
Cause
Suggested handling

.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.

Report if persistent.

Attribution is also available from web content through the JS ↔ Native Bridge as getAttributionMetadata().

Next

Last updated

Was this helpful?