Events
The snippet sends DOM events on document, named nativeslide: followed by the event name.
The details are in event.detail.
document.addEventListener('nativeslide:item-added', (event) => { console.log('Added', event.detail.items);});NativeSlide.on(name, listener) listens for the same events. It calls listener(detail, event), so you get the details directly and the DOM event as the second argument. It returns
a function that stops listening:
const stop = NativeSlide.on('open', ({ variant }) => { analytics.track('Cart opened', { variant });});
// laterstop();NativeSlide.off(name, listener) stops a listener too. You can call on() and off() at
any time, before the API is ready as well.
| Event | detail |
When |
|---|---|---|
ready |
{ enabled, version } |
The API is ready. Fires once. |
open |
{ variant } |
The drawer opened |
close |
{ variant } |
The drawer closed |
cart-updated |
{ cart } |
The drawer read a cart that differs from the last one, whoever changed it |
item-added |
{ items, source } |
Lines were added to the cart |
error |
{ key, message } |
A change to a line failed, or an add from the theme failed |
before-checkout |
{ cart, params } |
The shopper is about to go to checkout. Cancel the event to stop it. |
checkout |
{ cart, params } |
The shopper is going to checkout |
Details
Section titled “Details”ready:enabledisfalsewhen the store has no published NativeSlide cart.versionis the snippet release, such as1.1.0. A listener added after the event has fired isn’t called, so useNativeSlide.readyif your script may run late.open,close:variantis the ID of the cart the shopper sees, as inNativeSlide.variant. They fire however the drawer opened or closed: the shopper, the theme’s cart link or your script.cart-updated:cartis the whole cart, as inNativeSlide.Cart.cart. It also fires for the first read, just beforeready.item-added:itemsare the added lines as Shopify’s/cart/add.jsreturns them.sourceisapifor adds throughNativeSlide.Cart.addItem()andaddItems(), andthemefor every other add, including other apps’. It fires before thecart-updatedthat follows the add.error:messageis Shopify’s message, such as “You can only add 2 of Canvas tote to the cart.”, or the cart’s own error text if the request didn’t complete.keyis the key passed to the change (the line’s key, or the variant ID if that was used),clearfor a failedclear(), oraddwhen an add-to-cart form that NativeSlide took over failed. It fires for changes from the drawer and the API alike. Failed adds, discount codes, note and attributes through the API don’t fire it; check the action’s result instead.before-checkout,checkout:cartis the cart, ornullif it couldn’t be read.paramsare the parameters passed tocheckout(), or{}.before-checkoutis the only event you can cancel; see Stopping checkout.