/
Add-To-Cart Events

Add-To-Cart Events

This section explains how you can listen to add-to-cart events trigger actions.

Events

Event Name: przGreenbackAddToCartEvent

The przGreenbackAddToCartEvent event fires when adding to the cart is triggered in the Greenback widget. The event will contain products in an array of objects and each has IDs and quantity.

Syntax

Use the code below to listen to the event when it fires.

document.addEventListener('przGreenbackAddToCartEvent', function(event) { const items = event.detail; // Do what you want to do with product in items, e.g. refresh cart })

Data

Name

Data Type

Example

Explain

Name

Data Type

Example

Explain

detail

array

[ { id: "1234", productId: "1111", quantity: 1 }, { id: “4421”, productId: "2222", quantity: 1 } ]

The detail contains a list of products added to the cart.

  1. id: product variant id

  2. productId: product id

  3. quantity: number of products added

Implementation

Example

document.addEventListener('przGreenbackAddToCartEvent', function(event) { const items = event.detail; // Refresh cart })

Test without a developer

You can test without modifying the code

  1. Inspect the page
    Go to the page that has the Greenback widget on. Right-click on the page and click on inspect. It opens up the devtool panel. Then click on the console tab within the dev tool panel.

  2. Add event listener
    Within the console panel copy and paste the sample code below.

    document.addEventListener('przGreenbackAddToCartEvent', function(event) { const items = event.detail; console.log('Items added to cart:', items); })

    Press enter

  3. Add product to cart
    Navigate to the Greenback widget and interact with the chat to add a product to the cart while keeping the console open. Once the add-to-cart is triggered you should see a message in the console showing all items passed in the event.

    image-20250321-033125.png

Related content