Initialization (Flutter)
Configure the Emp-Mix SDK in your Dart application.
Basic Setup
The EmpAnalytics.init() method is asynchronous because it needs to set up the local SQLite database. It must be awaited before you call runApp().
import 'package:flutter/material.dart';
import 'package:emp_analytics/emp_analytics.dart';
void main() async {
// Required because we are running async code before runApp
WidgetsFlutterBinding.ensureInitialized();
// Initialize Emp-Mix
await EmpAnalytics.init(
'YOUR_PUBLIC_API_KEY',
debug: true,
);
runApp(const MyApp());
}Configuration Options
| Parameter | Type | Required | Description |
|---|---|---|---|
| apiKey | String | Yes | Your project's Public API key. |
| apiHost | String | No | Override the default ingest URL. Useful if proxying requests. |
| debug | bool | No | If true, prints verbose logs to the debug console. Default: false. |
| batchInterval | int | No | Seconds between automatic queue flushes. Default: 30. |
| maxBatchSize | int | No | Max events per batch. Default: 20. |
Automatic Tracking
By default, the Flutter SDK will automatically track the following lifecycle events:
- App Installed: Triggered once when the SQLite database is first created.
- App Opened: Triggered when the app is launched or brought to the foreground.
- App Backgrounded: Triggered when the app is minimized.
- App Updated: Triggered if the package version string changes.