---
description: >-
  E-commerce sites can trigger events for revenue analytics to get insights into
  what purchases are being driven by Alhena
---

# Cart & Checkout Event API

Once you install the Alhena Chat Widget snippet on your site, two global methods become available on `window.gleenWidget`:

* **sendCartEvent(data)**
* **sendCheckoutEvent(data)**

Use these methods to report e‑commerce cart and checkout actions so you can attribute revenue back to your chat widget interactions.

## sendCartEvent(data)

Report when the user adds, removes, or updates items in their cart.

#### Data properties

* **type** _(string, required)_\
  One of:
  * `"ITEM_ADDED"`
  * `"QUANTITY_INCREASED"`
  * `"QUANTITY_DECREASED"`
  * `"ITEM_REMOVED"`
* **productId** _(string, required)_ — Your internal product identifier
* **productName** _(string, required)_ — Human‑readable name
* **value** _(number, required)_ — Price after discounts
* **currency** _(string, required)_ — ISO 4217 currency code (e.g. `"USD"`)
* **quantity** _(number, required)_ — Quantity after the action

**Example**:

```javascript
window.gleenWidget.sendCartEvent({
  type: 'ITEM_ADDED',
  productId: 'SKU-1234',
  productName: 'Black Running Shoes',
  value: 79.99,
  currency: 'USD',
  quantity: 1
})
```

## sendCheckoutEvent(data)

Report when the user completes an order.&#x20;

#### Data properties

* **orderId** _(string, optional)_ — Your internal order ID. The same ID won't be recorded twice.
* **value** _(number, required)_ — Total order value after discounts/taxes
* **currency** _(string, required)_ — ISO 4217 currency code (e.g. `"EUR"`)
* **lineItems** _(array of objects, optional)_ — Details for each purchased item. Each item must include:
  * **productId** _(string, required)_
  * **productName** _(string, required)_
  * **quantity** _(number, required)_
  * **value** _(number, required)_ — Total for that line (price × quantity)
  * **currency** _(string, required)_

**Example:**

```javascript
window.gleenWidget.sendCheckoutEvent({
  orderId: 'ORDER-7890',
  value: 199.97,
  currency: 'USD',
  lineItems: [
    {
      productId: 'SKU-1234',
      productName: 'Black Running Shoes',
      quantity: 1,
      value: 79.99,
      currency: 'USD'
    },
    {
      productId: 'SKU-5678',
      productName: 'Running Socks (2-pack)',
      quantity: 2,
      value: 59.99,
      currency: 'USD'
    }
  ]
})
```

## What happens behind the scenes

* **Company key** is automatically included, so you don’t need to pass it.
* **Visitor fingerprints** (`user_fingerprint` and `user_faq_fingerprint`) are added to tie events back to unique users.
* Events will only be recorded for visitors who have interacted with the **chat widget** or the **Product FAQs** feature in their session—ensuring that only revenue driven by those interactions is attributed.
* Client‑side validation ensures all required fields are present and correctly typed.

## Troubleshooting

* **Methods undefined**\
  Make sure the widget snippet has fully loaded and that you call these methods only after `window.gleenWidget` exists, and is fully initialized. You can use `window.gleenWidget.on` to subscribe to the `widget:loaded` event if you are trying to record the checkout data on page load. Learn more here: [website-sdk-events](website-sdk-events "mention")
* **No events appearing in your dashboard**
  * Verify the user session included interaction with the chat widget or FAQs before the cart/checkout action.
  * Open **Analytics > Revenue impact** in the Alhena dashboard to view attributed add‑to‑cart and purchase revenue.
* **Validation errors**\
  Check the browser console for messages about missing or invalid fields and ensure you’re passing correct data types.
