Cartesiandocs

Integrate with your app

Events and analytics

Listen to what the assistant does, for analytics, badges or your own logic.

All UI callbacks go through one CartesianListener. Set it once:

Cartesian.listener = MyCartesianListener()
CallbackWhen
onAddToCart(product, quantity)Add to cart, in Host cart mode
onOpenCart()Cart icon or "View cart", in Host mode
onToggleSaved(product, saved)Heart, in Host wishlist mode
onOpenWishlist()Saved icon, in Host mode
onProductSelected(product)Product card tapped (if productTap is on)
onCheckout(cart): BooleanCheckout in the built-in cart drawer
onSignInRequired()UI shown while signed out and online
onEvent(event)Every ChatEvent (below)

All methods have empty defaults, so override only the ones you need.

Chat events

override fun onEvent(event: ChatEvent) {
    when (event) {
        is ChatEvent.TurnStarted -> analytics.track("assistant_question", mapOf("thread" to event.threadId))
        is ChatEvent.ProductsShown -> analytics.track("assistant_products_shown", mapOf("count" to event.products.size))
        is ChatEvent.CartChanged -> analytics.track("assistant_cart_changed", mapOf("items" to event.update.itemCount))
        is ChatEvent.TurnFinished -> analytics.track("assistant_answer", mapOf("seconds" to event.message.elapsedSeconds))
        is ChatEvent.Error -> analytics.track("assistant_error", mapOf("message" to event.message))
    }
}

The same stream is available headless as Cartesian.client.chat.events.

The SDK does not send analytics anywhere itself. Events are only delivered to your code.