analytics_manager
Simple one-line Firebase Analytics + Remote Config wrapper with event name validation and sanitization.
Features
- One-liner events:
AnalyticsManager().triggerFirebaseEvent('place order') - Validation: Event names are sanitized (spaces/
-→_). If the sanitized name exceeds 40 chars, an error is thrown so you can fix it. - Remote Config helpers:
getString/getBool/getInt/getDoubleandrefreshRemoteConfig() - Single init:
AnalyticsManager().init()initializes Firebase and prepares Remote Config
Getting started
- Add dependency
pubspec.yaml:
dependencies:
analytics_manager: ^1.0.1
- Configure Firebase
- Create your Firebase project in the console
- Add an Android app (package name must match your
applicationId) - Download
google-services.jsonand place it at:android/app/google-services.json - Ensure the Android app builds with the Google Services Gradle plugin
Kotlin DSL (already configured in example):
settings.gradle.ktsincludes:id("com.google.gms.google-services") version "4.4.2" apply falseapp/build.gradle.ktsincludes:id("com.google.gms.google-services")defaultConfig.minSdk = 23
- Initialize at app startup
void main() async {
WidgetsFlutterBinding.ensureInitialized();
final analytics = AnalyticsManager();
await analytics.init(
defaultRemoteConfig: {
'rc_title': 'Welcome',
'rc_subtitle': 'Subtext',
'rc_discount': '10',
'rc_flag': true,
},
);
runApp(const MyApp());
}
Usage
Trigger analytics events
// Spaces and dashes are converted to underscores, max length 40
await AnalyticsManager
().triggerFirebaseEvent
('add to-cart');
// If the sanitized name exceeds 40 chars, an ArgumentError is thrown.
try {
await AnalyticsManager().triggerFirebaseEvent(
'place order',
parameters: {'value': 123},
);
} on ArgumentError catch (e) {
// Handle/report invalid event name during development
debugPrint(e.message);
}
Remote Config
final analytics = AnalyticsManager();
await
analytics.refreshRemoteConfig
();
final title = analytics.getString('rc_title', defaultValue: '');
final enabled = analytics.getBool('rc_flag');
Example
See /example for a minimal app that:
- Initializes the package
- Displays 4 Remote Config values (
rc_title,rc_subtitle,rc_discount,rc_flag) - Has 2 buttons to fire events: Add to Cart and Place Order
Notes
- You must place a valid
google-services.jsonunderandroid/app/in your app to run on Android. - For iOS, add your app in Firebase, download
GoogleService-Info.plist, add to Runner, and enableFirebaseApp.configure()via the FlutterFire guide.
Debugging Analytics
- Use Realtime → DebugView to see events immediately.
- Enable debug mode on a device:
adb shell setprop debug.firebase.analytics.app com.vieappsstudio.analytics- Disable:
adb shell setprop debug.firebase.analytics.app .none.
- Custom events will appear in DebugView instantly but may take up to 24 hours to populate standard reports.
Remote Config tips (development)
- During development, fetch fresh values every time by setting:
await AnalyticsManager().init( defaultRemoteConfig: {...}, minimumFetchInterval: Duration.zero, ); - Publish your RC changes (not just save as draft).