Send click and conversion events with React InstantSearch
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.
On this page
What are events?
Events are actions that users take on your app or website. They unlock powerful features, such as recommendations, personalization, smarter search results, and analytics that help you optimize your user experience.
For more information, see Get started with click and conversion events.
How to send events
InstantSearch widgets can automatically send certain events if you enable the insights
option when setting up your app.
For a full guide to implementing events, see Send events with InstantSearch.
Default events
With the insights
middleware, your InstantSearch widgets send default events.
To check the default events, go to the Events Debugger.
For more information, see Validate your events.
Default click
events for refinement widgets
The following widgets send click
events (“Filter Applied”) when users select a refinement.
Custom widgets using the hooks send the same events.
Widget | Hook |
---|---|
<HierarchicalMenu> |
useHierarchicalMenu |
<Menu> |
useMenu |
<RefinementList> |
useRefinementList |
<ToggleRefinement> |
useToggleRefinement |
Numeric refinement widgets don’t send clicked
events as the clickedFilters
event does not apply to numeric filters. This is relevant for useNumericMenu
- and useRange
-based widgets.
Default view
events for results widgets
The following widgets send view
events (“Hits Viewed”) for the visible items in the search results.
Custom widgets using the connectors send the same events.
Widget | Hook |
---|---|
<Hits> |
useHits |
<InfiniteHits> |
useInfiniteHits |
Default click
events for results widgets
The following widgets send click
events (“Hit Clicked”) when users click a search result.
Widget | Hook |
---|---|
<Hits> |
useHits |
<InfiniteHits> |
useInfiniteHits |
Because of technical limitations, the default click
events aren’t sent when using useHits
or useInfiniteHits
. If you’re using hooks, make sure to set up click
events on them.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
function CustomHits(props) {
const { items, sendEvent } = useHits(props); // or `useInfiniteHits`
return (
<ul>
{items.map((item) => (
<li
key={item.objectID}
onClick={() => {
sendEvent('click', item, 'Hit Clicked');
}}
>
{item.name}
</li>
))}
</ul>
);
}