feat(chat): send events from hits in chat#6943
Conversation
More templates
algoliasearch-helper
instantsearch-ui-components
instantsearch.css
instantsearch.js
react-instantsearch
react-instantsearch-core
react-instantsearch-nextjs
react-instantsearch-router-nextjs
vue-instantsearch
commit: |
Haroenv
left a comment
There was a problem hiding this comment.
can be two separate PRs, but we should also send the click event by default like on hits
There was a problem hiding this comment.
Pull request overview
This PR wires Algolia Insights event tracking into chat carousel tool results so clicks on rendered hits can emit sendEvent events with the metadata needed for Insights.
Changes:
- Pass
sendEventthrough the chat tool pipeline (connector → tool props → carousel). - Enrich chat tool hits with
__queryIDand__position(fallbacks) for Insights payload construction. - Update types and unit tests to account for the new
sendEventplumbing.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/react-instantsearch/src/widgets/chat/tools/tests/SearchIndexTool.test.tsx | Updates test renders to provide the new required sendEvent prop. |
| packages/react-instantsearch/src/widgets/chat/tools/SearchIndexTool.tsx | Enriches tool hits with __queryID/__position and forwards sendEvent into the carousel. |
| packages/instantsearch.js/src/widgets/chat/chat.tsx | Mirrors the hit enrichment and sendEvent forwarding for the InstantSearch.js chat widget template path. |
| packages/instantsearch.js/src/connectors/chat/connectChat.ts | Injects sendEvent into tool instances exposed to the UI layer. |
| packages/instantsearch.js/src/connectors/chat/tests/connectChat-test.ts | Extends connector expectations to include sendEvent. |
| packages/instantsearch-ui-components/src/components/chat/types.ts | Adds sendEvent typing to chat tool component props/tool definitions. |
| packages/instantsearch-ui-components/src/components/chat/ChatMessage.tsx | Ensures sendEvent is always provided to tool layout components (fallback to no-op). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
packages/react-instantsearch/src/widgets/chat/tools/SearchIndexTool.tsx
Outdated
Show resolved
Hide resolved
packages/react-instantsearch/src/widgets/chat/tools/__tests__/SearchIndexTool.test.tsx
Show resolved
Hide resolved
| const items = output?.hits || []; | ||
| const items = (output?.hits || []).map((hit, index) => ({ | ||
| ...hit, | ||
| __queryID: hit.__queryID || output?.queryID, |
There was a problem hiding this comment.
- how does hit already have __queryID? and if it sometimes has it, why do we fall back to the output's query id?
- why not using the addHitPosition / addQueryID function as hits does?
There was a problem hiding this comment.
Fixed!
- I think I initially thought queryID is in the hits but it's actually in the main request body after verifying it from several tool calls. Removed this old code now.
- Did not think to look in the connectors to see if a util already exists 😅, thanks!
| const hitsWithAbsolutePosition = addAbsolutePosition( | ||
| output?.hits || [], | ||
| 0, // no page info in the tool input/output so assuming page 0 | ||
| input?.number_of_results ?? 5 // defaulting to 5 if number_of_results is not provided |
There was a problem hiding this comment.
can we use the hits.length if not provided? seems better even though it's still wrong of course
There was a problem hiding this comment.
good idea, added it now. although since technically the output.hits can still be undefined, we need to have a fallback (still kept it as 5 for now)
packages/react-instantsearch/src/widgets/chat/tools/SearchIndexTool.tsx
Outdated
Show resolved
Hide resolved
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 25 |
| Duplication | 1 |
TIP This summary will be updated as you push new changes. Give us feedback
FX-3734
Added
sendEventto the Carousel in the Search index tool component.