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

ParameterTypeRequiredDescription
apiKeyStringYesYour project's Public API key.
apiHostStringNoOverride the default ingest URL. Useful if proxying requests.
debugboolNoIf true, prints verbose logs to the debug console. Default: false.
batchIntervalintNoSeconds between automatic queue flushes. Default: 30.
maxBatchSizeintNoMax 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.
Last updated on June 4, 2026