koma_flutter 1.0.1
koma_flutter: ^1.0.1 copied to clipboard
Koma Analytics SDK for Flutter — event tracking, user identification, and user properties with a durable offline queue.
example/main.dart
// A minimal, self-contained usage snippet for the Koma Flutter SDK.
//
// This file exists so pub.dev renders an "Example" tab. The full, runnable
// reference app (multi-screen, live log, screen tracking) lives in the
// monorepo at `apps/koma-flutter-example`.
import 'package:flutter/widgets.dart';
import 'package:koma_flutter/koma_flutter.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
// 1. Initialize once, near app start.
await Koma.init(
KomaConfig(
apiKey: 'YOUR_API_KEY',
apiSecret: 'YOUR_API_SECRET',
debug: true,
onConnectionError: (e) =>
debugPrint('koma connection error [${e.code.name}]: ${e.message}'),
),
);
// 2. Track events (name must exist in your project's tracking plan).
Koma.instance.track('App Started');
Koma.instance.track('Product Viewed', {'product_id': 'p-42'});
// 3. Identify the user; pass null to reset the session.
Koma.instance.identify('user_123');
// 4. Attach user properties.
Koma.instance.setUserProperty({'plan': 'premium', 'country': 'CM'});
// Optional: opt-in automatic screen tracking with an app-supplied mapper.
// MaterialApp(
// navigatorObservers: [
// KomaNavigatorObserver(
// mapper: (route) {
// final name = route.settings.name;
// if (name == null) return null;
// return KomaScreenEvent('Page Viewed', {'page_name': name});
// },
// ),
// ],
// );
}