Installation
Requirements
- iOS 13.0+
- Swift 5.0+
- Xcode 12.0+
Add via Swift Package Manager
- In Xcode, select File → Add Packages...
- Enter the repository URL:
https://github.com/b2metric - Choose the version you need
- Add
B2MetricAnalyticsSDKto your app target
Initialize the SDK
Initialize the SDK in your AppDelegate.swift as early as possible:
import UIKit
import B2MetricAnalyticsSDK
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
// Set log level (optional)
B2MetricAnalytics.shared.logLevel = .debug
// Start the SDK
B2MetricAnalytics.shared.start(
apiKey: "YOUR_API_KEY",
batchSize: 20,
flushInterval: 30
)
return true
}
}
Configuration Options
| Parameter | Description | Default | Type |
|---|---|---|---|
apiKey | Required. Your B2Metric API key. Must be non-empty. | - | String |
batchSize | Number of events to batch before sending. | 20 | Int |
flushInterval | Time in seconds between automatic flushes. | 30 | TimeInterval |
Example Configurations
Development:
B2MetricAnalytics.shared.logLevel = .debug
B2MetricAnalytics.shared.start(
apiKey: "YOUR_DEV_API_KEY",
batchSize: 1, // Send immediately
flushInterval: 5
)
Production:
B2MetricAnalytics.shared.logLevel = .off
B2MetricAnalytics.shared.start(
apiKey: "YOUR_PROD_API_KEY",
batchSize: 50,
flushInterval: 60
)