5cd9d0ab10
Adds firebase_core + firebase_analytics and a FirebaseAnalyticsBackend that adapts the existing AnalyticsBackend interface to GA4. Kept in its own file so the typed AnalyticsService and DebugAnalyticsBackend stay free of the firebase dependency (unit tests never pull in platform channels). Not yet wired into main() — that needs lib/firebase_options.dart from flutterfire configure (owner step). All 161 tests still green. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
34 lines
1.1 KiB
Dart
34 lines
1.1 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:firebase_analytics/firebase_analytics.dart';
|
|
|
|
import 'analytics_service.dart';
|
|
|
|
/// Routes typed events to Firebase / GA4. Wired in main() for release builds
|
|
/// only; debug builds keep the console logger so development traffic never
|
|
/// pollutes production analytics.
|
|
///
|
|
/// Lives in its own file so [AnalyticsService] and [DebugAnalyticsBackend]
|
|
/// stay free of the firebase_analytics dependency (and so unit tests of the
|
|
/// typed event surface never pull in platform channels).
|
|
class FirebaseAnalyticsBackend implements AnalyticsBackend {
|
|
FirebaseAnalyticsBackend([FirebaseAnalytics? analytics])
|
|
: _analytics = analytics ?? FirebaseAnalytics.instance;
|
|
|
|
final FirebaseAnalytics _analytics;
|
|
|
|
@override
|
|
void logEvent(String name, Map<String, Object> params) {
|
|
// Fire-and-forget: analytics must never block or break gameplay, and a
|
|
// logging failure (offline, quota) is swallowed rather than surfaced.
|
|
unawaited(
|
|
_analytics
|
|
.logEvent(
|
|
name: name,
|
|
parameters: params.isEmpty ? null : params,
|
|
)
|
|
.catchError((Object _) {}),
|
|
);
|
|
}
|
|
}
|