Listening for checkout and express payment clicks
Listen for the lcu:checkout:clicked DOM event to run code when a customer clicks Checkout or an express payment button.
You can listen for both standard checkout clicks and express payment button clicks using a single custom DOM event. This makes it easy to track customer intent, trigger analytics, or run your own logic before the customer is redirected to checkout.
Event details
The app dispatches a CustomEvent on document with the name:
lcu:checkout:clickedThis event fires whenever a customer clicks:
- The regular Checkout button, or
- An express payment button (Shop Pay, Google Pay, PayPal, and others)
All relevant information is attached to event.detail.
How to listen for the event
Add an event listener to document to capture checkout interactions anywhere on the page:
document.addEventListener('lcu:checkout:clicked', (event) => {
console.log(event.detail);
});The event bubbles on document, so you can attach a single listener and capture every checkout and express payment click on the page — no matter where the button is rendered.
Event payload
The shape of event.detail depends on which button was clicked.
Supported express payment providers
The provider field is set to one of the following values:
shop_paygoogle_paypaypalamazon_payapple_pay
Example usage
Use the type field to tell checkout and express payment clicks apart, then read the rest of the payload to respond accordingly:
document.addEventListener('lcu:checkout:clicked', (event) => {
const { type, provider, cart, timestamp } = event.detail;
if (type === 'checkout_button') {
console.log('Checkout button clicked');
} else if (type === 'express_payment') {
console.log(`${provider} button clicked`);
}
console.log('Cart total:', cart.total_price / 100);
console.log('Item count:', cart.item_count);
console.log('Clicked at:', timestamp);
});The listener runs synchronously when the button is clicked. The customer continues to checkout immediately, so keep your handler lightweight and avoid blocking work or assuming the redirect can be delayed.
Common use cases
- Tracking checkout and express payment clicks for analytics.
- Triggering custom events before the customer is redirected to checkout.
- Debugging payment button behavior.
- Differentiating conversion funnels by payment method.
Refreshing widgets
Dispatch the upsell:refresh event with the latest cart in detail.cart to make Llama Upsells widgets re-render after you change the cart from theme code.
Global JavaScript API
Reference for the namespaced runtime object the Upsell theme extension attaches to window, its bootstrap helpers, and the onProductAddToCart callback.
