Report orders to Zuzana
Shops on Shopify don't need this: see Chat Revenue on Shopify. On any other shop, the chat learns about an order on your order confirmation page. It needs two things there: the chat script, and the order's details.
The chat script must load on the order confirmation page. It still reads the order if you hide the chat on that page in your chat settings.
Already sending a Google Analytics purchase event?
Then you may not need to change anything. The chat reads purchase events from window.dataLayer. For Google Analytics 4 that looks like this:
dataLayer.push({
event: 'purchase',
ecommerce: {
transaction_id: 'ORDER-1001',
value: 1249.50,
currency: 'DKK',
items: [{ item_id: '471426', quantity: 5, price: 249.90 }]
}
});A gtag('event', 'purchase', …) call with the same fields works too, and so does Universal Analytics enhanced ecommerce.
The event needs the order id, the total and the currency, and each item_id must be the product id from the product feed Zuzana reads.
To check, place a test order and stay on the confirmation page. Open the browser console, run dataLayer, and find the entry with your order id.
If your event uses other field names, don't push a second purchase event. Your own analytics tags may listen for it and count every order twice. Use window.Zuzana.track.purchase below instead.
Send the order with window.Zuzana.track.purchase
Add this to your order confirmation page, filled in with the order's real values:
<script>
(function () {
var order = {
order_id: 'ORDER-1001',
value: 1249.50,
currency: 'DKK',
items: [
{ variant_id: '471426', name: 'Barolo 2019', quantity: 5, price: 249.90 }
]
};
function send() {
window.Zuzana.track.purchase(order);
}
if (window.Zuzana) {
send();
} else {
window.addEventListener('zuzana-loaded', send, { once: true });
}
})();
</script>The last lines wait for the chat script, in case your page runs this first.
Each order is sent once per browser, so reloading the confirmation page is safe. It is only sent to Zuzana if the customer chatted in this browser.
Fields
order_id(required): your order number, as text or a number.value: the order total, as a number like1249.50. Text like'1249.50'works too. An amount written with a decimal comma, like'1.249,50', is ignored.currency: the three-letter currency code, likeDKK.items: one entry per product bought, each with:variant_id: the product id from your product feed. It is the same id the chat passes to your add-to-cart handler.product_id: used when there is novariant_id.name,quantity, andprice(the price of one item).
Without value and currency, the order is recorded but does not count towards your sales.
Check that it works
window.Zuzana.track.purchase returns what happened to the order:
'reported': the customer chatted in this browser, and the order is sent to Zuzana.'no_chat': the customer hasn't chatted in this browser, so nothing is sent.'duplicate': this order was already reported in this browser.'invalid': the order has no usableorder_id.
To test it:
- Open the chat on your shop and send a message.
- Place a test order in the same browser.
- On the confirmation page, open the browser console. A warning starting with Zuzana: means a field could not be used, and says which.
- After about 15 minutes, the order shows up in Chat Revenue. What each group means is in Chat Revenue: how the chat's sales are counted.
While you test, you can log the result by changing send to console.log(window.Zuzana.track.purchase(order));.
Next
To count sales driven by chat, let the chat put products in the cart: Let the chat add products to the cart.
Did this answer your question?