Flutter SDK
Install and initialize the IForevents Flutter SDK
The iforevents package tracks events from iOS, Android, macOS, Windows, Linux and web apps, and can fan the same events out to Firebase, Mixpanel, Amplitude, Segment, CleverTap, Algolia and Meta.
Installation
Add the package to pubspec.yaml:
dependencies:
iforevents: ^0.1.0Then run flutter pub get.
Initialization
Initialize once, before runApp, with the API integration pointed at your project key:
import 'package:iforevents/iforevents.dart';
final iforevents = Iforevents();
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await iforevents.init(integrations: [
IForeventsAPIIntegration(
config: IForeventsAPIConfig(
projectKey: const String.fromEnvironment('IFOREVENTS_PROJECT_KEY'),
baseUrl: 'https://api.iforevents.com',
),
),
]);
runApp(const MyApp());
}IForeventsAPIConfig also takes batchSize (default 20), batchIntervalMs (10000), retry settings and enableLogging. The key is public by design; keep it out of source control with --dart-define anyway so each environment gets its own.
Identify users
await iforevents.identify(
event: IdentifyEvent(
customID: 'user-123',
properties: {
'email': '[email protected]',
'plan': 'pro',
},
),
);Device brand, model, OS version, app version and platform are collected automatically. The SDK sends X-User-Id on every request: an anonymous id it generates on first launch and keeps in local storage, replaced by customID once you identify, so users behind one carrier or NAT never collapse into one profile.
Track events
// Simple event
iforevents.track(event: TrackEvent(eventName: 'app_opened'));
// With properties
iforevents.track(
event: TrackEvent(
eventName: 'purchase_completed',
properties: {
'product_id': 'prod_123',
'price': 29.99,
'currency': 'USD',
},
),
);Events are queued locally, sent in batches to POST /v1/events/batch and retried on failure.
Screen tracking
Add the navigator observer to record screen views as page_view events:
MaterialApp(
navigatorObservers: [IforeventsNavigatorObserver(iforevents: iforevents)],
);Additional integrations
Each destination is a separate package (iforevents_firebase, iforevents_mixpanel, iforevents_amplitude, iforevents_segment, iforevents_clevertap, iforevents_algolia, iforevents_meta). Pass their integrations in the same init list and every identify/track call reaches all of them.
Troubleshooting
Events not showing up? Check that:
- the project key is the one shown in Settings → Project;
baseUrlishttps://api.iforevents.com(production) orhttps://dev-api.iforevents.com(development), without/v1;- with
enableLogging: truethe log showsPOST /v1/events/batchanswered202; - the organization has not passed its monthly quota (ingest answers
429after the grace period).