From 2679a5e6a5e5767fc3b1c1e074c53ab6a084e7f3 Mon Sep 17 00:00:00 2001 From: Maria Lungu Date: Wed, 15 Jan 2025 18:48:47 +0100 Subject: [PATCH] feat(recommend): add support for event collection in recommend (#6523) --------- Co-authored-by: Raed --- .../src/components/Carousel.tsx | 9 ++++ .../components/__tests__/Carousel.test.tsx | 5 +++ .../src/components/recommend-shared/List.tsx | 8 +++- .../src/types/Recommend.ts | 3 +- .../connectFrequentlyBoughtTogether.ts | 41 +++++++++++++++-- .../looking-similar/connectLookingSimilar.ts | 44 +++++++++++++++--- .../connectRelatedProducts.ts | 45 ++++++++++++++++--- .../trending-items/connectTrendingItems.ts | 45 ++++++++++++++++--- .../src/templates/__tests__/carousel.test.tsx | 4 ++ .../src/templates/carousel/carousel.tsx | 4 ++ .../frequently-bought-together.test.tsx | 6 ++- .../frequently-bought-together.tsx | 11 +++-- .../__tests__/looking-similar.test.tsx | 6 ++- .../looking-similar/looking-similar.tsx | 12 ++++- .../__tests__/related-products.test.tsx | 6 ++- .../related-products/related-products.tsx | 11 +++-- .../__tests__/trending-items.test.tsx | 6 ++- .../widgets/trending-items/trending-items.tsx | 11 +++-- .../__tests__/useRelatedProducts.test.tsx | 11 ++++- .../__tests__/useTrendingItems.test.tsx | 11 ++++- .../components/__tests__/Carousel.test.tsx | 4 ++ .../src/widgets/FrequentlyBoughtTogether.tsx | 8 ++-- .../src/widgets/LookingSimilar.tsx | 8 ++-- .../src/widgets/RelatedProducts.tsx | 8 ++-- .../src/widgets/TrendingItems.tsx | 8 ++-- .../FrequentlyBoughtTogether.test.tsx | 6 ++- .../widgets/__tests__/LookingSimilar.test.tsx | 6 ++- .../__tests__/RelatedProducts.test.tsx | 6 ++- .../widgets/__tests__/TrendingItems.test.tsx | 6 ++- .../frequently-bought-together/options.ts | 12 +++-- .../common/widgets/looking-similar/options.ts | 12 +++-- .../widgets/related-products/options.ts | 12 +++-- .../common/widgets/trending-items/options.ts | 12 +++-- 33 files changed, 322 insertions(+), 85 deletions(-) diff --git a/packages/instantsearch-ui-components/src/components/Carousel.tsx b/packages/instantsearch-ui-components/src/components/Carousel.tsx index 452cec3e80..ed6b18fb51 100644 --- a/packages/instantsearch-ui-components/src/components/Carousel.tsx +++ b/packages/instantsearch-ui-components/src/components/Carousel.tsx @@ -9,6 +9,7 @@ import type { RecommendItemComponentProps, RecordWithObjectID, Renderer, + SendEventForHits, } from '../types'; export type CarouselProps< @@ -28,6 +29,7 @@ export type CarouselProps< nextIconComponent?: () => JSX.Element; classNames?: Partial; translations?: Partial; + sendEvent: SendEventForHits; }; export type CarouselClassNames = { @@ -135,6 +137,7 @@ export function createCarouselComponent({ createElement, Fragment }: Renderer) { nextIconComponent: NextIconComponent = NextIconDefaultComponent, items, translations: userTranslations, + sendEvent, ...props } = userProps; @@ -235,6 +238,12 @@ export function createCarouselComponent({ createElement, Fragment }: Renderer) { className={cx(cssClasses.item)} aria-roledescription="slide" aria-label={`${index + 1} of ${items.length}`} + onClick={() => { + sendEvent('click:internal', item, 'Item Clicked'); + }} + onAuxClick={() => { + sendEvent('click:internal', item, 'Item Clicked'); + }} > diff --git a/packages/instantsearch-ui-components/src/components/__tests__/Carousel.test.tsx b/packages/instantsearch-ui-components/src/components/__tests__/Carousel.test.tsx index 9f906e705d..802dbca496 100644 --- a/packages/instantsearch-ui-components/src/components/__tests__/Carousel.test.tsx +++ b/packages/instantsearch-ui-components/src/components/__tests__/Carousel.test.tsx @@ -43,6 +43,7 @@ describe('Carousel', () => { test('renders items', () => { const { container } = render( { test('renders custom "Previous" and "Next" components', () => { const { container } = render( { test('accepts custom translations', () => { const { container } = render( { test('forwards `div` props to the root element', () => { const { container } = render(