Skip to main content

Overview

The B2Metric Flutter SDK is the official client library for sending analytics data from Flutter applications to the B2Metric platform. It is designed to be a complete, drop-in solution: it captures user interactions as events, manages user sessions automatically, registers push notification tokens, and handles the entire delivery pipeline — batching, retry logic, offline persistence — without requiring any additional setup.

The SDK ships as a single Dart package with zero third-party runtime dependencies. It runs natively on both Android and iOS through the same unified API, so the integration code in your application stays identical across platforms. Once initialized, the SDK runs in the background, intercepts your event calls, and delivers them efficiently to the B2Metric backend with minimal impact on battery life and network usage.

The package is published on pub.dev and can be installed with the standard Flutter package manager. The latest version and complete release history are available at pub.dev/packages/b2metric_sdk.

What You Can Do With This SDK

The SDK is built around three core capabilities, each described in detail in its own section of this guide:

  • Track custom events — log any user action (a screen view, a button tap, a purchase) along with structured properties and, optionally, an array of item-level details for e-commerce scenarios.
  • Manage user sessions — the SDK automatically detects when a session starts and ends based on app foreground/background transitions and a configurable inactivity timeout. You do not need to instrument any of this yourself.
  • Track push notifications — register a device token from FCM, HMS, or APNS and report when a push notification opens the application, including any campaign metadata you want to attach.

Features

  • Custom event tracking with properties and item-level data
  • Automatic session management (first_open, session_start, session_end)
  • Push notification token registration (FCM, HMS, APNS) and open tracking
  • Offline event queueing with persistent storage — no events are lost when the device is offline
  • Automatic batching, exponential backoff retry, and network-aware delivery
  • Automatic device and app metadata collection (OS version, device model, app version, locale)
  • Configurable log levels for debugging during development
  • Zero third-party dependencies — only the Flutter SDK is required

How It Works

When your application calls a tracking method such as logEvent(), the SDK does not send the event immediately. Instead, it enriches the event with automatic context (timestamp, session ID, device metadata) and places it into an in-memory queue that is also persisted to local storage. A background worker then groups queued events into batches and ships them to the B2Metric ingestion endpoint on a periodic schedule, or when the queue reaches the configured batch size — whichever comes first.

If the device is offline or the network request fails, events remain in the persistent queue and are retried with exponential backoff. This means you can call logEvent() safely from anywhere in your code — inside background tasks, during connectivity loss, even right before the app is killed — and trust that the data will eventually reach the platform.

Requirements

  • Flutter >= 3.10
  • iOS 13+ · Android API 24+
  • A valid B2Metric API key