JavaScript SDK events

In order to listen to Snipcart events, you can use the on method:

Snipcart.events.on('{eventName}', callback);

Public events

item.adding

Before an item gets added to the cart, an item.adding event is triggered. The callback function receives the ParsedCartItem as an argument.

Snipcart.events.on('item.adding', (parsedCartItem) => {
    console.log(parsedCartItem);
});

item.added

After an item gets added to the cart, an item.added event is triggered. The callback function receives the ParsedCartItem as an argument.

Snipcart.events.on('item.added', (parsedCartItem) => {
    console.log(parsedCartItem);
});

cart.created

When a cart gets created (e.g., when an item gets added for the first time), a cart.created event is triggered. The callback function receives the CartResponse as an argument.

Snipcart.events.on('cart.created', (cartResponse) => {
    console.log(cartResponse);
});

cart.confirmed

When an order is placed and the cart gets confirmed successfully, a cart.confirmed event is triggered. The callback function receives the CartConfirmResponse as an argument.

Snipcart.events.on('cart.confirmed', (cartConfirmResponse) => {
    console.log(cartConfirmResponse);
});

customer.registered

When customers create an account so they can access their customer dashboard, a customer.registered event is triggered. The callback function receive the CustomerAuthenticationResponse as an argument.

Snipcart.events.on('customer.registered', (authResponse) => {
    console.log(`Customer ${authResponse.customer.email} just created an account.`);
});

customer.signedin

When a customer signs into their customer dashboard, a customer.signedin event is triggered. The callback function receives the CustomerAuthenticationResponseas an argument.

Snipcart.events.on('customer.signedin', (authResponse) => {
    console.log(`Customer ${authResponse.customer.email} just signed in.`);
});

customer.signedout

When a customer signs out, a customer.signedout event is triggered. The callback doesn't receive any parameters.

Snipcart.events.on('customer.signedout', () => {
    console.log('Customer signed out');
});

Browser context events

summary.checkout_clicked

When a customer clicks on a show cart button, a summary.checkout_clicked event is triggered. In this case, the callback function takes no arguments.

Snipcart.events.on('summary.checkout_clicked', () => {
    // Anything goes...
});