Subscribe to Instant button click events
Subscribing to instant button click events allows you to perform custom actions in response to user interactions on your site. For example, you might initiate a "checkout started" event to track user behaviour for analytics purposes.
How to Subscribe
To start receiving click events from instant buttons, subscribe to the instant_button_clicked
event. This is accomplished using the window.addEventListener
method in JavaScript.
Step-by-Step Implementation
Event Listener: Add an event listener to the window object to listen for the instant_button_clicked
event. This event is triggered each time an instant button is clicked.
window.addEventListener('instant_button_clicked', function(event) {
const buttonSource = event.detail;
// Use the buttonSource to perform any desired actions
// Add custom functionality
});
Event Details: When an instant button is clicked, the event.detail
provides information about the source of the button click, such as whether the button was clicked from the mini-cart or the cart page.