removed unused analytics event & added logCrash

This commit is contained in:
Vadim 2024-01-27 20:52:10 +01:00
parent 9cb1cbaa90
commit 683b506650
5 changed files with 51 additions and 23 deletions

View file

@ -3,7 +3,6 @@ import 'dart:developer';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:lightmeter/data/analytics/api/analytics_api_interface.dart'; import 'package:lightmeter/data/analytics/api/analytics_api_interface.dart';
import 'package:lightmeter/data/analytics/entity/analytics_event.dart';
class LightmeterAnalytics { class LightmeterAnalytics {
final ILightmeterAnalyticsApi _api; final ILightmeterAnalyticsApi _api;
@ -11,24 +10,35 @@ class LightmeterAnalytics {
const LightmeterAnalytics({required ILightmeterAnalyticsApi api}) : _api = api; const LightmeterAnalytics({required ILightmeterAnalyticsApi api}) : _api = api;
Future<void> logEvent( Future<void> logEvent(
LightmeterAnalyticsEvent event, { String eventName, {
Map<String, dynamic>? parameters, Map<String, dynamic>? parameters,
}) async { }) async {
if (kDebugMode) { if (kDebugMode) {
log('<LightmeterAnalytics> logEvent: ${event.name} / $parameters'); log('<LightmeterAnalytics> logEvent: $eventName / $parameters');
return; return;
} }
return _api.logEvent( return _api.logEvent(
event: event, eventName,
parameters: parameters, parameters: parameters,
); );
} }
Future<void> logUnlockProFeatures(String listTileTitle) async { Future<void> logCrash(
return logEvent( dynamic exception,
LightmeterAnalyticsEvent.unlockProFeatures, StackTrace? stack, {
parameters: {"listTileTitle": listTileTitle}, dynamic reason,
Iterable<Object> information = const [],
}) async {
if (kDebugMode) {
return;
}
return _api.logCrash(
exception,
stack,
reason: reason,
information: information,
); );
} }
} }

View file

@ -1,8 +1,13 @@
import 'package:lightmeter/data/analytics/entity/analytics_event.dart';
abstract class ILightmeterAnalyticsApi { abstract class ILightmeterAnalyticsApi {
Future<void> logEvent({ Future<void> logEvent(
required LightmeterAnalyticsEvent event, String eventName, {
Map<String, dynamic>? parameters, Map<String, dynamic>? parameters,
}); });
Future<void> logCrash(
dynamic exception,
StackTrace? stack, {
dynamic reason,
Iterable<Object> information = const [],
});
} }

View file

@ -1,20 +1,20 @@
import 'package:firebase_analytics/firebase_analytics.dart'; import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:lightmeter/data/analytics/api/analytics_api_interface.dart'; import 'package:lightmeter/data/analytics/api/analytics_api_interface.dart';
import 'package:lightmeter/data/analytics/entity/analytics_event.dart';
class LightmeterAnalyticsFirebase implements ILightmeterAnalyticsApi { class LightmeterAnalyticsFirebase implements ILightmeterAnalyticsApi {
const LightmeterAnalyticsFirebase(); const LightmeterAnalyticsFirebase();
@override @override
Future<void> logEvent({ Future<void> logEvent(
required LightmeterAnalyticsEvent event, String eventName, {
Map<String, dynamic>? parameters, Map<String, dynamic>? parameters,
}) async { }) async {
try { try {
await FirebaseAnalytics.instance.logEvent( await FirebaseAnalytics.instance.logEvent(
name: event.name, name: eventName,
parameters: parameters, parameters: parameters,
); );
} on FirebaseException catch (e) { } on FirebaseException catch (e) {
@ -23,4 +23,20 @@ class LightmeterAnalyticsFirebase implements ILightmeterAnalyticsApi {
debugPrint(e.toString()); debugPrint(e.toString());
} }
} }
@override
Future<void> logCrash(
dynamic exception,
StackTrace? stackTrace, {
dynamic reason,
Iterable<Object> information = const [],
}) async {
FirebaseCrashlytics.instance.recordError(
exception,
stackTrace,
reason: reason,
information: information,
fatal: true,
);
}
} }

View file

@ -1,3 +0,0 @@
enum LightmeterAnalyticsEvent {
unlockProFeatures,
}

View file

@ -73,8 +73,8 @@ class RemoteConfigService implements IRemoteConfigService {
try { try {
final feature = Feature.values.firstWhere((f) => f.name == value.key); final feature = Feature.values.firstWhere((f) => f.name == value.key);
result[feature] = value.value.toValue(feature); result[feature] = value.value.toValue(feature);
} catch (e) { } catch (e, stackTrace) {
log(e.toString()); log(e.toString(), stackTrace: stackTrace);
} }
} }
return result; return result;
@ -88,8 +88,8 @@ class RemoteConfigService implements IRemoteConfigService {
for (final key in event.updatedKeys) { for (final key in event.updatedKeys) {
try { try {
updatedFeatures.add(Feature.values.firstWhere((element) => element.name == key)); updatedFeatures.add(Feature.values.firstWhere((element) => element.name == key));
} catch (e) { } catch (e, stackTrace) {
log(e.toString()); log(e.toString(), stackTrace: stackTrace);
} }
} }
return updatedFeatures; return updatedFeatures;