trackLifecycleEvent method
Track app lifecycle events
Automatically track important app lifecycle events like app start, app background, app foreground, etc.
Example:
await client.trackLifecycleEvent('app_launched', {
'launch_time': DateTime.now().toIso8601String(),
'cold_start': true,
});
Implementation
Future<CFResult<bool>> trackLifecycleEvent(
String lifecycleEvent,
Map<String, dynamic> context,
) async {
try {
Logger.d('🔔 Tracking lifecycle event: $lifecycleEvent');
final properties = {
...context,
'_lifecycle_event': lifecycleEvent,
'_app_version': 'unknown', // Could be extracted from PackageInfo
'_platform': 'flutter',
};
return await trackEventWithProperties(
'app_lifecycle',
properties,
);
} catch (e) {
final errorMsg = 'Error tracking lifecycle event "$lifecycleEvent": $e';
Logger.e('🔔 $errorMsg');
return CFResult.error(errorMsg);
}
}