umami_flutter 0.1.1
umami_flutter: ^0.1.1 copied to clipboard
A lightweight Flutter package for Umami analytics with non-blocking initialization and automatic device info collection.
umami_flutter #
A lightweight Flutter package for Umami analytics with non-blocking initialization and automatic device info collection.
Features #
- π Non-blocking init β
init()returns immediately; events tracked before initialization completes are automatically queued and flushed. - π± Automatic device info β Collects device ID, locale, and screen resolution out of the box.
- π Persistent device IDs β Uses platform-specific identifiers (Android ID,
identifierForVendor, etc.) persisted in secure storage (Keychain / EncryptedSharedPreferences) to survive app reinstalls. - π₯ Fire-and-forget tracking β
trackScreenandtrackEventnever block the UI thread. - π₯οΈ Multi-platform β Supports Android, iOS, macOS, and Windows.
- πͺ΅ Optional debug logging β Enable verbose logs during development with a single flag.
- β οΈ Error monitoring β Optional
onErrorcallback for production health checks. - π Configurable User-Agent β Override the default browser UA string if needed.
Getting Started #
Installation #
Add umami_flutter to your pubspec.yaml:
dependencies:
umami_flutter:
git:
url: https://github.com/hamzache497/umami_flutter.git
Then run:
flutter pub get
Platform Setup #
Android
No additional setup required. The package uses android_id and EncryptedSharedPreferences internally.
iOS / macOS
Keychain access is used for persistent device IDs. No extra entitlements are needed beyond the defaults.
Usage #
1. Initialize at app startup #
Call init() once, typically in your main() or a splash screen. It returns immediately and never blocks.
import 'package:umami_flutter/umami_flutter.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
UmamiAnalytics.init(
websiteId: 'your-website-id',
serverUrl: 'https://your-umami.example.com',
hostname: 'myapp',
enableLogging: true, // optional, prints debug logs
onError: (e) => debugPrint('Analytics error: $e'), // optional
);
runApp(MyApp());
}
2. Track screen views #
UmamiAnalytics.trackScreen('HomeScreen');
3. Track custom events #
UmamiAnalytics.trackEvent('purchase', data: {'plan': 'pro', 'price': 9.99});
Note: Both
trackScreenandtrackEventare safe to call beforeinit()finishes β events are queued automatically and sent once the client is ready.
API Reference #
| Method | Description |
|---|---|
UmamiAnalytics.init(...) |
Starts background device-info collection and prepares the HTTP client. Returns immediately. |
UmamiAnalytics.trackScreen(String screenName) |
Sends a page-view event for the given screen name. |
UmamiAnalytics.trackEvent(String eventName, {Map? data}) |
Sends a custom event with an optional data payload. |
UmamiAnalytics.reset() |
Resets internal state, allowing init() to be called again. Primarily for testing. |
UmamiAnalytics.isInitialized |
Whether init() has been called and hasn't failed. |
DeviceIdService.getId() |
Returns the persistent device ID (also accessible independently). |
init() Parameters #
| Parameter | Required | Description |
|---|---|---|
websiteId |
β | Website ID from your Umami dashboard. |
serverUrl |
β | Base URL of your Umami instance. |
hostname |
β | Logical hostname for this app. |
enableLogging |
β | Print debug logs to console. Default: false. |
onError |
β | Callback invoked on init or send failures. |
userAgent |
β | Custom User-Agent string override. |
Supported platforms: Android, iOS, macOS, Windows. Flutter Web is not supported (the package uses
dart:io).
Architecture #
umami_flutter.dart β Public barrel export
ββ src/
ββ umami_analytics.dart β Static API (init, trackScreen, trackEvent)
ββ umami_client.dart β HTTP client for Umami /api/send endpoint
ββ device_info.dart β Collects device ID, locale, screen resolution
ββ device_id_service.dartβ Persistent device ID (Keychain / SecureStorage)
Dependencies #
| Package | Purpose |
|---|---|
http |
HTTP requests to the Umami server |
device_info_plus |
Platform-specific device identifiers |
android_id |
Android device ID |
flutter_secure_storage |
Persistent secure storage for device IDs |
uuid |
UUID v4 fallback for device IDs |
License #
See LICENSE for details.