Skip to content

feat(chat): send events from hits in chat#6943

Merged
shaejaz merged 6 commits intomasterfrom
feat/chat-hits-insights-events
Mar 31, 2026
Merged

feat(chat): send events from hits in chat#6943
shaejaz merged 6 commits intomasterfrom
feat/chat-hits-insights-events

Conversation

@shaejaz
Copy link
Copy Markdown
Contributor

@shaejaz shaejaz commented Mar 27, 2026

FX-3734

Added sendEvent to the Carousel in the Search index tool component.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 27, 2026

More templates

algoliasearch-helper

npm i https://pkg.pr.new/algolia/instantsearch/algoliasearch-helper@6943

instantsearch-ui-components

npm i https://pkg.pr.new/algolia/instantsearch/instantsearch-ui-components@6943

instantsearch.css

npm i https://pkg.pr.new/algolia/instantsearch/instantsearch.css@6943

instantsearch.js

npm i https://pkg.pr.new/algolia/instantsearch/instantsearch.js@6943

react-instantsearch

npm i https://pkg.pr.new/algolia/instantsearch/react-instantsearch@6943

react-instantsearch-core

npm i https://pkg.pr.new/algolia/instantsearch/react-instantsearch-core@6943

react-instantsearch-nextjs

npm i https://pkg.pr.new/algolia/instantsearch/react-instantsearch-nextjs@6943

react-instantsearch-router-nextjs

npm i https://pkg.pr.new/algolia/instantsearch/react-instantsearch-router-nextjs@6943

vue-instantsearch

npm i https://pkg.pr.new/algolia/instantsearch/vue-instantsearch@6943

commit: 83ee8e4

Copy link
Copy Markdown
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be two separate PRs, but we should also send the click event by default like on hits

@shaejaz shaejaz marked this pull request as ready for review March 30, 2026 09:42
@shaejaz shaejaz requested review from Haroenv and Copilot March 30, 2026 09:42
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 sendEvent through the chat tool pipeline (connector → tool props → carousel).
  • Enrich chat tool hits with __queryID and __position (fallbacks) for Insights payload construction.
  • Update types and unit tests to account for the new sendEvent plumbing.

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.

const items = output?.hits || [];
const items = (output?.hits || []).map((hit, index) => ({
...hit,
__queryID: hit.__queryID || output?.queryID,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

  1. 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.
  2. Did not think to look in the connectors to see if a util already exists 😅, thanks!

Copy link
Copy Markdown
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great!

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use the hits.length if not provided? seems better even though it's still wrong of course

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

@codacy-production
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 25 complexity . 1 duplication

Metric Results
Complexity 25
Duplication 1

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

@shaejaz shaejaz requested a review from Haroenv March 31, 2026 15:29
@Haroenv Haroenv changed the title feat(chat): add insights events to hits in chat feat(chat): expose send event to hits in chat Mar 31, 2026
@Haroenv Haroenv changed the title feat(chat): expose send event to hits in chat feat(chat): send events from hits in chat Mar 31, 2026
@shaejaz shaejaz merged commit 7c9a6dd into master Mar 31, 2026
15 checks passed
@shaejaz shaejaz deleted the feat/chat-hits-insights-events branch March 31, 2026 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants