Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions modules/common/lib/analytics/abstract/analytics_client.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/// Additional method to track custom events with a specific type.
/// Follow the naming convention for event types.
/// Future trackInitLoginFlow() => trackEvent('init_login', properties: {...});
/// Future trackErrorLogin() => trackEvent('error_login', properties: {...});

abstract class AnalyticsClient {
/// Tracks an event with a function call and a name.
/// This is useful for tracking events that are triggered by specific actions.
/// Example usage:
/// trackFunction(() => loginWithEmailPassword(email, password), 'login_triggered', properties: {email: email});
Copy link
Preview

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example shows tracking email addresses in analytics properties, which could be sensitive user data. Consider using hashed identifiers or removing PII from analytics examples to avoid accidental data exposure.

Suggested change
/// trackFunction(() => loginWithEmailPassword(email, password), 'login_triggered', properties: {email: email});
/// trackFunction(() => loginWithEmailPassword(email, password), 'login_triggered', properties: {user_id: hashedUserId});

Copilot uses AI. Check for mistakes.

Future trackFunction(
Copy link
Preview

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Function type is too generic and doesn't provide type safety. Consider using FutureOr Function() or separate methods for sync/async functions to ensure proper type checking and runtime behavior.

Copilot uses AI. Check for mistakes.

Function fn,
String name, {
Map<String, dynamic>? properties,
});

Future trackEvent(String name, {Map<String, dynamic>? properties});

Future setUserId(String? userId);

Future setUserProperties(Map<String, dynamic> properties);

Future setUserProperty(String name, String value);

Future reset();

Future trackAppCreated();

Future trackAppUpdated();

Future trackAppDeleted();
}
58 changes: 58 additions & 0 deletions modules/common/lib/analytics/concrete/firebase_analytics.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import 'package:common/analytics/abstract/analytics_client.dart';

class FirebaseAnalytics implements AnalyticsClient {
@override
Future reset() {
// TODO: implement reset
throw UnimplementedError();
}

@override
Future setUserId(String? userId) {
// TODO: implement setUserId
throw UnimplementedError();
}

@override
Future setUserProperties(Map<String, dynamic> properties) {
// TODO: implement setUserProperties
throw UnimplementedError();
}

@override
Future setUserProperty(String name, String value) {
// TODO: implement setUserProperty
throw UnimplementedError();
}

@override
Future trackAppCreated() {
// TODO: implement trackAppCreated
throw UnimplementedError();
}

@override
Future trackAppDeleted() {
// TODO: implement trackAppDeleted
throw UnimplementedError();
}

@override
Future trackAppUpdated() {
// TODO: implement trackAppUpdated
throw UnimplementedError();
}

@override
Future trackEvent(String name, {Map<String, dynamic>? properties}) {
// TODO: implement trackEvent
throw UnimplementedError();
}

@override
Future trackFunction(
Function fn,
String name, {
Map<String, dynamic>? properties,
}) => fn().then((_) => trackEvent(name, properties: properties));
Copy link
Preview

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The trackFunction implementation assumes fn() returns a Future, but the Function type doesn't guarantee this. This will cause a runtime error if fn() returns a non-Future value. Consider using FutureOr or handle both sync and async functions properly.

Suggested change
Function fn,
String name, {
Map<String, dynamic>? properties,
}) => fn().then((_) => trackEvent(name, properties: properties));
FutureOr<void> Function() fn,
String name, {
Map<String, dynamic>? properties,
}) => Future.value(fn()).then((_) => trackEvent(name, properties: properties));

Copilot uses AI. Check for mistakes.

}
7 changes: 7 additions & 0 deletions modules/common/lib/analytics/setup_analytics.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

class SetupAnalytics {
static void initialize() {
// Initialize analytics services here
print("Analytics services initialized.");
Copy link
Preview

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using print() statements for logging is not recommended in production code. Consider using a proper logging framework or removing debug prints before production deployment.

Copilot uses AI. Check for mistakes.

}
}