Shared Hooks
For developers
How the shared providers and hooks keep event tracking close to business logic so screens reuse the same behavior.
Why hooks are used here
The example keeps analytics close to business logic in providers/hooks. This improves reuse because screens consuming the same hook share the same event behavior.
Cart provider (shared/hooks/useCart.tsx)
addToCart
- sends
BasketAddfor new item insertion - payload includes
productId,quantity,price
removeFromCart
- sends
BasketRemove - payload uses the line’s catalog
productId, removed quantity, and lineprice
updateQuantity
- reuses
BasketAddwith updated quantity
clearCart
- sends
BasketClear
Reference: Checkout and Basket Events.
Wishlist provider (shared/hooks/useWishlist.tsx)
addToWishlist
- sends
FavoriteAdd
removeFromWishlist
- sends
FavoriteRemove
clearWishlist
- no dedicated batch clear event method in current SDK usage
Reference: User and Wishlist Events.
Auth provider (shared/hooks/useAuth.tsx)
logout
- sends
Logoutbefore auth state reset
login
- after
login()succeeds,LoginScreenpersists the user withInitialize.setUser({ email })and sendsevents.Login({ email })
Reference: User and Wishlist Events.
Hook-level hardening suggestions
- Use catalog
productIdconsistently for basket events. - Guard repeated event calls triggered by render loops.
- Keep type unions aligned with real payload values (
INTERACTIONuse-cases).
For search/popup interaction hooks, see Search, Interaction, Form and Custom and Popups, Search and Push.