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 listenarrow-up-right

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 thisarrow-up-right for API documentation on each of these event types and it's associated payload

Lifecycle Events

circle-info

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. Refer to our API documentation on prerequestarrow-up-right.

prerender

After receiving response from the recommendation request but before recommendations are rendered. Refer to our API documentation on prerenderarrow-up-right.

postrender

**Only For HTML response mode.

After recommendations are rendered/injected on the page. Refer to our API documentation on postrenderarrow-up-right.

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). Refer to our API documentation on taggingsentarrow-up-right.

taggingresent

When tagging data is resent. Associated with sendTaggingarrow-up-right (a.k.a resendAllTagging) API. Payload is the tagging data from the store page. Refer to our API documentation on taggingresentarrow-up-right.

carttaggingresent

When cart contents are resent to Nosto either using the resendCartTaggingarrow-up-right or resendCartContentarrow-up-right API. Payload is the cart items extracted from tagging (resendCartTagging) or the cart items from the supplied cart object (resendCartContent). Refer to our API documentation on carttaggingresentarrow-up-right.

customertaggingresent

When customer info is resent to Nosto from page tagging. Associated with the resendCustomerTaggingarrow-up-right API. Payload is the customer info extracted from the page tagging. Refer to our API documentation on customertaggingresentarrow-up-right.

emailgiven

When customer info is sent to Nosto either using the customerarrow-up-right API or using the discount popup. Payload is the customer object which is being sent to Nosto. Refer to our API documentation on emailgivenarrow-up-right.

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. Refer to our API documentation on popupopenedarrow-up-right.

popupmaximized

When a popup is maximized from ribbon mode. Payload is the campaign ID associated with the popup. Refer to our API documentation on popupmaximizedarrow-up-right.

popupminimized

When a popup is minimized into a ribbon. Payload is the campaign ID associated with the popup. Refer to our API documentation on popupminimizedarrow-up-right.

popupclosed

When a popup is closed in the page. Refer to our API documentation on popupclosedarrow-up-right.

popupribbonshown

When a popup ribbon is activated on page load or when popup is minimized. Refer to our API documentation on popupribbonshownarrow-up-right.

Tagging Events

Event Name
Description

cartupdated

**Only for Shopify merchants.

Whenever the a product is added or removed from cart. Refer to our API documentation on cartupdatedarrow-up-right.

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 unlistenarrow-up-right.

Example usage

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

Last updated

Was this helpful?