API Reference
B2MetricSDK
Main SDK class for tracking events.
getInstance(context: Context): B2MetricSDK
Returns the singleton SDK instance.
Parameters:
context: Application or Activity context
val sdk = B2MetricSDK.getInstance(applicationContext)
start(config: B2MetricAnalyticsConfig)
Initializes and configures the SDK.
Parameters:
config: Configuration object with SDK settings
sdk.start(
B2MetricAnalyticsConfig(
apiKey = "YOUR_API_KEY",
batchSize = 20
)
)
logEvent(name: String, properties: Map<String, Any>? = null)
Tracks a custom event with optional properties.
Parameters:
name: Event name (required)properties: Event properties (optional)
sdk.logEvent(
name = "button_clicked",
properties = mapOf("screen" to "home")
)
registerPushToken(token: String, provider: PushProvider)
Registers a push notification token and logs a push_token event.
Parameters:
token: FCM or HMS tokenprovider:PushProvider.FCMorPushProvider.HMS
sdk.registerPushToken(fcmToken, PushProvider.FCM)
trackPushOpened(data: Map<String, String>)
Tracks push notification open and logs a push_opened event.
Parameters:
data: Push notification data payload
override fun onMessageReceived(remoteMessage: RemoteMessage) {
sdk.trackPushOpened(remoteMessage.data)
}
B2MetricAnalyticsConfig
Configuration data class.
| Parameter | Type | Default | Range | Description |
|---|---|---|---|---|
apiKey | String | - | - | Required. Your B2Metric API key |
batchSize | Int | 20 | 1-100 | Batch size for event sending |
flushIntervalSeconds | Long | 30 | 1-3600 | Time between automatic flushes |
maxRetries | Int | 3 | 1-10 | Maximum retry attempts |
assumedSessionTimeInMinutes | Int | 30 | 1-10080 | Session timeout duration |
b2MetricAnalyticsLogLevel | LogLevel | OFF | - | Logging level |
PushProvider
Enum for push notification providers.
PushProvider.FCM— Firebase Cloud MessagingPushProvider.HMS— Huawei Mobile Services
B2MetricAnalyticsLogLevel
Enum for log levels.
| Value | Description |
|---|---|
OFF | No logging |
ERROR | Errors only |
WARNING | Errors and warnings |
INFO | General information |
DEBUG | Detailed debug information |