---
title: "Storefront JavaScript Events"
description: "Add cart and item lifecycle events to build custom integrations on your storefront."
url: https://help.cartgenie.com/en/articles/191-storefront-javascript-events
collection: "Developers"
updated: 2026-09-15
language: en
---

# Storefront JavaScript Events

Add cart and item lifecycle events to build custom integrations on your storefront.

CartGenie emits a set of DOM events at key moments during the shopping experience — when the cart opens, when items are added or removed, when discounts are applied, and more. Any third-party script running on your storefront can listen for these events and react accordingly.

## Listening for Events

Use the standard `document.addEventListener` API. Every CartGenie event is dispatched on the `document` object:

js

```js
document.addEventListener('item.added', (event) => {
  console.log('A product was just added to the cart.');
});
```

## Available Events

### Initialization

<table data-id="9529d7ef-3015-4ae3-a45f-1fa3f4c06abc" style="min-width: 151px;"><colgroup><col style="width: 126px;"><col style="min-width: 25px;"></colgroup><tbody><tr><td colspan="1" rowspan="1" colwidth="126"><p data-id="06859ecd-40bf-4742-bd97-1e22f7601cb1"><strong>Event</strong></p></td><td colspan="1" rowspan="1"><p data-id="4ba17cc4-89ba-423c-a28c-0a7daf4571c8"><strong>Fires when…</strong></p></td></tr><tr><td colspan="1" rowspan="1" colwidth="126"><p data-id="08debac6-982a-4825-9c6e-151bb62f8087"><strong>cartgenie.ready</strong></p></td><td colspan="1" rowspan="1"><p data-id="57d6ec1d-7da0-46e3-8c1b-b51890c342d6">The CartGenie script has fully loaded and initialized on the page. Wait for this event before calling any CartGenie APIs.</p></td></tr></tbody></table>

### Cart Lifecycle

<table data-id="88914ccf-d3a0-4976-bad7-c790f7ec71e4" style="min-width: 50px;"><colgroup><col style="min-width: 25px;"><col style="min-width: 25px;"></colgroup><tbody><tr><td colspan="1" rowspan="1"><p data-id="68abeda3-c92f-4818-948d-e3fce85b7e35"><strong>Event</strong></p></td><td colspan="1" rowspan="1"><p data-id="10245f7c-3dce-44cc-a12f-eaf70365a21c"><strong>Fires when…</strong></p></td></tr><tr><td colspan="1" rowspan="1"><p data-id="2ced56c7-d42e-4490-b455-b61885e0ec37"><strong>cart.created</strong></p></td><td colspan="1" rowspan="1"><p data-id="0a12dd6f-e80b-44e1-8144-453a1c07b7a7">A new cart is created for the current visitor (first item added or cart initialized for a new session).</p></td></tr><tr><td colspan="1" rowspan="1"><p data-id="e4a0c390-eae4-443b-88b9-6f8c1ddf24b1"><strong>cart.ready</strong></p></td><td colspan="1" rowspan="1"><p data-id="a6ff876a-8570-4e65-8c1b-d28dca688444">The cart has finished loading its contents and is available for interaction.</p></td></tr><tr><td colspan="1" rowspan="1"><p data-id="1befcac2-60fe-43de-bcc3-f6d8b6575a2f"><strong>cart.open</strong></p></td><td colspan="1" rowspan="1"><p data-id="232d295e-94f5-4bb6-a955-7b5b6704704e">The cart drawer or modal becomes visible to the shopper.</p></td></tr><tr><td colspan="1" rowspan="1"><p data-id="8a8b3539-4343-4926-a160-0a5b92f1f10c"><strong>cart.close</strong></p></td><td colspan="1" rowspan="1"><p data-id="7c208c5c-7e9a-4cee-80fe-999df0d92312">The cart drawer or modal is dismissed.</p></td></tr></tbody></table>

### Item Events

