Skip to main content

Installation

Requirements

  • iOS 13.0+
  • Swift 5.0+
  • Xcode 12.0+

Add via Swift Package Manager

  1. In Xcode, select File → Add Packages...
  2. Enter the repository URL:
    https://github.com/b2metric
  3. Choose the version you need
  4. Add B2MetricAnalyticsSDK to 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

ParameterDescriptionDefaultType
apiKeyRequired. Your B2Metric API key. Must be non-empty.-String
batchSizeNumber of events to batch before sending.20Int
flushIntervalTime in seconds between automatic flushes.30TimeInterval

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
)