AppstleLoyalty:AppliedDiscountCode. It tells your theme code that a loyalty widget has just put a customer’s reward code on their cart. Use it to refresh a custom cart or cart drawer, to show the discount in your own design, or to send an analytics event.
The event exists only on a Shopify theme where the Appstle Loyalty app embed is on, and only for actions the customer takes in the Appstle widgets. If you build your own loyalty UI with the Storefront API, or run a headless storefront, nothing fires the event: update your own UI when your own calls return.
The event
event.detail is an object with three fields:
The embed dispatches one event on
document and another on window, so a listener on both runs twice for one apply. Listen on one of them.
defer, so it’s in place before the customer opens the widget.
When it fires
The event fires when a customer applies one of their loyalty rewards from an Appstle widget, and both of these are true:- The embed’s request to the store’s discount link,
/discount/{discountCode}, succeeds. That request puts the code on the customer’s cart. - The code is one of the customer’s rewards that the page had when it loaded. A reward the customer redeems after the page loads isn’t one of them until the next page load.
document and once on window, with this detail:
- The Apply Code button in a reward’s detail view. The merchant can change its label.
- The Add to cart button of a free product reward. The widget adds the product to the cart while the code is being applied, so the event can fire before the product is in the cart.
- On the Legacy design of the loyalty page, a click on a code in the customer’s list of rewards.
When it doesn’t fire
Merchant settings that affect the event
Four settings in the Loyalty app, under Design > Behavior, change whether the event fires and how long your listener has before the page unloads.- Add the code to the cart when copied, in Codes and cart, on by default. When it’s on, applying a reward in the popup or on the loyalty page puts the code on the customer’s cart, and the event fires. When it’s off, those actions only copy the code.
- Add the code to the cart after redeeming, in Codes and cart, off by default. When it’s on, the widget puts a newly redeemed discount code on the customer’s cart and reloads the page once the code is there. No event fires. Store credit rewards aren’t affected.
- Reload after adding a free product, in Codes and cart, off by default. When it’s on, the page reloads one second after a customer applies a free product reward or adds it to the cart. The reload can come before the event.
- Page to open after copying a code, in Links, empty by default. When it’s set, that page opens two seconds after a customer applies a code.
Example: refresh a custom cart
The embed sends the code to Shopify, but it doesn’t redraw your cart. Read the cart again when the event fires, and check whether the code applies to what’s in it:renderCartDiscount stands for your own function that updates the cart. Shopify lists the code in discount_codes as soon as the discount link succeeds, even when the cart is empty or the code doesn’t apply to its items. On the demo store, an empty cart listed the code with "applicable": false. Check applicable before you tell the customer a discount is in place.
Further reading
Build your own frontend
Show points and rewards in your own design with the Storefront API.
Metafields and tags
The rules, settings and customer data the app publishes to your theme.