Step 2: Let the chat add products to the cart

The chat can't reach your cart by itself, so you hand it a small function that can. Product cards in the chat then get an Add to cart button, and Chat Revenue can show Sales driven by chat.

  1. Add this script to every page

    The chat can be opened anywhere, so the script goes on every page of your shop.

    <script>
      (function () {
        function register() {
          window.Zuzana.onAddToCart(async function (item) {
            await yourShop.addToCart(item.variant_id, item.quantity);
          });
        }
        if (window.Zuzana) {
          register();
        } else {
          window.addEventListener('zuzana-loaded', register, { once: true });
        }
      })();
    </script>
  2. Point it at your own cart

    Replace yourShop.addToCart with the code your own Add to cart button runs. Your cart counter and mini cart then update as usual. There are no settings to change.

  3. Test it

    Ask the chat for a product and click Add to cart on its card. The chat should say Added to your cart. and the product should be in your cart.

What your function receives

FieldWhat it is
variant_idThe product id from your product feed, for the exact variant the customer picked. Send the same id when you track the sale.
product_idThe id of the product it belongs to, when your feed has one.
quantityHow many to add.
titleThe product name, with the variant name if there is one.

The same ids are also there as variantId and productId.

What the customer sees

Your functionThe chat saysCounts as driven by chat
Finishes without an errorAdded to your cart.Yes, when the customer buys it and the sale is tracked
Throws an error, or returns a promise that rejectsSorry, we couldn't add that to your cart. Please try again.No

If the button doesn't show

  • Check that your function runs on the page.
  • The button only shows on products with a price above 0.
  • For a product with several variants, the customer picks one first.
  • Ask Zuzana whether your chat has a custom cart setting that overrides it.