feat: integrate Firebase Analytics, add Google Maps dependencies, and expose new GA4 metric API endpoints.

This commit is contained in:
Van Leemput Dayron
2026-01-02 17:10:03 +01:00
parent 5a682bb6d7
commit a9c3087f53
6 changed files with 304 additions and 6 deletions

View File

@@ -26,12 +26,14 @@ import '../../repositories/auth_repository.dart';
import 'auth_event.dart';
import 'auth_state.dart';
import '../../services/notification_service.dart';
import '../../services/analytics_service.dart';
/// BLoC for managing authentication state and operations.
class AuthBloc extends Bloc<AuthEvent, AuthState> {
/// Repository for authentication operations.
final AuthRepository _authRepository;
final NotificationService _notificationService;
final AnalyticsService _analyticsService;
/// Creates an [AuthBloc] with the provided [authRepository].
///
@@ -40,8 +42,10 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
AuthBloc({
required AuthRepository authRepository,
NotificationService? notificationService,
AnalyticsService? analyticsService,
}) : _authRepository = authRepository,
_notificationService = notificationService ?? NotificationService(),
_analyticsService = analyticsService ?? AnalyticsService(),
super(AuthInitial()) {
on<AuthCheckRequested>(_onAuthCheckRequested);
on<AuthSignInRequested>(_onSignInRequested);
@@ -76,6 +80,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
if (user != null) {
// Save FCM Token on auto-login
await _notificationService.saveTokenToFirestore(user.id!);
await _analyticsService.setUserId(user.id);
emit(AuthAuthenticated(user: user));
} else {
emit(AuthUnauthenticated());
@@ -107,6 +112,11 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
if (user != null) {
// Save FCM Token
await NotificationService().saveTokenToFirestore(user.id!);
await _analyticsService.setUserId(user.id);
await _analyticsService.logEvent(
name: 'login',
parameters: {'method': 'email'},
);
emit(AuthAuthenticated(user: user));
} else {
emit(const AuthError(message: 'Invalid email or password'));
@@ -138,6 +148,11 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
if (user != null) {
// Save FCM Token
await NotificationService().saveTokenToFirestore(user.id!);
await _analyticsService.setUserId(user.id);
await _analyticsService.logEvent(
name: 'sign_up',
parameters: {'method': 'email'},
);
emit(AuthAuthenticated(user: user));
} else {
emit(const AuthError(message: 'Failed to create account'));
@@ -163,6 +178,11 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
if (user != null) {
// Save FCM Token
await NotificationService().saveTokenToFirestore(user.id!);
await _analyticsService.setUserId(user.id);
await _analyticsService.logEvent(
name: 'login',
parameters: {'method': 'google'},
);
emit(AuthAuthenticated(user: user));
} else {
emit(
@@ -191,6 +211,11 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
);
if (user != null) {
await _analyticsService.setUserId(user.id);
await _analyticsService.logEvent(
name: 'sign_up',
parameters: {'method': 'google'},
);
emit(AuthAuthenticated(user: user));
} else {
emit(const AuthError(message: 'Failed to create account with Google'));
@@ -214,6 +239,11 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
);
if (user != null) {
await _analyticsService.setUserId(user.id);
await _analyticsService.logEvent(
name: 'sign_up',
parameters: {'method': 'apple'},
);
emit(AuthAuthenticated(user: user));
} else {
emit(const AuthError(message: 'Failed to create account with Apple'));
@@ -239,6 +269,11 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
if (user != null) {
// Save FCM Token
await NotificationService().saveTokenToFirestore(user.id!);
await _analyticsService.setUserId(user.id);
await _analyticsService.logEvent(
name: 'login',
parameters: {'method': 'apple'},
);
emit(AuthAuthenticated(user: user));
} else {
emit(
@@ -261,6 +296,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
Emitter<AuthState> emit,
) async {
await _authRepository.signOut();
await _analyticsService.setUserId(null); // Clear user ID
emit(AuthUnauthenticated());
}