Event API: Listening to Bus Events with api.listen

Overview

Registers a listener for Nosto JS API events. Use this to react to specific lifecycle or user events dispatched by the Nosto client.

api.listen(event: BusEvent, callback: (...args) => void)

Check out the API documentation for listen

Example Usage

nostojs(api => {
  api.listen('taggingsent', (response) => {
    // 'response' from recommendation request 
    // consume response if necessary
    console.log('Tagging data was sent to Nosto');
  });
});

Supported BusEvent Types

The following table lists all event types supported by the listen API. See this for API documentation on each of these event types and it's associated payload

Lifecycle Events

A Nosto recommendation request is sent to the /ev1 endpoint and returns the product recommendation(s) for placements injected on the page.

A recommendation response is the response returned from the /ev1 endpoint.

Event Name
Description

prerequest

Before a recommendation request is sent to Nosto. Payload is the data that's sent in the recommendation request.

prerender

After receiving response from the recommendation request but before recommendations are rendered.

postrender

**Only For HTML response mode.

After recommendations are rendered/injected on the page.

taggingsent

After receiving recommendation response and the recommendations are rendered. Payload is the response data from the recommendation request, all placement - campaign markup mapping that will be injected (unFilledElements) and all placement -campaign markup mapping that's injected (filledElements).

taggingresent

When tagging data is resent. Associated with sendTagging (a.k.a resendAllTagging) API. Payload is the tagging data from the store page.

carttaggingresent

When cart contents are resent to Nosto either using the resendCartTagging or resendCartContent API. Payload is the cart items extracted from tagging (resendCartTagging) or the cart items from the supplied cart object (resendCartContent).

customertaggingresent

When customer info is resent to Nosto from page tagging. Associated with the resendCustomerTagging API. Payload is the customer info extracted from the page tagging.

emailgiven

When customer info is sent to Nosto either using the customer API or using the discount popup. Payload is the customer object which is being sent to Nosto.

Event Name
Description

popupopened

When a discount popup is opened and displayed on the store page. Payload is the campaign ID associated with the popup and the trigger that caused the popup to display.

popupmaximized

When a popup is maximized from ribbon mode. Payload is the campaign ID associated with the popup.

popupminimized

When a popup is minimized into a ribbon. Payload is the campaign ID associated with the popup.

popupclosed

When a popup is closed in the page.

popupribbonshown

When a popup ribbon is activated on page load or when popup is minimized.

Tagging Events

Event Name
Description

cartUpdated

**Only for Shopify merchants.

Whenever the a product is added or removed from cart.

Unregistering listener

Use the unlisten method to remove a previously registered event handler for a specific event type, using the listen API method. Check out the API documentation for unlisten.

Example usage

// Register a listener
api.listen('taggingsent', onTaggingSent);

// Unregister the listener
api.unlisten('taggingsent', onTaggingSent);

function onTaggingSent(response) {
  console.log('Tagging sent:', response);
}

Note: If the callback was not previously registered for the event, calling unlisten has no effect.

Last updated

Was this helpful?