Class

SpressoSdk

SpressoSdk

Instantiated as the global variable window.SpressoSdk on page load.

Methods

# queueEvent(data)

Generic method to send event data. See TEventName for a list of supported events.

Parameters:
Name Type Description
data object
eventName TEventName

See TEventName for a list of possible values.

eventData object

See TEventName for required eventData properties.

Example
SpressoSdk.queueEvent('VIEW_PDP', {
	variantSku: 'some-unique-identifier',
	variantPrice: 100000
});

# registerGlimpsePLE(eventData)

Registers a listener that invokes SpressoSdk#trackGlimpsePLE on the first appearance of a Product List Entity (PLE) within either the browser viewport or a bounding rectangle (if specified).

Note: do not use SpressoSdk#trackGlimpsePLE if you opt to use this method.

Parameters:
Name Type Attributes Default Description
eventData object
root HTMLElement <optional>
null

The parent container of the PLE elements, whose bounding rectangle will be considered the viewport. Defaults to browser viewport.

target HTMLElement

The PLE element to be glimpsed.

glimpseThreshold number <optional>
1

The area of the PLE element that's visible in the viewport, expressed as a ratio, to trigger the event.

userId string | null

The customer's user ID. Pass in null value if the customer is not logged in.

variantSku string

The unique identifier of the product variant.

variantName string

The name of the product variant.

variantPrice number

The unit selling price of the variant.

productId string <optional>

The unique identifier of the product to which the variant belongs.

postalCode string <optional>

The customer's postal code.

remoteAddress string <optional>

The 'x-forwarded-for' HTTP request header.

refUserId string <optional>

Other customer unique identifier.

# registerGlimpseProductPLE(eventData)

Registers a listener that invokes SpressoSdk#trackGlimpseProductPLE on the first appearance of a Product List Entity (PLE) within either the browser viewport or a bounding rectangle (if specified).

Note: do not use SpressoSdk#trackGlimpseProductPLE if you opt to use this method.

Parameters:
Name Type Attributes Default Description
eventData object
root HTMLElement <optional>
null

The parent container of the PLE elements, whose bounding rectangle will be considered the viewport. Defaults to browser viewport.

target HTMLElement

The PLE element to be glimpsed.

glimpseThreshold number <optional>
1

The area of the PLE element that's visible in the viewport, expressed as a ratio, to trigger the event.

userId string | null

The customer's user ID. Pass in null value if the customer is not logged in.

productId string

The unique identifier of the product.

productName string

The name of the product.

minPriceRange number

The price of the cheapest variant that belongs to the product.

maxPriceRange number

The price of the most expensive variant that belongs to the product.

postalCode string <optional>

The customer's postal code.

remoteAddress string <optional>

The 'x-forwarded-for' HTTP request header.

refUserId string <optional>

Other customer unique identifier.

# trackCreateOrder(eventData)

Tracks when a user places a successful order.

This is a mandatory event.

Parameters:
Name Type Attributes Description
eventData object
userId string | null

The customer's user ID. Pass in null value if the customer is not logged in.

orderNumber string

The unique identifier for the customer's order.

totalOrderPrice number

The total price of the order that a customer is paying for (inclusive of tax and shipping).

shippingInfoAddressLine1 string
shippingInfoAddressLine2 string
shippingInfoCity string
shippingInfoState string
shippingInfoPostalCode string
shippingInfoCountry string
shippingInfoFirstName string
shippingInfoLastName string
totalVariantQuantity number <optional>

Strongly recommended. The total quantity amount of the order.

totalVariantPrice number <optional>

Strongly recommended. The extended selling price of the variant.

orderTax number <optional>

Order-level taxes.

totalOrderFees number <optional>

The total value of order-level fees such as shipping, delivery, convenience, service fees.

orderFees Array.<{type: string, id: string, value: number}> <optional>

An array of order-level fees such as shipping, delivery, convenience, service fees.

totalOrderDeductions number <optional>

The total value of promo codes or discounts or credits or loyalty promotions.

orderDeductions Array.<{type: string, id: string, value: number}> <optional>

An array of all promo codes or discounts or credits or loyalty promotions.

refUserId string <optional>

Other customer unique identifier.

# trackGlimpsePLE(eventData)

Tracks when a user views a variant Product List Element (PLE). Should only fire when a variant PLE first becomes visible in the browser viewport.

This is a mandatory event.

Note: do not use this method if you opt to use SpressoSdk#registerGlimpsePLE.

Parameters:
Name Type Attributes Description
eventData object
userId string | null

The customer's user ID. Pass in null value if the customer is not logged in.

variantSku string

The unique identifier of the product variant.

