E-commerce

Connect the Widget with your online store.

If you run an online store, the Widget can connect conversations with what your customers view and buy, and keep your store cart in sync with products the AI Agent adds in the conversation.

Everything on this page extends the Widget setup. Pass the options and callbacks in the configuration object of ZowieWidget.init, and call the methods on the global ZowieWidget object after the Widget has loaded.

Sync the cart from the conversation

When the AI Agent adds products to the cart or removes them in the conversation, the Widget calls onCartItemsModified with the list of changes. Use it to update the cart on your website with your store's own cart API.

ZowieWidget.init("<your-instance-id>", {
  onCartItemsModified: (items) => {
    const added = items.filter((item) => item.modificationType === "Added");
    const removed = items.filter((item) => item.modificationType === "Removed");

    added.forEach((item) => myStore.cart.add(item.productId, item.quantity));
    removed.forEach((item) => myStore.cart.remove(item.productId, item.quantity));
  },
});

Without this callback the cart still works inside the conversation, but your website's cart doesn't change.

E-commerce tracking

E-commerce tracking connects conversations with what customers view and buy in your store. Your TAM sets it up for your store platform.

  • Shopify, BigCommerce, Magento and nopCommerce: the Widget tracks product visits and the cart automatically. To turn off automatic cart tracking, set ecommerceCartWatchEnabled: false.
  • Other stores: report events yourself with trackVisitedProduct, trackCartUpdated and trackPurchased.

The tracking methods do nothing when tracking is off for your website.

ZowieWidget.trackVisitedProduct({
  productId: "8123",
  title: "Wireless Headphones",
  price: 79.99,
  currency: "USD",
  shopUrl: "https://shop.example.com/products/wireless-headphones",
  imageUrl: "https://shop.example.com/images/8123.jpg",
});

ZowieWidget.trackPurchased({
  orderId: "ORD-1042",
  lineItems: [{ productId: "8123", variantId: "8123-black" }],
  totalAmount: 79.99,
  currency: "USD",
});

Options

OptionTypeDefaultDescription
trackingEnabledbooleanSet by ZowieTurn tracking on or off on this website.
ecommerceCartWatchEnabledbooleantrueLet the Widget watch the store cart automatically on Shopify, BigCommerce, Magento and nopCommerce.

Callbacks

CallbackArgumentsCalled when
onCartItemsModifieditems: CartModifiedItem[]The AI Agent added products to or removed them from the cart in the conversation. See CartModifiedItem.
onEcommerceProductVisitedNoneThe customer visited a product page. Shopify, BigCommerce, Magento and nopCommerce only.
onEcommercePurchasedtotal: number, currency: stringThe customer completed a purchase. BigCommerce, Magento and nopCommerce only.

Methods

MethodDescription
trackVisitedProduct(product)Report a product page visit. See VisitedProduct.
trackCartUpdated(lineItems)Report the current cart content. See LineItem.
trackPurchased(purchase)Report a completed purchase. See Purchase.
updateEcommerceCart()Read the cart again on Shopify stores, for example after your own code changed it.

Types

CartModifiedItem

FieldTypeDescription
productIdstringID of the product variant.
quantitynumberNumber of items added or removed.
modificationType"Added" | "Removed"Whether the items were added or removed.
productobjectProduct details shown on the product card in the conversation.

VisitedProduct

FieldTypeRequiredDescription
productIdstringYesProduct ID.
titlestringYesProduct name.
pricenumberYesProduct price.
currencystringYesCurrency code, for example USD.
shopUrlstringYesURL of the product page.
imageUrlstringNoURL of the product image.
category{ id: string, name: string }NoProduct category.

LineItem

FieldTypeRequiredDescription
productIdstringYesProduct ID.
variantIdstringYesProduct variant ID.
titlestringYesProduct name.
pricenumberYesPrice of one item.
currencystringYesCurrency code, for example USD.
quantitynumberYesNumber of items in the cart.
shopUrlstringYesURL of the product page.
imageUrlstringNoURL of the product image.

Purchase

FieldTypeRequiredDescription
orderIdstringYesOrder ID.
lineItems{ productId: string, variantId: string }[]YesPurchased products.
totalAmountnumberYesTotal order value.
currencystringYesCurrency code, for example USD.
subtotalAmountnumberNoOrder subtotal.
discountAmountnumberNoDiscount amount.
taxAmountnumberNoTax amount.
shippingCostAmountnumberNoShipping cost.

Did this page help you?