Events API
Reference for the AutoCart DOM events dispatched on document when cart gifts are added, removed, or swapped.
Overview
AutoCart's standard and Progressive storefront engines dispatch the same CustomEvents on document. These events let your theme or custom code react to gift changes without polling the cart API.
Enable them using the setting for the engine you use:
| Storefront engine | Events opt-in |
|---|---|
| Standard Theme Extension | Set onAutocartUpdateCallback: true in Custom Settings. |
| Progressive Theme Extension | Select Callback Function as the Cart refresh method. |
Events are gated behind the corresponding callback option. The standard and Progressive engines use the same event names and payload contract, so one listener can handle both. When callback mode is disabled, that engine does not dispatch events.
Events Reference
| Event Name | When it Fires | Cancellable | event.detail Type |
|---|---|---|---|
autocart:ready | Once, after the first rule evaluation completes on page load | No | AutoCartResult |
autocart:before | Before cart mutations are executed (planned changes) | No | AutoCartResult |
autocart:updated | After evaluation and any mutations complete (debounced 100ms) | No | AutoCartResult |
autocart:error | When a cart mutation fails | No | { error: unknown, result?: AutoCartResult } |
All events bubble, so you can listen on document or any ancestor element.
Result Object Shape
Every event carries an AutoCartResult object in event.detail:
type Values
| Value | Meaning |
|---|---|
"add" | Only additions in this evaluation |
"remove" | Only removals in this evaluation |
"swap" | Both additions and removals (e.g., gift replaced) |
"noop" | Cart evaluated but no gift changes were needed |
For Progressive automations, rule.scope identifies the strategy as "tiered" or "cyclic". Standard automation events retain their normal storefront, checkout, global, or remove scope.
Change Entry
Each entry in the changes array describes one cart line that was added or removed:
| Field | Type | Description |
|---|---|---|
action | "added" | "removed" | Whether the line was added or removed |
reason | string | Why the change happened (see below) |
rule | object | { id, title, scope } of the rule that triggered the change |
variantId | number | Shopify variant ID |
productId | number | Shopify product ID (0 if unknown) |
handle | string | Product handle |
title | string | Product title |
quantity | number | Line quantity |
properties | object | Line item properties |
Reason Codes
| Reason | Action | Description |
|---|---|---|
qualified | added | Rule conditions now met, gift added |
no_longer_qualifying | removed | Rule conditions no longer met |
promotion_ended | removed | Rule's scheduled end date has passed |
outdated | removed | Rule or variant no longer exists in active rules |
rule_triggered | removed | A scope="remove" rule actively removed the item |
manual | added/removed | Customer selected or changed gifts in the picker dialog |
unknown | added/removed | A maintenance operation could not be attributed to a more specific reason |
Progressive removals use outdated when the saved rule is no longer active, promotion_ended when its schedule is inactive, and no_longer_qualifying when the current cart no longer earns the gift. Progressive additions use qualified.
Usage Examples
Listen for Gift Changes
Lock UI During Mutations
Track Removed Gifts
Wait for AutoCart Ready
Debouncing
When multiple cart changes happen in rapid succession (e.g., customer adds 3 items quickly), each storefront engine coalesces its own autocart:updated events with a 100ms debounce window. Only the final evaluation result from that engine is dispatched.
autocart:before is not debounced — it fires immediately before each mutation so your UI can show a loading state right away.
The debounce only affects autocart:updated. All other events (autocart:before, autocart:error, autocart:ready) fire immediately.
Using Both Storefront Engines
The standard and Progressive engines intentionally publish the same event names. If both are enabled, a document listener receives events from both. Inspect change.rule.scope or Progressive properties such as _autocart_prog, _ac_tier, and _ac_cyclic when your integration needs to distinguish the source.