This commit is contained in:
Phuoc Nguyen
2025-12-09 16:57:58 +07:00
parent 597c6a0e57
commit 4cfe000172
11 changed files with 89 additions and 2 deletions

View File

@@ -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(

View File

@@ -29,6 +29,8 @@ import 'package:worker/features/cart/presentation/widgets/payment_method_section
import 'package:worker/features/cart/presentation/widgets/price_negotiation_section.dart';
import 'package:worker/features/orders/presentation/providers/order_status_provider.dart';
import 'package:worker/features/orders/presentation/providers/payment_terms_provider.dart';
import 'package:worker/core/services/analytics_service.dart';
import 'package:firebase_analytics/firebase_analytics.dart';
/// Checkout Page
///
@@ -104,6 +106,22 @@ class CheckoutPage extends HookConsumerWidget {
final total = subtotal - memberDiscount + shipping;
// Log begin checkout analytics event
if (cartItemsData.isNotEmpty) {
AnalyticsService.logBeginCheckout(
value: total,
items: cartItemsData.map((itemData) {
final cartItem = itemData as CartItemData;
return AnalyticsEventItem(
itemId: cartItem.product.productId,
itemName: cartItem.product.name,
price: cartItem.product.basePrice,
quantity: cartItem.quantity.toInt(),
);
}).toList(),
);
}
return Scaffold(
backgroundColor: colorScheme.surfaceContainerLowest,
appBar: AppBar(