variantName string

The name of the product variant.

variantPrice number

The unit selling price of the variant.

productId string <optional>

The unique identifier of the product to which the variant belongs.

postalCode string <optional>

The customer's postal code.

remoteAddress string <optional>

The 'x-forwarded-for' HTTP request header.

refUserId string <optional>

Other customer unique identifier.

# trackGlimpseProductPLE(eventData)

Tracks when a user views a product Product List Element (PLE). Should only fire when a product PLE first becomes visible in the browser viewport.

This is an optional event.

Note: do not use this method if you opt to use SpressoSdk#registerGlimpseProductPLE.

Parameters:
Name Type Attributes Description
eventData object
userId string | null

The customer's user ID. Pass in null value if the customer is not logged in.

productId string

The unique identifier of the product.

productName string

The name of the product.

minPriceRange number

The price of the cheapest variant that belongs to the product.

maxPriceRange number

The price of the most expensive variant that belongs to the product.

postalCode string <optional>

The customer's postal code.

remoteAddress string <optional>

The 'x-forwarded-for' HTTP request header.

refUserId string <optional>

Other customer unique identifier.

# trackPageView(eventData)

Tracks when a user navigates to any page on the site. Should only fire once on fresh page load or after a SPA transition.

This is a mandatory event.

Parameters:
Name Type Attributes Description
eventData object
userId string | null

The customer's user ID. Pass in null value if the customer is not logged in.

remoteAddress string

The 'x-forwarded-for' HTTP request header.

postalCode string <optional>

The customer's postal code.

refUserId string <optional>

Other customer unique identifier.

# trackPurchaseVariant(eventData)

Tracks when a user places a successful order. Should be invoked once for every unique product variant in the order.

This is a mandatory event.

Parameters:
Name Type Attributes Description
eventData object
userId string | null

The customer's user ID. Pass in null value if the customer is not logged in.

orderNumber string

The unique identifier for the customer's order.

variantSku string

The unique identifier of the product variant.

variantName string

The name of the product variant.

variantPrice number

The unit selling price of the variant.

variantQuantity number

Variant quantity.

variantStandardPrice number <optional>

Strongly recommended. The default base unit price of the variant not inclusive of price optimization or promotions.

variantTotalPrice number <optional>

Strongly recommended. The extended total price of the variant inclusive of tax and shipping.

refUserId string <optional>

Other customer unique identifier.

# trackTapAddToCart(eventData)

Tracks when a user adds a product variant to cart. Should fire everytime a user clicks on a link/button to add product variant to cart.

This is a mandatory event.

Parameters:
Name Type Attributes Description
eventData object
userId string | null

The customer's user ID. Pass in null value if the customer is not logged in.

variantSku string

The unique identifier of the product variant.

variantName string

The name of the product variant.

variantPrice number

The unit selling price of the variant.

productId string <optional>

The unique identifier of the product to which the variant belongs.

postalCode string <optional>

The customer's postal code.

remoteAddress string <optional>

The 'x-forwarded-for' HTTP request header.

refUserId string <optional>

Other customer unique identifier.

# trackViewPDP(eventData)

Tracks when a user navigates to a Product Display Page (PDP). Should only fire once on fresh page load or after a SPA transition. Should be used in addition to SpressoSdk#trackPageView.

This is a mandatory event.

Parameters:
Name Type Attributes Description
eventData object
userId string | null

The customer's user ID. Pass in null value if the customer is not logged in.

variantSku string

The unique identifier of the product variant.

variantName string

The name of the product variant.

variantPrice number

The unit selling price of the variant.

productId string <optional>

The unique identifier of the product to which the variant belongs.

inStock boolean <optional>

Variant's stock availability.

postalCode string <optional>

The customer's postal code.

remoteAddress string <optional>

The 'x-forwarded-for' HTTP request header.

refUserId string <optional>

Other customer unique identifier.

Type Definitions

object

# TEventName

Properties:
Name Type Description
CREATE_ORDER string

Requires the same eventData as SpressoSdk#trackCreateOrder.

GLIMPSE_PLE string

Requires the same eventData as SpressoSdk#trackGlimpsePLE.

GLIMPSE_PRODUCT_PLE string

Requires the same eventData as SpressoSdk#trackGlimpseProductPLE.

PAGE_VIEW string

Requires the same eventData as SpressoSdk#trackPageView.

PURCHASE_VARIANT string

Requires the same eventData as SpressoSdk#trackPurchaseVariant.

TAP_ADD_TO_CART string

Requires the same eventData as SpressoSdk#trackTapAddToCart.

VIEW_PDP string

Requires the same eventData as SpressoSdk#trackViewPDP.