insights
This is the React InstantSearch v7 documentation. React InstantSearch v7 is the latest version of React InstantSearch and the stable version of React InstantSearch Hooks.
If you were using React InstantSearch v6, you can upgrade to v7.
If you were using React InstantSearch Hooks, you can still use the React InstantSearch v7 documentation, but you should check the upgrade guide for necessary changes.
If you want to keep using React InstantSearch v6, you can find the archived documentation.
const middleware = createInsightsMiddleware({ // Optional parameters insightsClient: InsightsClient | null, insightsInitParams: object, onEvent: function, })
1
import { createInsightsMiddleware } from 'instantsearch.js/es/middlewares';
About this middleware
You can use the insights
option instead of setting up the Insights middleware yourself.
The createInsightsMiddleware
creates an insights middleware to help you achieve the following:
- Set the
userToken
for insights purposes (Click Analytics, Personalization, etc.) - Automatically send events from built-in widgets. You can turn this off if needed
- Send events from your own custom widgets
Requirements
- Use
search-insights
v1.6.2 or later.
Examples
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { createInsightsMiddleware } from 'instantsearch.js/es/middlewares';
import { useInstantSearch } from 'react-instantsearch';
import { useLayoutEffect } from 'react';
import algoliasearch from 'algoliasearch/lite';
function InsightsMiddleware() {
const { addMiddlewares } = useInstantSearch();
useLayoutEffect(() => {
const middleware = createInsightsMiddleware({
insightsClient: window.aa,
});
return addMiddlewares(middleware);
}, [addMiddlewares]);
return null;
}
const searchClient = algoliasearch('YourApplicationID', 'YourSearchOnlyAPIKey');
function App() {
return (
<InstantSearch indexName="instant_search" searchClient={searchClient}>
{/* ... */}
<InsightsMiddleware />
</InstantSearch>
);
}
Options
Parameter | Description | ||
---|---|---|---|
insightsClient
|
type: InsightsClient | null
Optional
The Insights client is used to send events. It synchronizes the user token between search and analytics calls. To disable |
||
Copy
|
|||
insightsInitParams
|
type: object
Optional
Insights parameters to forward to the Insights client’s With With |
||
Copy
|
|||
onEvent
|
type: (event: InsightsEvent, aa: null | InsightsClient) => void
default: undefined
Optional
By default, the middleware sends events to Algolia using the provided If you want to use The
|
||
Copy
|
Custom events
Parameter | Description | ||
---|---|---|---|
Connectors
|
Many of the InstantSearch connectors expose the Here’s a list of connectors that expose |
||
Copy
|