mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-25 17:00:39 +00:00
removed unused analytics event & added logCrash
This commit is contained in:
parent
9cb1cbaa90
commit
683b506650
5 changed files with 51 additions and 23 deletions
|
@ -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<void> logEvent(
|
||||
LightmeterAnalyticsEvent event, {
|
||||
String eventName, {
|
||||
Map<String, dynamic>? parameters,
|
||||
}) async {
|
||||
if (kDebugMode) {
|
||||
log('<LightmeterAnalytics> logEvent: ${event.name} / $parameters');
|
||||
log('<LightmeterAnalytics> logEvent: $eventName / $parameters');
|
||||
return;
|
||||
}
|
||||
|
||||
return _api.logEvent(
|
||||
event: event,
|
||||
eventName,
|
||||
parameters: parameters,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> logUnlockProFeatures(String listTileTitle) async {
|
||||
return logEvent(
|
||||
LightmeterAnalyticsEvent.unlockProFeatures,
|
||||
parameters: {"listTileTitle": listTileTitle},
|
||||
Future<void> logCrash(
|
||||
dynamic exception,
|
||||
StackTrace? stack, {
|
||||
dynamic reason,
|
||||
Iterable<Object> information = const [],
|
||||
}) async {
|
||||
if (kDebugMode) {
|
||||
return;
|
||||
}
|
||||
|
||||
return _api.logCrash(
|
||||
exception,
|
||||
stack,
|
||||
reason: reason,
|
||||
information: information,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
import 'package:lightmeter/data/analytics/entity/analytics_event.dart';
|
||||
|
||||
abstract class ILightmeterAnalyticsApi {
|
||||
Future<void> logEvent({
|
||||
required LightmeterAnalyticsEvent event,
|
||||
Future<void> logEvent(
|
||||
String eventName, {
|
||||
Map<String, dynamic>? parameters,
|
||||
});
|
||||
|
||||
Future<void> logCrash(
|
||||
dynamic exception,
|
||||
StackTrace? stack, {
|
||||
dynamic reason,
|
||||
Iterable<Object> information = const [],
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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<void> logEvent({
|
||||
required LightmeterAnalyticsEvent event,
|
||||
Future<void> logEvent(
|
||||
String eventName, {
|
||||
Map<String, dynamic>? 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<void> logCrash(
|
||||
dynamic exception,
|
||||
StackTrace? stackTrace, {
|
||||
dynamic reason,
|
||||
Iterable<Object> information = const [],
|
||||
}) async {
|
||||
FirebaseCrashlytics.instance.recordError(
|
||||
exception,
|
||||
stackTrace,
|
||||
reason: reason,
|
||||
information: information,
|
||||
fatal: true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
enum LightmeterAnalyticsEvent {
|
||||
unlockProFeatures,
|
||||
}
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue