Class: AddToCartRequestListener

AddToCartRequestListener(request, cart)

'ga4_add_to_cart' - triggered when a request to '/cart/add.js' resolves successfully. Uses an XMLHttpRequest object to determine the item added to the cart. Uses the CartJS cart to query the item that was updated and generate the event payload. Reuses the `createPayload` implementation of AddToCartButtonListener.

Constructor

new AddToCartRequestListener(request, cart)

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

Extends

Classes

AddToCartRequestListener

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

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