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.
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>Point it at your own cart
Replace
yourShop.addToCartwith 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.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
| Field | What it is |
|---|---|
variant_id | The product id from your product feed, for the exact variant the customer picked. Send the same id when you track the sale. |
product_id | The id of the product it belongs to, when your feed has one. |
quantity | How many to add. |
title | The 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 function | The chat says | Counts as driven by chat |
|---|---|---|
| Finishes without an error | Added to your cart. | Yes, when the customer buys it and the sale is tracked |
| Throws an error, or returns a promise that rejects | Sorry, 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.
Did this answer your question?