diff --git a/lib/data/analytics/analytics.dart b/lib/data/analytics/analytics.dart index 1bd6496..9920311 100644 --- a/lib/data/analytics/analytics.dart +++ b/lib/data/analytics/analytics.dart @@ -3,7 +3,6 @@ import 'dart:developer'; import 'package:flutter/foundation.dart'; import 'package:lightmeter/data/analytics/api/analytics_api_interface.dart'; -import 'package:lightmeter/data/analytics/entity/analytics_event.dart'; class LightmeterAnalytics { final ILightmeterAnalyticsApi _api; @@ -11,24 +10,35 @@ class LightmeterAnalytics { const LightmeterAnalytics({required ILightmeterAnalyticsApi api}) : _api = api; Future logEvent( - LightmeterAnalyticsEvent event, { + String eventName, { Map? parameters, }) async { if (kDebugMode) { - log(' logEvent: ${event.name} / $parameters'); + log(' logEvent: $eventName / $parameters'); return; } return _api.logEvent( - event: event, + eventName, parameters: parameters, ); } - Future logUnlockProFeatures(String listTileTitle) async { - return logEvent( - LightmeterAnalyticsEvent.unlockProFeatures, - parameters: {"listTileTitle": listTileTitle}, + Future logCrash( + dynamic exception, + StackTrace? stack, { + dynamic reason, + Iterable information = const [], + }) async { + if (kDebugMode) { + return; + } + + return _api.logCrash( + exception, + stack, + reason: reason, + information: information, ); } } diff --git a/lib/data/analytics/api/analytics_api_interface.dart b/lib/data/analytics/api/analytics_api_interface.dart index 1aa007f..5c8f013 100644 --- a/lib/data/analytics/api/analytics_api_interface.dart +++ b/lib/data/analytics/api/analytics_api_interface.dart @@ -1,8 +1,13 @@ -import 'package:lightmeter/data/analytics/entity/analytics_event.dart'; - abstract class ILightmeterAnalyticsApi { - Future logEvent({ - required LightmeterAnalyticsEvent event, + Future logEvent( + String eventName, { Map? parameters, }); + + Future logCrash( + dynamic exception, + StackTrace? stack, { + dynamic reason, + Iterable information = const [], + }); } diff --git a/lib/data/analytics/api/analytics_firebase.dart b/lib/data/analytics/api/analytics_firebase.dart index fb11d02..691e393 100644 --- a/lib/data/analytics/api/analytics_firebase.dart +++ b/lib/data/analytics/api/analytics_firebase.dart @@ -1,20 +1,20 @@ import 'package:firebase_analytics/firebase_analytics.dart'; import 'package:firebase_core/firebase_core.dart'; +import 'package:firebase_crashlytics/firebase_crashlytics.dart'; import 'package:flutter/foundation.dart'; import 'package:lightmeter/data/analytics/api/analytics_api_interface.dart'; -import 'package:lightmeter/data/analytics/entity/analytics_event.dart'; class LightmeterAnalyticsFirebase implements ILightmeterAnalyticsApi { const LightmeterAnalyticsFirebase(); @override - Future logEvent({ - required LightmeterAnalyticsEvent event, + Future logEvent( + String eventName, { Map? parameters, }) async { try { await FirebaseAnalytics.instance.logEvent( - name: event.name, + name: eventName, parameters: parameters, ); } on FirebaseException catch (e) { @@ -23,4 +23,20 @@ class LightmeterAnalyticsFirebase implements ILightmeterAnalyticsApi { debugPrint(e.toString()); } } + + @override + Future logCrash( + dynamic exception, + StackTrace? stackTrace, { + dynamic reason, + Iterable information = const [], + }) async { + FirebaseCrashlytics.instance.recordError( + exception, + stackTrace, + reason: reason, + information: information, + fatal: true, + ); + } } diff --git a/lib/data/analytics/entity/analytics_event.dart b/lib/data/analytics/entity/analytics_event.dart deleted file mode 100644 index 8275869..0000000 --- a/lib/data/analytics/entity/analytics_event.dart +++ /dev/null @@ -1,3 +0,0 @@ -enum LightmeterAnalyticsEvent { - unlockProFeatures, -} diff --git a/lib/data/remote_config_service.dart b/lib/data/remote_config_service.dart index 1ae86ef..5159a2b 100644 --- a/lib/data/remote_config_service.dart +++ b/lib/data/remote_config_service.dart @@ -73,8 +73,8 @@ class RemoteConfigService implements IRemoteConfigService { try { final feature = Feature.values.firstWhere((f) => f.name == value.key); result[feature] = value.value.toValue(feature); - } catch (e) { - log(e.toString()); + } catch (e, stackTrace) { + log(e.toString(), stackTrace: stackTrace); } } return result; @@ -88,8 +88,8 @@ class RemoteConfigService implements IRemoteConfigService { for (final key in event.updatedKeys) { try { updatedFeatures.add(Feature.values.firstWhere((element) => element.name == key)); - } catch (e) { - log(e.toString()); + } catch (e, stackTrace) { + log(e.toString(), stackTrace: stackTrace); } } return updatedFeatures;