Signature
About this widget
Middleware is a function that returns an object withonStateChange
,
subscribe
,
and unsubscribe
functions.
The middleware
function doesn’t perform any actions itself but lets you inject logic into InstantSearch.js,
for example, sending events to Google Analytics.
To send Algolia click and conversion events,
use the insights
middleware.
Requirements
- InstantSearch.js v4.8.3 or later.
Examples
JavaScript
Options
You have access to the instance of
instantsearch
which lets you read values from the instance or call instance methods like addWidgets
, setUiState
, and refresh
.JavaScript
Hooks
The function is called with
uiState
whenever the state changes.JavaScript
This function is called when the InstantSearch instance starts (when
search.start()
is called).
This is where you can add event listeners, subscribe to an API, and run any side effects.JavaScript
The function is called when the InstantSearch instance is disposed of.
You can clean up anything you initiated in the
subscribe
function.JavaScript