Skip to content

Commit 10f5878

Browse files
Implement click count tracking in AddToCart component and display click count to users
1 parent dd9b435 commit 10f5878

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

app/add-to-cart.tsx

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,29 @@ export function AddToCart() {
1111
const router = useRouter();
1212
const { color, size } = useProductDetailPageContext();
1313
const [isLoading, setIsLoading] = useState(false);
14+
const [clickCount, setClickCount] = useState(0);
1415

1516
useEffect(() => {
1617
track('add_to_cart:viewed');
1718
}, []);
1819

1920
return (
20-
<AddToCartButton
21-
isLoading={isLoading}
22-
onClick={async () => {
23-
setIsLoading(true);
24-
track('add_to_cart:clicked');
25-
await addToCart({ id: 'shirt', color, size, quantity: 1 });
26-
router.push('/cart');
27-
}}
28-
/>
21+
<div className="space-y-2">
22+
<AddToCartButton
23+
isLoading={isLoading}
24+
onClick={async () => {
25+
setIsLoading(true);
26+
setClickCount(prev => prev + 1);
27+
track('add_to_cart:clicked');
28+
await addToCart({ id: 'shirt', color, size, quantity: 1 });
29+
router.push('/cart');
30+
}}
31+
/>
32+
{clickCount > 0 && (
33+
<div className="text-sm text-gray-600 text-center">
34+
Button clicked {clickCount} times
35+
</div>
36+
)}
37+
</div>
2938
);
3039
}

0 commit comments

Comments
 (0)