Class: AddToCartFormListener

AddToCartFormListener(cart)

'ga4_add_to_cart' - triggered when the quantity of an item is increased on the /cart page. Listens for the cart form submit event. Uses the CartJS cart to query the item that was updated and generate the event payload. Reuses the `createPayload` implementation of AddToCartButtonListener.

Constructor

new AddToCartFormListener(cart)

Parameters:
Name Type Description
cart Object the CartJS cart object
Source:

Extends

Classes

AddToCartFormListener

Members

addedItems :Array

Getter that returns an array of items that were added to the cart. The array is empty if no items were added. Subclasses can override this method to control the event payload.
Type:
  • Array
Overrides:
Source:

Methods

getNewQuantities() → {Array.<number>}

Gets the new quantity values for each item on the /cart page. This is used to determine which items increased in quantity (ie, addedItems)
Source:
Returns:
the quantity values from the cart form
Type
Array.<number>

getQuantityDifference(item) → {number}

Compares the added item against the existing cart and returns the difference in quantity.
Parameters:
Name Type Description
item Object the item added
Properties
Name Type Description
id string | number
quantity number
Overrides:
Source:
Returns:
the quantity increase in the added item
Type
number