-
Notifications
You must be signed in to change notification settings - Fork 0
Add analytics layer #104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add analytics layer #104
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a comprehensive analytics layer with an abstract interface for standardized event tracking across the application. The implementation follows clean architecture principles and provides a foundation for multiple analytics provider integrations.
- Adds abstract
AnalyticsClient
interface with core tracking methods and function wrapping capabilities - Implements Firebase Analytics as the first concrete analytics provider (stub implementation)
- Includes setup utility class for analytics service initialization
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
File | Description |
---|---|
analytics_client.dart | Defines abstract interface with event tracking, user management, and app lifecycle methods |
firebase_analytics.dart | Provides Firebase-specific implementation stub with all required methods |
setup_analytics.dart | Contains initialization utility for analytics services |
class SetupAnalytics { | ||
static void initialize() { | ||
// Initialize analytics services here | ||
print("Analytics services initialized."); |
There was a problem hiding this comment.
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.
Function fn, | ||
String name, { | ||
Map<String, dynamic>? properties, | ||
}) => fn().then((_) => trackEvent(name, properties: properties)); |
There was a problem hiding this comment.
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.
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.
/// This is useful for tracking events that are triggered by specific actions. | ||
/// Example usage: | ||
/// trackFunction(() => loginWithEmailPassword(email, password), 'login_triggered', properties: {email: email}); | ||
Future trackFunction( |
There was a problem hiding this comment.
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.
/// 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}); |
There was a problem hiding this comment.
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.
/// 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.
18c3bcf
to
fa6ca2f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! 🚀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! 🚀 It would be nice to have the commented code of how firebase analytics could be set up just as an example too
Description
Added a comprehensive analytics layer to the project with an abstract AnalyticsClient interface that provides standardized event tracking capabilities across the application.
Changes Made
📊 New Analytics Layer - [analytics_client.dart]
Core Features:
Function Tracking: trackFunction() method that wraps function calls with event tracking
Event Tracking: Standard trackEvent() method for custom analytics events
User Management: Complete user identification and property management
App Lifecycle: Built-in tracking for app creation, updates, and deletion
Key Methods Implemented:
Analytics Event Naming Convention:
Follows snake_case naming: init_login, error_login, login_triggered
Structured event categorization for better analytics organization
Standardized property mapping for consistent data collection
Architecture Integration
Fits Clean Architecture Pattern:
📁 Location: analytics - properly placed in common module
🏗️ Abstract Interface: Allows multiple analytics provider implementations
🔧 Service Integration: Can be injected into Services for domain-specific tracking
📱 Cross-Module: Available to all modules through common dependency
Usage Examples:
Benefits
✅ Standardized Tracking: Consistent analytics interface across the entire application
✅ Function Wrapping: Innovative trackFunction() approach for automatic event tracking
✅ User Journey Mapping: Complete user identification and property management
✅ App Lifecycle Monitoring: Built-in tracking for key app events
✅ Flexible Implementation: Abstract interface allows multiple [analytics]
✅ Clean Architecture Compliance: Properly integrated into existing project structure
Next Steps
Implement concrete analytics providers (Firebase Analytics, Mixpanel, etc.)
Add analytics injection to Services through dependency injection
Create analytics constants file for standardized event names
Add analytics documentation with tracking guidelines
Impact
This analytics layer provides the foundation for comprehensive user behavior tracking, performance monitoring, and business intelligence gathering while maintaining the project's clean architecture principles.