Event Listeners
These events trigger within the Smart Cart lifecycle. Since Smart Cart extends the cart object, Cart events like rebuy:cart.change can also be used for cart-based logic.
You can also add these as anonymous functions in Smart Cart settings under the "Advanced" section—no theme code changes required.
Init
Triggers when the Smart Cart begins initialization.
document.addEventListener('rebuy:smartcart.init', (event) => {
const { smartcart } = event.detail;
// Your logic here
});
Payload
| Property |
Type |
Description |
smartcart |
object |
The Smart Cart instance |
Ready
Triggers when the Smart Cart has fully initialized and is ready.
document.addEventListener('rebuy:smartcart.ready', (event) => {
const { smartcart } = event.detail;
// Your logic here
});
Payload
| Property |
Type |
Description |
smartcart |
object |
The Smart Cart instance |
Show
Triggers when the Smart Cart is shown. Can also be triggered via window.Rebuy.SmartCart.show().
document.addEventListener('rebuy:smartcart.show', (event) => {
const { smartcart } = event.detail;
// Your logic here
});
Payload
| Property |
Type |
Description |
smartcart |
object |
The Smart Cart instance |
Hide
Triggers when the Smart Cart is hidden. Can also be triggered via window.Rebuy.SmartCart.hide().
document.addEventListener('rebuy:smartcart.hide', (event) => {
const { smartcart } = event.detail;
// Your logic here
});
Payload
| Property |
Type |
Description |
smartcart |
object |
The Smart Cart instance |
Item Increase
Triggers when an item's quantity is increased in the Smart Cart.
document.addEventListener('rebuy:smartcart.line-item-increase', (event) => {
const { smartcart, item } = event.detail;
// Your logic here
});
Payload
| Property |
Type |
Description |
smartcart |
object |
The Smart Cart instance |
item |
object |
The cart item that was increased |
Item Decrease
Triggers when an item's quantity is decreased in the Smart Cart.
document.addEventListener('rebuy:smartcart.line-item-decrease', (event) => {
const { smartcart, item } = event.detail;
// Your logic here
});
Payload
| Property |
Type |
Description |
smartcart |
object |
The Smart Cart instance |
item |
object |
The cart item that was decreased |
Item Removed
Triggers when a customer removes an item from the Smart Cart.
document.addEventListener('rebuy:smartcart.line-item-removed', (event) => {
const { smartcart, item } = event.detail;
// Your logic here
});
Payload
| Property |
Type |
Description |
smartcart |
object |
The Smart Cart instance |
item |
object |
The cart item that was removed |
Item Switched to Subscription
Triggers when an item is switched to subscription within the Smart Cart.
document.addEventListener('rebuy:smartcart.item-switch-to-subscription', (event) => {
const { smartcart, item } = event.detail;
// Your logic here
});
Payload
| Property |
Type |
Description |
smartcart |
object |
The Smart Cart instance |
item |
object |
The cart item that was switched |
Item Switched to One-time
Triggers when an item is switched to one-time purchase within the Smart Cart.
document.addEventListener('rebuy:smartcart.item-switch-to-one-time', (event) => {
const { smartcart, item } = event.detail;
// Your logic here
});
Payload
| Property |
Type |
Description |
smartcart |
object |
The Smart Cart instance |
item |
object |
The cart item that was switched |
Countdown Timer Started
Triggers when the Countdown Timer component starts its clock: with the first_item trigger on the first item added to an empty cart and when the cart token or the configured duration changes; with the drawer_open trigger the first time the drawer opens with items; with the page_load trigger on the shopper's first page view of the session; on every restart with the restart action; and on every restart in the admin preview. A persisted clock that continues after a page load does not trigger it again.
document.addEventListener('rebuy:smartcart.countdown-timer-started', (event) => {
const { smartcart, timer } = event.detail;
// Your logic here
});
Payload
| Property |
Type |
Description |
smartcart |
object |
The Smart Cart instance |
timer |
object |
{ action, componentId, deadline, durationMs, remainingMs, startTrigger }: the configured end action (none, hide, restart, clear_cart or checkout), the component id, the deadline as an epoch timestamp in milliseconds, the configured duration, the time left and the start trigger (first_item, page_load or drawer_open) |
Countdown Timer Expired
Triggers once per deadline when the Countdown Timer reaches zero, before the configured end action runs; later page loads with the same expired clock do not trigger it again (with the restart action it fires once per cycle). To replace the built-in ending with your own, set the action to Do Nothing or Hide and act here. In the admin preview the timer shows the expired text briefly and restarts instead of acting.
document.addEventListener('rebuy:smartcart.countdown-timer-expired', (event) => {
const { smartcart, timer } = event.detail;
// Your logic here (timer.remainingMs is 0)
});
Payload
| Property |
Type |
Description |
smartcart |
object |
The Smart Cart instance |
timer |
object |
Same shape as the started event, with remainingMs: 0 |
---
title: Event Listeners
excerpt: Handle cart lifecycle events and trigger custom logic with JavaScript
deprecated: false
hidden: false
metadata:
title: ''
description: ''
robots: index
next:
description: ''
---
These events trigger within the Smart Cart lifecycle. Since Smart Cart extends the cart object, [Cart events](cart-event-listeners.md) like `rebuy:cart.change` can also be used for cart-based logic.
You can also add these as anonymous functions in Smart Cart settings under the "Advanced" section—no theme code changes required.
## Init
Triggers when the Smart Cart begins initialization.
```javascript
document.addEventListener('rebuy:smartcart.init', (event) => {
const { smartcart } = event.detail;
// Your logic here
});
```
### Payload
| Property | Type | Description |
|----------|------|-------------|
| `smartcart` | object | The Smart Cart instance |
## Ready
Triggers when the Smart Cart has fully initialized and is ready.
```javascript
document.addEventListener('rebuy:smartcart.ready', (event) => {
const { smartcart } = event.detail;
// Your logic here
});
```
### Payload
| Property | Type | Description |
|----------|------|-------------|
| `smartcart` | object | The Smart Cart instance |
## Show
Triggers when the Smart Cart is shown. Can also be triggered via `window.Rebuy.SmartCart.show()`.
```javascript
document.addEventListener('rebuy:smartcart.show', (event) => {
const { smartcart } = event.detail;
// Your logic here
});
```
### Payload
| Property | Type | Description |
|----------|------|-------------|
| `smartcart` | object | The Smart Cart instance |
## Hide
Triggers when the Smart Cart is hidden. Can also be triggered via `window.Rebuy.SmartCart.hide()`.
```javascript
document.addEventListener('rebuy:smartcart.hide', (event) => {
const { smartcart } = event.detail;
// Your logic here
});
```
### Payload
| Property | Type | Description |
|----------|------|-------------|
| `smartcart` | object | The Smart Cart instance |
## Item Increase
Triggers when an item's quantity is increased in the Smart Cart.
```javascript
document.addEventListener('rebuy:smartcart.line-item-increase', (event) => {
const { smartcart, item } = event.detail;
// Your logic here
});
```
### Payload
| Property | Type | Description |
|----------|------|-------------|
| `smartcart` | object | The Smart Cart instance |
| `item` | object | The cart item that was increased |
## Item Decrease
Triggers when an item's quantity is decreased in the Smart Cart.
```javascript
document.addEventListener('rebuy:smartcart.line-item-decrease', (event) => {
const { smartcart, item } = event.detail;
// Your logic here
});
```
### Payload
| Property | Type | Description |
|----------|------|-------------|
| `smartcart` | object | The Smart Cart instance |
| `item` | object | The cart item that was decreased |
## Item Removed
Triggers when a customer removes an item from the Smart Cart.
```javascript
document.addEventListener('rebuy:smartcart.line-item-removed', (event) => {
const { smartcart, item } = event.detail;
// Your logic here
});
```
### Payload
| Property | Type | Description |
|----------|------|-------------|
| `smartcart` | object | The Smart Cart instance |
| `item` | object | The cart item that was removed |
## Item Switched to Subscription
Triggers when an item is switched to subscription within the Smart Cart.
```javascript
document.addEventListener('rebuy:smartcart.item-switch-to-subscription', (event) => {
const { smartcart, item } = event.detail;
// Your logic here
});
```
### Payload
| Property | Type | Description |
|----------|------|-------------|
| `smartcart` | object | The Smart Cart instance |
| `item` | object | The cart item that was switched |
## Item Switched to One-time
Triggers when an item is switched to one-time purchase within the Smart Cart.
```javascript
document.addEventListener('rebuy:smartcart.item-switch-to-one-time', (event) => {
const { smartcart, item } = event.detail;
// Your logic here
});
```
### Payload
| Property | Type | Description |
|----------|------|-------------|
| `smartcart` | object | The Smart Cart instance |
| `item` | object | The cart item that was switched |
## Countdown Timer Started
Triggers when the Countdown Timer component starts its clock: with the `first_item` trigger on the first item added to an empty cart and when the cart token or the configured duration changes; with the `drawer_open` trigger the first time the drawer opens with items; with the `page_load` trigger on the shopper's first page view of the session; on every restart with the `restart` action; and on every restart in the admin preview. A persisted clock that continues after a page load does not trigger it again.
```javascript
document.addEventListener('rebuy:smartcart.countdown-timer-started', (event) => {
const { smartcart, timer } = event.detail;
// Your logic here
});
```
### Payload
| Property | Type | Description |
|----------|------|-------------|
| `smartcart` | object | The Smart Cart instance |
| `timer` | object | `{ action, componentId, deadline, durationMs, remainingMs, startTrigger }`: the configured end action (`none`, `hide`, `restart`, `clear_cart` or `checkout`), the component id, the deadline as an epoch timestamp in milliseconds, the configured duration, the time left and the start trigger (`first_item`, `page_load` or `drawer_open`) |
## Countdown Timer Expired
Triggers once per deadline when the Countdown Timer reaches zero, before the configured end action runs; later page loads with the same expired clock do not trigger it again (with the `restart` action it fires once per cycle). To replace the built-in ending with your own, set the action to Do Nothing or Hide and act here. In the admin preview the timer shows the expired text briefly and restarts instead of acting.
```javascript
document.addEventListener('rebuy:smartcart.countdown-timer-expired', (event) => {
const { smartcart, timer } = event.detail;
// Your logic here (timer.remainingMs is 0)
});
```
### Payload
| Property | Type | Description |
|----------|------|-------------|
| `smartcart` | object | The Smart Cart instance |
| `timer` | object | Same shape as the started event, with `remainingMs: 0` |
## Related
- [Cart Event Listeners](cart-event-listeners.md) - Events for the underlying cart object
- [Widget Event Listeners](widget-event-listeners.md) - Events for recommendation widgets