Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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 an ID IDs and quantity.

Syntax

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

...

Name

Data Type

Example

Explain

detail

array

Code Block
languagejson
[
  {
    id: "1234",
    productId: “1234”"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

...

  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.

    Code Block
    languagejs
    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 Removedimage-20250321-033125.pngImage Added