### Initialization Source: https://github.com/aptabase/aptabase-swift/blob/main/llms.txt Initialize the Aptabase SDK as early as possible in your application's lifecycle. This example shows initialization for SwiftUI apps. ```APIDOC ## Initialization Initialize the SDK as early as possible in your app: ```swift import SwiftUI import Aptabase @main struct MyApp: App { init() { Aptabase.shared.initialize(appKey: "") } var body: some Scene { WindowGroup { ContentView() } } } ``` For UIKit apps: ```swift import UIKit import Aptabase @main class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { Aptabase.shared.initialize(appKey: "") return true } } ``` ``` -------------------------------- ### Configuration Source: https://github.com/aptabase/aptabase-swift/blob/main/llms.txt Customize SDK behavior using `InitOptions` during initialization. This includes setting a custom host for self-hosted instances, adjusting the flush interval, and controlling the tracking mode. ```APIDOC ## Configuration Pass `InitOptions` to customize behavior: ```swift let options = InitOptions( host: "https://your-self-hosted-instance.com", // For self-hosted Aptabase flushInterval: 30, // Custom flush interval in seconds trackingMode: .asRelease // Force release mode ) Aptabase.shared.initialize(appKey: "", with: options) ``` - `host` — Custom server URL for self-hosted Aptabase instances (required for `A-SH-*` app keys) - `flushInterval` — Interval in seconds for batching and sending events (default: automatic) - `trackingMode` — `.readFromEnvironment` (default), `.asDebug`, or `.asRelease` ``` -------------------------------- ### Initialize Aptabase with Custom Options Source: https://github.com/aptabase/aptabase-swift/blob/main/llms.txt Customize Aptabase SDK behavior by passing InitOptions during initialization. This is useful for self-hosted instances or adjusting the flush interval. ```swift let options = InitOptions( host: "https://your-self-hosted-instance.com", // For self-hosted Aptabase flushInterval: 30, // Custom flush interval in seconds trackingMode: .asRelease // Force release mode ) Aptabase.shared.initialize(appKey: "", with: options) ``` -------------------------------- ### Initialize Aptabase SDK in SwiftUI App Source: https://github.com/aptabase/aptabase-swift/blob/main/README.md Initialize the Aptabase SDK early in your application's lifecycle, typically in the `init` method of your main App struct. Ensure you replace "" with your actual Aptabase App Key. ```swift import SwiftUI import Aptabase @main struct ExampleApp: App { init() { Aptabase.shared.initialize(appKey: "") // 👈 this is where you enter your App Key } var body: some Scene { WindowGroup { MainView() } } } ``` -------------------------------- ### Initialize Aptabase SDK in UIKit App Source: https://github.com/aptabase/aptabase-swift/blob/main/llms.txt Initialize the Aptabase SDK in your UIKit application's AppDelegate. Replace '' with your actual Aptabase App Key. ```swift import UIKit import Aptabase @main class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { Aptabase.shared.initialize(appKey: "") return true } } ``` -------------------------------- ### Add Aptabase Dependency to Package.swift Source: https://github.com/aptabase/aptabase-swift/blob/main/README.md Use Swift Package Manager to add the Aptabase SDK as a dependency in your Package.swift file. ```swift let package = Package( ... dependencies: [ ... .package(name: "Aptabase", url: "https://github.com/aptabase/aptabase-swift.git", from: "0.3.4"), ], targets: [ .target( name: "MyApp", dependencies: ["Aptabase"] // Add as a dependency ) ] ) ``` -------------------------------- ### Add Aptabase Dependency via CocoaPods Source: https://github.com/aptabase/aptabase-swift/blob/main/README.md Integrate the Aptabase SDK into your project using CocoaPods by adding the specified line to your Podfile. ```ruby pod 'Aptabase', :git => 'https://github.com/aptabase/aptabase-swift.git', :tag => '0.3.4' ``` -------------------------------- ### Track Events with Aptabase SDK Source: https://github.com/aptabase/aptabase-swift/blob/main/README.md Use the `trackEvent` function to send events to Aptabase. Events can be simple strings or include custom properties. Only string and number values are allowed for properties. This operation is non-blocking. ```swift import Aptabase Aptabase.shared.trackEvent("app_started") // An event with no properties Aptabase.shared.trackEvent("screen_view", with: ["name": "Settings"]) // An event with a custom property ``` -------------------------------- ### Track Events with Properties Source: https://github.com/aptabase/aptabase-swift/blob/main/llms.txt Track events with associated properties to provide more context. Allowed property types are strings, numbers, and booleans. ```swift Aptabase.shared.trackEvent("screen_view", with: ["name": "Settings"]) Aptabase.shared.trackEvent("purchase", with: ["amount": 9.99, "currency": "USD"]) Aptabase.shared.trackEvent("level_complete", with: ["level": 5, "score": 1200]) ``` -------------------------------- ### Force Send Events Source: https://github.com/aptabase/aptabase-swift/blob/main/llms.txt Immediately send any queued events without waiting for the next flush interval. ```APIDOC ## Force Send Events To force-send queued events immediately: ```swift Aptabase.shared.flush() ``` ``` -------------------------------- ### Force Send Queued Events Source: https://github.com/aptabase/aptabase-swift/blob/main/llms.txt Immediately send any events that are currently queued by the SDK. This can be useful before an app is terminated. ```swift Aptabase.shared.flush() ``` -------------------------------- ### Track Events with Properties Source: https://github.com/aptabase/aptabase-swift/blob/main/llms.txt Track events and associate them with custom properties. Allowed property types are strings, numbers (Int, Double, Float), and booleans. ```APIDOC ## Track Events with Properties ```swift Aptabase.shared.trackEvent("screen_view", with: ["name": "Settings"]) Aptabase.shared.trackEvent("purchase", with: ["amount": 9.99, "currency": "USD"]) Aptabase.shared.trackEvent("level_complete", with: ["level": 5, "score": 1200]) ``` ``` -------------------------------- ### Track Basic Events Source: https://github.com/aptabase/aptabase-swift/blob/main/llms.txt Manually track events in your application using the trackEvent function. No events are tracked automatically. ```swift import Aptabase Aptabase.shared.trackEvent("app_started") Aptabase.shared.trackEvent("screen_view") ``` -------------------------------- ### Track Events Source: https://github.com/aptabase/aptabase-swift/blob/main/llms.txt Manually track events in your application. No events are tracked automatically. ```APIDOC ## Track Events ```swift import Aptabase Aptabase.shared.trackEvent("app_started") Aptabase.shared.trackEvent("screen_view") ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.