# Drive the widget from your code

Once the widget is ready, every method is on `window.subblyCart`. Use the
`onReady` helper from
[Wait for the widget](/developer-resources/cart-widget/install#wait-for-the-widget).

## Call a method

```js title="Open the checkout from your own button"
onReady(async (cart) => {
  await cart.configureItem({ productId: 555 })

  cart.open('checkout')
})
```

Every method is on [Methods](/reference/cart-widget/methods).

## Follow what the customer does

The widget emits an event for every step the customer takes: the cart
changes, the panel opens, an email is captured, a purchase completes.

```js title="Track purchases"
onReady(({ events }) => {
  events.on(events.type.PURCHASE_COMPLETED, (err, data) => {
    track('purchase', {
      value: data.purchase.invoice?.total ?? 0,
      currency: data.cart.currencyCode
    })
  })
})
```

Every event and its payload is on
[Events](/reference/cart-widget/events#on).
