Event bus

You can create an event bus to handle some events in your store. The main purpose of this feature is to create an abstract way to react to different actions that your client is performing in the store. For example, you can emit events to Google Analytics or to the Facebook Pixel.

Creating Event Bus

import { createHeseyaEventBusService } from '@heseya/store-core'

const eventBus = createHeseyaEventBusService()

Listening and emitting events

import { HeseyaEvent } from '@heseya/store-core'

eventBus.on(HeseyaEvent.AddToCart, (product) => {
  gtm.emit('add_to_cart', { product_id: product.id })
})

eventBus.emit(HeseyaEvent.AddToCart, { id: '123' })

Available events

EventPayloadDescription
HeseyaEventType.ViewProductProductView product page
HeseyaEventType.ViewProductList{ set?: Partial<ProductSetList>; items: ProductList[] }View list of the products
HeseyaEventType.CustomizeProductCartItemThe customisation of products through a configuration tool
HeseyaEventType.AddToCartCartItemThe addition of an item to a shopping cart or basket
HeseyaEventType.ViewCartCartItem[]Show the shopping cart page
HeseyaEventType.RemoveFromCartCartItemRemove item from cart
HeseyaEventType.AddToWishlistProductThe addition of items to a wishlist
HeseyaEventType.InitiateCheckoutCartItem[]The start of a checkout process
HeseyaEventType.AddShippingInfo{ shipping: ShippingMethod; items: CartItem[] }Add shipping information to a checkout
HeseyaEventType.Purchase{ order: OrderSummary; items: CartItem[] }The completion of a purchase, usually signified by receiving order or purchase confirmation, or a transaction receipt
HeseyaEventType.SearchstringA search performed on your website or app
HeseyaEventType.RegisterUserA submission of information by a customer in exchange for a service provided by your business
HeseyaEventType.LoginUserUser log in.
HeseyaEventType.ViewContentunknownA visit to a web page you care about.