data-hemsy-action on the script tag sets the default, and any launcher element can override it with its own data-hemsy-action. It applies to every launch mode, including Instant.
In the Shopify theme extension, this is the app embed’s “When shoppers finish” setting and each trigger block’s override — no attributes to write. The examples below show the equivalent script install markup.
Use
cart when your storefront owns cart state and should add the returned variants itself: headless storefronts, Hydrogen, or any site with a custom cart drawer.
data-hemsy-action on the element:
The legacy script-level
data-hemsy-mode="cart" still maps to the cart
action for backward compatibility, but prefer data-hemsy-action:
data-hemsy-mode should be reserved for "instant". (data-hemsy-mode="checkout"
has no effect; checkout is simply the default action.)Native cart strategy
By default thecart action hands items to your code via onProductVariantData, which means writing a callback. If your storefront is a standard Shopify theme, skip that entirely with data-hemsy-cart-strategy="native":
- Adds the returned items to the Shopify cart via the Ajax API (
/cart/add.js), converting variant GIDs to numeric IDs and mapping item attributes to line-item properties. - Dispatches
cart:refresh,cart:updated, andcart:changeevents ondocumentwith the updated cart, so cart drawers and count bubbles that listen for them update in place. - Closes the modal once the add completes (unless
data-hemsy-auto-close="false").
The Shopify theme extension uses the native strategy
automatically, so merchants who install through the theme editor get a working
cart handoff with zero code.
Event callbacks
Callbacks are configured onwindow.HemsyEmbedConfig (not data attributes). Define it before the embed script loads:
onItemAdded and onItemRemoved fire live as the shopper edits their bag, regardless of action. onProductVariantData is the cart handoff itself: the items array includes any line-item attributes from the original payload (bundle keys and so on), so pass them through to your cart.
Keeping the modal open
By default, Hemsy closes the modal after the cart handoff. Setdata-hemsy-auto-close="false" on the script tag (or autoClose: false on HemsyEmbedConfig) to keep it open (for example if you show your cart drawer next to the modal).
Hydrogen example
variantId is the numeric Shopify variant ID as a string. Convert it to GID
format (gid://shopify/ProductVariant/...) for Hydrogen’s cart operations.