Skip to main content
This page tracks a React shop with Analytics Web and its hooks from @grainql/analytics-web/react. Every block uses Analytics Web. The template methods send the events add_to_cart, remove_from_cart, checkout, purchase, and search. The dashboard reads them by these names. Read E-commerce tracking for the funnel and the rules.

Product view

There is no template method for a product view. Use track with useTrack.

Add to cart

trackAddToCart takes itemId, itemName, price, quantity, currency, category, and variant. useGrainAnalytics returns the client that holds the template methods.

Remove from cart

trackRemoveFromCart takes the same properties as trackAddToCart.

Checkout

Call trackCheckout when the checkout starts, with the cart as items. Each item holds id, name, price, and quantity. If the payment fails, call it again with success: false and the errorMessage.
createOrder and processPayment are functions of your shop.

Purchase

Call trackPurchase on the order confirmation page, with { flush: true }. The flush sends the event before the visitor leaves the page. trackPurchase takes orderId, total, currency, items, paymentMethod, shippingMethod, tax, shipping, discount, and couponCode.
The effect depends on order.id, so a re-render with the same order sends one purchase event. trackSearch takes query, results, filters, sortBy, category, and success. Call it after the results arrive, so results holds the count.
The TypeScript types of @grainql/analytics-web win over this page when they disagree. Read Template events.