Skip to main content

Quick Start

This section shows the absolute minimum code required to get the SDK running and to send your first event to the B2Metric platform. Use it as a smoke test after installation — once you see an event arriving in your dashboard, you know the integration is working and you can start instrumenting the rest of your application.

There are exactly three things you need to do: ensure the Flutter binding is initialized, call B2Metric.instance.init() with your API key, and then call any tracking method such as logEvent(). The init call must complete before the rest of your application starts firing events, which is why the example below uses await inside main():

import 'package:b2metric_sdk/b2metric_sdk.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();

// Initialize at app startup
await B2Metric.instance.init(
const B2MetricConfig(apiKey: 'YOUR_API_KEY'),
);

// Track an event
B2Metric.instance.logEvent('button_click', properties: {
'screen': 'home',
});

runApp(const MyApp());
}
IMPORTANT

Call init() exactly once, at application startup, before invoking any other SDK method. Subsequent init() calls are ignored — no additional configuration is applied. To change configuration at runtime, call destroy() first and then init() again with the new config.