add logs
This commit is contained in:
@@ -17,6 +17,8 @@ import 'package:worker/core/theme/typography.dart';
|
||||
import 'package:worker/features/cart/presentation/providers/cart_provider.dart';
|
||||
import 'package:worker/features/cart/presentation/providers/cart_state.dart';
|
||||
import 'package:worker/features/cart/presentation/widgets/cart_item_widget.dart';
|
||||
import 'package:worker/core/services/analytics_service.dart';
|
||||
import 'package:firebase_analytics/firebase_analytics.dart';
|
||||
|
||||
/// Cart Page
|
||||
///
|
||||
@@ -52,6 +54,19 @@ class _CartPageState extends ConsumerState<CartPage> {
|
||||
final itemCount = cartState.itemCount;
|
||||
final hasSelection = cartState.selectedCount > 0;
|
||||
|
||||
// Log view cart analytics event when cart has items
|
||||
if (cartState.isNotEmpty) {
|
||||
AnalyticsService.logViewCart(
|
||||
cartValue: cartState.selectedTotal,
|
||||
items: cartState.items.map((item) => AnalyticsEventItem(
|
||||
itemId: item.product.productId,
|
||||
itemName: item.product.name,
|
||||
price: item.product.basePrice,
|
||||
quantity: item.quantity.toInt(),
|
||||
)).toList(),
|
||||
);
|
||||
}
|
||||
|
||||
return PopScope(
|
||||
// Intercept back navigation to sync pending updates
|
||||
onPopInvokedWithResult: (didPop, result) async {
|
||||
@@ -442,6 +457,17 @@ class _CartPageState extends ConsumerState<CartPage> {
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
// Log remove from cart analytics for selected items
|
||||
for (final item in cartState.items) {
|
||||
if (cartState.selectedItems[item.product.productId] == true) {
|
||||
AnalyticsService.logRemoveFromCart(
|
||||
productId: item.product.productId,
|
||||
productName: item.product.name,
|
||||
price: item.product.basePrice,
|
||||
quantity: item.quantity.toInt(),
|
||||
);
|
||||
}
|
||||
}
|
||||
ref.read(cartProvider.notifier).deleteSelected();
|
||||
context.pop();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
|
||||
Reference in New Issue
Block a user