Template
Initial commit
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F22Ms5Cxam5UHyxaCrtZzu
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect } from "react";
|
||||
|
||||
import { AnalyticsEvent, getAnalytics } from "@/lib/analytics";
|
||||
import { useCart } from "@/lib/cart";
|
||||
|
||||
/**
|
||||
* Publishes `CART_VIEWED` when the `/cart` page is viewed
|
||||
* (`hydrogen-analytics` / `references/react.md`). The cart payload is
|
||||
* `AnalyticsCart | null`: when a compatible cart is available, include `id` +
|
||||
* `updatedAt` + connection-shaped `lines`; otherwise pass `cart: null`.
|
||||
*/
|
||||
export function CartViewedTracker() {
|
||||
const cart = useCart((state) => state.data);
|
||||
|
||||
useEffect(() => {
|
||||
const analytics = getAnalytics();
|
||||
if (!analytics) return;
|
||||
analytics.publish(AnalyticsEvent.CART_VIEWED, {
|
||||
cart: cart.id ? cart : null,
|
||||
prevCart: null,
|
||||
});
|
||||
}, [cart]);
|
||||
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user