Skip to main content

API Reference

This section is a complete listing of every public method and enum exposed by the SDK. Each previous section in this guide covers when and how to use these methods in practice; this one is the quick-lookup reference you can come back to after you've integrated the SDK and just need to remember a signature.

The full, generated DartDoc API reference including parameter-by-parameter documentation is available at pub.dev/documentation/b2metric_sdk/latest.

B2Metric.instance

All SDK access goes through the singleton B2Metric.instance. The singleton is safe to access from anywhere in your application after init() has completed.

MethodSignatureDescription
initFuture<void> init(B2MetricConfig config)Initializes the SDK. Must be called once, before any other method.
logEventvoid logEvent(String name, {Map<String, dynamic>? properties, List<Map<String, dynamic>>? itemProperties})Enqueues an event for delivery.
registerPushTokenvoid registerPushToken(String token, PushProvider provider)Registers a push notification token. Call this whenever the token is generated or refreshed.
trackPushOpenedvoid trackPushOpened([Map<String, dynamic>? metadata])Marks that a push notification was opened, with optional campaign metadata.
flushFuture<void> flush()Sends all queued events immediately. Returns when the network request completes.
destroyFuture<void> destroy()Releases SDK resources. After this returns, init() must be called again before further use.

Enumerations

LogLevel

Controls how verbose the SDK's console output is. Increasing the level adds messages on top of all the lower levels — LogLevel.debug includes everything below it. Set via B2MetricConfig.logLevel at initialization.

  • LogLevel.off — no logging (default — recommended for production)
  • LogLevel.error — errors only
  • LogLevel.warning — warnings and errors
  • LogLevel.info — informational logs about the SDK's internal state
  • LogLevel.debug — all logs, including individual event payloads (recommended during development)

PushProvider

Identifies the push notification provider that generated a token. Pass the matching value to registerPushToken() so the B2Metric platform can route notifications back through the correct provider.

  • PushProvider.fcm — Firebase Cloud Messaging — the default on most Android devices
  • PushProvider.hms — Huawei Mobile Services — for Huawei devices without Google Play services
  • PushProvider.apns — Apple Push Notification Service — used on all iOS devices