<table data-id="0d1cc96e-910f-4bbf-8e23-ad5031baec75" style="min-width: 50px;"><colgroup><col style="min-width: 25px;"><col style="min-width: 25px;"></colgroup><tbody><tr><td colspan="1" rowspan="1"><p data-id="8ebc29e2-d0b0-4f9d-a486-e7243429e1f7"><strong>Event</strong></p></td><td colspan="1" rowspan="1"><p data-id="3784ac90-b3fb-4f88-820d-3ae3aa16f635"><strong>Fires when…</strong></p></td></tr><tr><td colspan="1" rowspan="1"><p data-id="f7ad5c14-bf0e-40b1-99b9-8015955c285a"><strong>item.adding</strong></p></td><td colspan="1" rowspan="1"><p data-id="f6f9b4c5-fc9e-4453-a213-6c499f122ef0">An add-to-cart request has started but has not yet completed. Useful for showing loading states.</p></td></tr><tr><td colspan="1" rowspan="1"><p data-id="3ec0071c-d774-454d-a2cd-7c9dc12eea40"><strong>item.added</strong></p></td><td colspan="1" rowspan="1"><p data-id="a579e4dc-c233-4792-98a8-acb3eb669580">An item has been successfully added to the cart.</p></td></tr><tr><td colspan="1" rowspan="1"><p data-id="e1e805c8-07e4-4727-8969-fa832a57eaa6"><strong>item.adding.error</strong></p></td><td colspan="1" rowspan="1"><p data-id="304e1ee7-abc9-4435-9be8-728cfd554b7a">An add-to-cart request failed (e.g., out of stock, network error).</p></td></tr><tr><td colspan="1" rowspan="1"><p data-id="66650e6e-56e3-4b5e-97fe-8a950068dbc6"><strong>item.updated</strong></p></td><td colspan="1" rowspan="1"><p data-id="04826e31-4218-4921-b18c-422aa3b846b8">An existing line item's quantity or properties have changed.</p></td></tr><tr><td colspan="1" rowspan="1"><p data-id="a6b0d0d2-0334-40ee-a640-9958b242a1c4"><strong>item.removed</strong></p></td><td colspan="1" rowspan="1"><p data-id="c54fde74-5669-48a3-a545-6babf9d54ce3">An item has been removed from the cart entirely.</p></td></tr></tbody></table>

### Discounts

<table data-id="9ade60f5-bdfe-475f-b9b5-621117448501" style="min-width: 50px;"><colgroup><col style="min-width: 25px;"><col style="min-width: 25px;"></colgroup><tbody><tr><td colspan="1" rowspan="1"><p data-id="8b783087-78f4-4cff-bd75-4fa971388ae2"><strong>Event</strong></p></td><td colspan="1" rowspan="1"><p data-id="d752747d-356d-459d-aca7-b5b6b726d6bd"><strong>Fires when…</strong></p></td></tr><tr><td colspan="1" rowspan="1"><p data-id="1704c69d-d41f-4fa8-84c9-3072cfc2f359"><strong>discount.applied</strong></p></td><td colspan="1" rowspan="1"><p data-id="cae48eb9-aee3-4d5a-8eb8-4368d4e9f2aa">A discount code or automatic discount has been applied to the cart.</p></td></tr></tbody></table>

## Example: Fire a Tracking Pixel After Add-to-Cart

js

```js
document.addEventListener('cartgenie.ready', () => {
  console.log('CartGenie is ready — registering event listeners.');

  document.addEventListener('item.added', (event) => {
    // Send an event to your analytics provider
    analytics.track('Product Added', {
      // Access event.detail for item data (if provided)
    });
  });
});
```

## Tips

-   **Always wait for** `cartgenie.ready` before registering other listeners. This guarantees the CartGenie runtime is available.
    
-   **Events bubble up the DOM**, so `document.addEventListener` will catch them regardless of where they originate.
    
-   **Check** `event.detail` — some events include a payload with contextual data such as the item, quantity, or error message.
    
-   **Multiple listeners are fine.** You can register as many listeners for the same event as you need; they won't interfere with each other.
