From c15dd17bcb0895c21bdf8ad4558161046f94abb2 Mon Sep 17 00:00:00 2001 From: Haroen Viaene Date: Thu, 12 Dec 2024 12:06:23 +0100 Subject: [PATCH] fix(insights): remove bindEvent (#6471) bindEvent is no longer handled in the component since #6403 (https://github.com/algolia/instantsearch/pull/6403/files#diff-e7717d55fdbbc94c7dd996f78b6f0f860332545d6fa8f6b843c940798334532cL94) [FX-3191] BREAKING CHANGE: the `bindEvent` related functions are non longer usable, use `sendEvent` instead --- .../connectors/__tests__/connectHits.test.ts | 70 ----- .../__tests__/connectInfiniteHits.test.ts | 70 ----- .../src/connectors/connectHits.ts | 18 -- .../src/connectors/connectInfiniteHits.ts | 14 - .../__tests__/createSendEventForFacet.test.ts | 27 +- .../__tests__/createSendEventForHits.test.ts | 276 +----------------- .../src/lib/utils/createSendEventForFacet.ts | 5 +- .../src/lib/utils/createSendEventForHits.ts | 45 +-- .../instantsearch-core/src/lib/utils/index.ts | 1 - .../src/lib/utils/serializer.ts | 9 - .../instantsearch-core/src/types/insights.ts | 12 - .../components/InfiniteHits/InfiniteHits.tsx | 2 - .../__tests__/InfiniteHits-test.tsx | 7 - .../__tests__/InfiniteHits.test.tsx | 1 - .../widgets/infinite-hits/infinite-hits.tsx | 2 - .../src/connectors/__tests__/useHits.test.tsx | 2 - .../__tests__/useInfiniteHits.test.tsx | 2 - 17 files changed, 33 insertions(+), 530 deletions(-) delete mode 100644 packages/instantsearch-core/src/lib/utils/serializer.ts diff --git a/packages/instantsearch-core/src/connectors/__tests__/connectHits.test.ts b/packages/instantsearch-core/src/connectors/__tests__/connectHits.test.ts index 71f1b26fbe..cbbf982ee8 100644 --- a/packages/instantsearch-core/src/connectors/__tests__/connectHits.test.ts +++ b/packages/instantsearch-core/src/connectors/__tests__/connectHits.test.ts @@ -20,7 +20,6 @@ import { createInitOptions, createRenderOptions, } from '../../../test/createWidget'; -import { deserializePayload } from '../../lib/utils'; import type { EscapedHits, @@ -509,7 +508,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hits/js/#co hits: [], items: [], sendEvent: expect.any(Function), - bindEvent: expect.any(Function), results: undefined, widgetParams: {}, }); @@ -541,7 +539,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hits/js/#co hits: expectedHits, items: expectedHits, sendEvent: renderState1.hits.sendEvent, - bindEvent: renderState1.hits.bindEvent, results, widgetParams: {}, }); @@ -573,7 +570,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hits/js/#co items: [], banner: undefined, sendEvent: expect.any(Function), - bindEvent: expect.any(Function), results: undefined, widgetParams: {}, }); @@ -611,7 +607,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hits/js/#co items: expectedHits, banner, sendEvent: renderState1.sendEvent, - bindEvent: renderState2.bindEvent, results, widgetParams: {}, }); @@ -1033,71 +1028,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hits/js/#co }); }); }); - - describe('bindEvent', () => { - it('returns a payload for click event', () => { - const { renderFn, hits } = createRenderedWidget(); - const { bindEvent } = - renderFn.mock.calls[renderFn.mock.calls.length - 1][0]; - const payload = bindEvent('click', hits[0], 'Product Added'); - expect(payload.startsWith('data-insights-event=')).toBe(true); - expect( - deserializePayload(payload.substr('data-insights-event='.length)) - ).toEqual([ - { - eventType: 'click', - hits: [ - { - __position: 0, - __queryID: 'test-query-id', - fake: 'data', - objectID: '1', - }, - ], - insightsMethod: 'clickedObjectIDsAfterSearch', - payload: { - eventName: 'Product Added', - index: '', - objectIDs: ['1'], - positions: [0], - queryID: 'test-query-id', - }, - widgetType: 'ais.hits', - }, - ]); - }); - - it('returns a payload for conversion event', () => { - const { renderFn, hits } = createRenderedWidget(); - const { bindEvent } = - renderFn.mock.calls[renderFn.mock.calls.length - 1][0]; - const payload = bindEvent('conversion', hits[1], 'Product Ordered'); - expect(payload.startsWith('data-insights-event=')).toBe(true); - expect( - deserializePayload(payload.substr('data-insights-event='.length)) - ).toEqual([ - { - eventType: 'conversion', - hits: [ - { - __position: 1, - __queryID: 'test-query-id', - objectID: '2', - sample: 'infos', - }, - ], - insightsMethod: 'convertedObjectIDsAfterSearch', - payload: { - eventName: 'Product Ordered', - index: '', - objectIDs: ['2'], - queryID: 'test-query-id', - }, - widgetType: 'ais.hits', - }, - ]); - }); - }); }); }); }); diff --git a/packages/instantsearch-core/src/connectors/__tests__/connectInfiniteHits.test.ts b/packages/instantsearch-core/src/connectors/__tests__/connectInfiniteHits.test.ts index 861d77a3cc..53a3b72ecd 100644 --- a/packages/instantsearch-core/src/connectors/__tests__/connectInfiniteHits.test.ts +++ b/packages/instantsearch-core/src/connectors/__tests__/connectInfiniteHits.test.ts @@ -18,7 +18,6 @@ import { createRenderOptions, } from '../../../test/createWidget'; import { createInfiniteHitsSessionStorageCache } from '../../lib/infiniteHitsCache'; -import { deserializePayload } from '../../lib/utils'; import type { SearchClient, @@ -1328,7 +1327,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi items: [], currentPageHits: [], sendEvent: expect.any(Function), - bindEvent: expect.any(Function), isFirstPage: true, isLastPage: true, banner: undefined, @@ -1392,7 +1390,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi items: expectedHits, currentPageHits: expectedCurrentPageHits, sendEvent: renderState1.infiniteHits.sendEvent, - bindEvent: renderState1.infiniteHits.bindEvent, isFirstPage: true, isLastPage: true, banner: undefined, @@ -1423,7 +1420,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi items: [], currentPageHits: [], sendEvent: expect.any(Function), - bindEvent: expect.any(Function), isFirstPage: true, isLastPage: true, banner: undefined, @@ -1500,7 +1496,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi items: expectedHits, currentPageHits: expectedCurrentPageHits, sendEvent: renderState1.sendEvent, - bindEvent: renderState1.bindEvent, isFirstPage: true, isLastPage: true, banner, @@ -1870,71 +1865,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/infinite-hi }); }); }); - - describe('bindEvent', () => { - it('returns a payload for click event', () => { - const { renderFn, hits } = createRenderedWidget(); - const { bindEvent } = - renderFn.mock.calls[renderFn.mock.calls.length - 1][0]; - const payload = bindEvent('click', hits[0], 'Product Added'); - expect(payload.startsWith('data-insights-event=')).toBe(true); - expect( - deserializePayload(payload.substr('data-insights-event='.length)) - ).toEqual([ - { - eventType: 'click', - hits: [ - { - __position: 0, - __queryID: 'test-query-id', - fake: 'data', - objectID: '1', - }, - ], - insightsMethod: 'clickedObjectIDsAfterSearch', - payload: { - eventName: 'Product Added', - index: '', - objectIDs: ['1'], - positions: [0], - queryID: 'test-query-id', - }, - widgetType: 'ais.infiniteHits', - }, - ]); - }); - - it('returns a payload for conversion event', () => { - const { renderFn, hits } = createRenderedWidget(); - const { bindEvent } = - renderFn.mock.calls[renderFn.mock.calls.length - 1][0]; - const payload = bindEvent('conversion', hits[1], 'Product Ordered'); - expect(payload.startsWith('data-insights-event=')).toBe(true); - expect( - deserializePayload(payload.substr('data-insights-event='.length)) - ).toEqual([ - { - eventType: 'conversion', - hits: [ - { - __position: 1, - __queryID: 'test-query-id', - objectID: '2', - sample: 'infos', - }, - ], - insightsMethod: 'convertedObjectIDsAfterSearch', - payload: { - eventName: 'Product Ordered', - index: '', - objectIDs: ['2'], - queryID: 'test-query-id', - }, - widgetType: 'ais.infiniteHits', - }, - ]); - }); - }); }); }); }); diff --git a/packages/instantsearch-core/src/connectors/connectHits.ts b/packages/instantsearch-core/src/connectors/connectHits.ts index 8ff829ad8c..026ff0ca1a 100644 --- a/packages/instantsearch-core/src/connectors/connectHits.ts +++ b/packages/instantsearch-core/src/connectors/connectHits.ts @@ -9,7 +9,6 @@ import { addAbsolutePosition, addQueryID, createSendEventForHits, - createBindEventForHits, } from '../lib/utils'; import type { @@ -21,7 +20,6 @@ import type { Unmounter, Renderer, SendEventForHits, - BindEventForHits, Widget, } from '../types'; import type { Banner, SearchResults } from 'algoliasearch-helper'; @@ -57,11 +55,6 @@ export type HitsRenderState = BaseHit> = { * Sends an event to the Insights middleware. */ sendEvent: SendEventForHits; - - /** - * Returns a string for the `data-insights-event` attribute for the Insights middleware - */ - bindEvent: BindEventForHits; }; export type HitsConnectorParams = BaseHit> = { @@ -107,7 +100,6 @@ export const connectHits = function connectHits( >, } = (widgetParams || {}) as HitsConnectorParams; let sendEvent: SendEventForHits; - let bindEvent: BindEventForHits; type HitsWidget = Widget< HitsWidgetDescription & { @@ -160,14 +152,6 @@ export const connectHits = function connectHits( }); } - if (!bindEvent) { - bindEvent = createBindEventForHits({ - getIndex: () => helper.getIndex(), - widgetType: this.$$type, - instantSearchInstance, - }); - } - if (!results) { return { hits: [], @@ -175,7 +159,6 @@ export const connectHits = function connectHits( results: undefined, banner: undefined, sendEvent, - bindEvent, widgetParams, }; } @@ -207,7 +190,6 @@ export const connectHits = function connectHits( results, banner, sendEvent, - bindEvent, widgetParams, }; }, diff --git a/packages/instantsearch-core/src/connectors/connectInfiniteHits.ts b/packages/instantsearch-core/src/connectors/connectInfiniteHits.ts index b8d13dd703..b8105d54cf 100644 --- a/packages/instantsearch-core/src/connectors/connectInfiniteHits.ts +++ b/packages/instantsearch-core/src/connectors/connectInfiniteHits.ts @@ -11,7 +11,6 @@ import { addAbsolutePosition, addQueryID, createSendEventForHits, - createBindEventForHits, } from '../lib/utils'; import type { @@ -24,7 +23,6 @@ import type { Unmounter, UnknownWidgetParams, SendEventForHits, - BindEventForHits, Widget, } from '../types'; import type { @@ -117,11 +115,6 @@ export type InfiniteHitsRenderState< */ sendEvent: SendEventForHits; - /** - * Returns a string of data-insights-event attribute for insights middleware - */ - bindEvent: BindEventForHits; - /** * Hits for the current page */ @@ -237,7 +230,6 @@ export const connectInfiniteHits = function connectInfiniteHits< let showPrevious: () => void; let showMore: () => void; let sendEvent: SendEventForHits; - let bindEvent: BindEventForHits; const getFirstReceivedPage = ( state: SearchParameters, cachedHits: InfiniteHitsCachedHits @@ -365,11 +357,6 @@ export const connectInfiniteHits = function connectInfiniteHits< getIndex: () => helper.getIndex(), widgetType: this.$$type, }); - bindEvent = createBindEventForHits({ - getIndex: () => helper.getIndex(), - widgetType: this.$$type, - instantSearchInstance, - }); isFirstPage = state.page === undefined || getFirstReceivedPage(state, cachedHits) === 0; @@ -440,7 +427,6 @@ export const connectInfiniteHits = function connectInfiniteHits< items, currentPageHits, sendEvent, - bindEvent, banner, results: results || undefined, showPrevious, diff --git a/packages/instantsearch-core/src/lib/utils/__tests__/createSendEventForFacet.test.ts b/packages/instantsearch-core/src/lib/utils/__tests__/createSendEventForFacet.test.ts index 3260c9868b..e3c0785c97 100644 --- a/packages/instantsearch-core/src/lib/utils/__tests__/createSendEventForFacet.test.ts +++ b/packages/instantsearch-core/src/lib/utils/__tests__/createSendEventForFacet.test.ts @@ -34,12 +34,11 @@ describe('createSendEventForFacet', () => { expect(() => { sendEvent('click'); }).toThrowErrorMatchingInlineSnapshot(` -"You need to pass between two and four arguments like: - sendEvent('click', facetValue, eventName?, additionalData?); + "You need to pass between two and four arguments like: + sendEvent('click', facetValue, eventName?, additionalData?); -If you want to send a custom payload, you can pass one object: sendEvent(customPayload); -" -`); + If you want to send a custom payload, you can pass one object: sendEvent(customPayload);" + `); }); it('throws with unknown eventType', () => { @@ -47,12 +46,11 @@ If you want to send a custom payload, you can pass one object: sendEvent(customP expect(() => { sendEvent('my custom event type'); }).toThrowErrorMatchingInlineSnapshot(` -"You need to pass between two and four arguments like: - sendEvent('click', facetValue, eventName?, additionalData?); + "You need to pass between two and four arguments like: + sendEvent('click', facetValue, eventName?, additionalData?); -If you want to send a custom payload, you can pass one object: sendEvent(customPayload); -" -`); + If you want to send a custom payload, you can pass one object: sendEvent(customPayload);" + `); }); it('throws when eventType is not click', () => { @@ -60,12 +58,11 @@ If you want to send a custom payload, you can pass one object: sendEvent(customP expect(() => { sendEvent('custom event type'); }).toThrowErrorMatchingInlineSnapshot(` -"You need to pass between two and four arguments like: - sendEvent('click', facetValue, eventName?, additionalData?); + "You need to pass between two and four arguments like: + sendEvent('click', facetValue, eventName?, additionalData?); -If you want to send a custom payload, you can pass one object: sendEvent(customPayload); -" -`); + If you want to send a custom payload, you can pass one object: sendEvent(customPayload);" + `); }); it('does not send event when a facet is removed', () => { diff --git a/packages/instantsearch-core/src/lib/utils/__tests__/createSendEventForHits.test.ts b/packages/instantsearch-core/src/lib/utils/__tests__/createSendEventForHits.test.ts index a08002c996..d0fa7c0e8e 100644 --- a/packages/instantsearch-core/src/lib/utils/__tests__/createSendEventForHits.test.ts +++ b/packages/instantsearch-core/src/lib/utils/__tests__/createSendEventForHits.test.ts @@ -3,11 +3,7 @@ */ import { createInstantSearch } from '../../../../test/createInstantSearch'; -import { deserializePayload } from '../../utils'; -import { - createBindEventForHits, - createSendEventForHits, -} from '../createSendEventForHits'; +import { createSendEventForHits } from '../createSendEventForHits'; import type { EscapedHits } from '../../../types'; @@ -41,11 +37,6 @@ const createTestEnvironment = ({ getIndex: () => helper.getIndex(), widgetType, }); - const bindEvent = createBindEventForHits({ - getIndex: () => helper.getIndex(), - widgetType, - instantSearchInstance, - }); return { instantSearchInstance, helper, @@ -54,7 +45,6 @@ const createTestEnvironment = ({ hits, additionalData, sendEvent, - bindEvent, }; }; @@ -65,10 +55,9 @@ describe('createSendEventForHits', () => { expect(() => { sendEvent('click'); }).toThrowErrorMatchingInlineSnapshot(` -"You need to pass hit or hits as the second argument like: - sendEvent(eventType, hit); - " -`); + "You need to pass hit or hits as the second argument like: + sendEvent(eventType, hit);" + `); }); it('throws with unknown eventType', () => { @@ -76,10 +65,9 @@ describe('createSendEventForHits', () => { expect(() => { sendEvent('my custom event type'); }).toThrowErrorMatchingInlineSnapshot(` -"You need to pass hit or hits as the second argument like: - sendEvent(eventType, hit); - " -`); + "You need to pass hit or hits as the second argument like: + sendEvent(eventType, hit);" + `); }); it('throw when eventName is missing for click or conversion event', () => { @@ -88,23 +76,21 @@ describe('createSendEventForHits', () => { // @ts-expect-error wrong input sendEvent('click', {}); }).toThrowErrorMatchingInlineSnapshot(` -"You need to pass eventName as the third argument for 'click' or 'conversion' events like: - sendEvent('click', hit, 'Product Purchased'); + "You need to pass eventName as the third argument for 'click' or 'conversion' events like: + sendEvent('click', hit, 'Product Purchased'); - To learn more about event naming: https://www.algolia.com/doc/guides/getting-insights-and-analytics/search-analytics/click-through-and-conversions/in-depth/clicks-conversions-best-practices/ - " -`); + To learn more about event naming: https://www.algolia.com/doc/guides/getting-insights-and-analytics/search-analytics/click-through-and-conversions/in-depth/clicks-conversions-best-practices/" + `); expect(() => { // @ts-expect-error wrong input sendEvent('conversion', {}); }).toThrowErrorMatchingInlineSnapshot(` -"You need to pass eventName as the third argument for 'click' or 'conversion' events like: - sendEvent('click', hit, 'Product Purchased'); + "You need to pass eventName as the third argument for 'click' or 'conversion' events like: + sendEvent('click', hit, 'Product Purchased'); - To learn more about event naming: https://www.algolia.com/doc/guides/getting-insights-and-analytics/search-analytics/click-through-and-conversions/in-depth/clicks-conversions-best-practices/ - " -`); + To learn more about event naming: https://www.algolia.com/doc/guides/getting-insights-and-analytics/search-analytics/click-through-and-conversions/in-depth/clicks-conversions-best-practices/" + `); }); }); @@ -597,235 +583,3 @@ describe('createSendEventForHits', () => { }); }); }); - -describe('createBindEventForHits', () => { - function parsePayload(payload: string): Record { - expect(payload.startsWith('data-insights-event=')).toBe(true); - return deserializePayload(payload.substr('data-insights-event='.length)); - } - - it('returns a payload for view event', () => { - const { bindEvent, hits, additionalData } = createTestEnvironment(); - const parsedPayload = parsePayload(bindEvent('view', hits)); - expect(parsedPayload).toEqual([ - { - eventType: 'view', - hits: [ - { - __position: 0, - __queryID: 'test-query-id', - objectID: 'obj0', - }, - { - __position: 1, - __queryID: 'test-query-id', - objectID: 'obj1', - }, - ], - insightsMethod: 'viewedObjectIDs', - payload: { - eventName: 'Hits Viewed', - index: 'testIndex', - objectIDs: ['obj0', 'obj1'], - }, - widgetType: 'ais.testWidget', - }, - ]); - - const parsedPayloadWithAdditionalData = parsePayload( - bindEvent('view', hits, 'Products Viewed', additionalData) - ); - expect(parsedPayloadWithAdditionalData).toEqual([ - { - eventType: 'view', - hits: [ - { - __position: 0, - __queryID: 'test-query-id', - objectID: 'obj0', - }, - { - __position: 1, - __queryID: 'test-query-id', - objectID: 'obj1', - }, - ], - insightsMethod: 'viewedObjectIDs', - payload: { - eventName: 'Products Viewed', - index: 'testIndex', - objectIDs: ['obj0', 'obj1'], - ...additionalData, - }, - widgetType: 'ais.testWidget', - }, - ]); - }); - - it('skips payload for view event when search is not idle', () => { - const { bindEvent, hits, instantSearchInstance } = createTestEnvironment(); - - instantSearchInstance.status = 'loading'; - expect(bindEvent('view', hits)).toHaveLength(0); - - instantSearchInstance.status = 'error'; - expect(bindEvent('view', hits)).toHaveLength(0); - - instantSearchInstance.status = 'stalled'; - expect(bindEvent('view', hits)).toHaveLength(0); - - instantSearchInstance.status = 'idle'; - expect(bindEvent('view', hits)).not.toHaveLength(0); - }); - - it('returns a payload for click event', () => { - const { bindEvent, hits, additionalData } = createTestEnvironment(); - const parsedPayload = parsePayload( - bindEvent('click', hits[0], 'Product Clicked') - ); - expect(parsedPayload).toEqual([ - { - eventType: 'click', - hits: [ - { - __position: 0, - __queryID: 'test-query-id', - objectID: 'obj0', - }, - ], - insightsMethod: 'clickedObjectIDsAfterSearch', - payload: { - eventName: 'Product Clicked', - index: 'testIndex', - objectIDs: ['obj0'], - positions: [0], - queryID: 'test-query-id', - }, - widgetType: 'ais.testWidget', - }, - ]); - - const parsedPayloadWithAdditionalData = parsePayload( - bindEvent('click', hits[0], 'Product Clicked', additionalData) - ); - expect(parsedPayloadWithAdditionalData).toEqual([ - { - eventType: 'click', - hits: [ - { - __position: 0, - __queryID: 'test-query-id', - objectID: 'obj0', - }, - ], - insightsMethod: 'clickedObjectIDsAfterSearch', - payload: { - eventName: 'Product Clicked', - index: 'testIndex', - objectIDs: ['obj0'], - positions: [0], - queryID: 'test-query-id', - ...additionalData, - }, - widgetType: 'ais.testWidget', - }, - ]); - }); - - it('returns a payload for conversion event', () => { - const { bindEvent, hits, additionalData } = createTestEnvironment(); - const parsedPayload = parsePayload( - bindEvent('conversion', hits[0], 'Product Ordered') - ); - expect(parsedPayload).toEqual([ - { - eventType: 'conversion', - hits: [ - { - __position: 0, - __queryID: 'test-query-id', - objectID: 'obj0', - }, - ], - insightsMethod: 'convertedObjectIDsAfterSearch', - payload: { - eventName: 'Product Ordered', - index: 'testIndex', - objectIDs: ['obj0'], - queryID: 'test-query-id', - }, - widgetType: 'ais.testWidget', - }, - ]); - - const parsedPayloadWithAdditionalData = parsePayload( - bindEvent('conversion', hits[0], 'Product Added To Cart', additionalData) - ); - expect(parsedPayloadWithAdditionalData).toEqual([ - { - eventType: 'conversion', - hits: [ - { - __position: 0, - __queryID: 'test-query-id', - objectID: 'obj0', - }, - ], - insightsMethod: 'convertedObjectIDsAfterSearch', - payload: { - eventName: 'Product Added To Cart', - index: 'testIndex', - objectIDs: ['obj0'], - queryID: 'test-query-id', - ...additionalData, - }, - widgetType: 'ais.testWidget', - }, - ]); - }); - - it('splits a payload for > 20 hits', () => { - const { bindEvent, hits } = createTestEnvironment({ nbHits: 21 }); - const parsedPayload = parsePayload( - bindEvent('click', hits, 'Product Clicked') - ); - expect(parsedPayload).toEqual([ - { - eventType: 'click', - hits: Array.from({ length: 20 }, (_, i) => ({ - __position: i, - __queryID: 'test-query-id', - objectID: `obj${i}`, - })), - insightsMethod: 'clickedObjectIDsAfterSearch', - payload: { - eventName: 'Product Clicked', - index: 'testIndex', - objectIDs: Array.from({ length: 20 }, (_, i) => `obj${i}`), - positions: Array.from({ length: 20 }, (_, i) => i), - queryID: 'test-query-id', - }, - widgetType: 'ais.testWidget', - }, - { - eventType: 'click', - hits: [ - { - __position: 20, - __queryID: 'test-query-id', - objectID: 'obj20', - }, - ], - insightsMethod: 'clickedObjectIDsAfterSearch', - payload: { - eventName: 'Product Clicked', - index: 'testIndex', - objectIDs: ['obj20'], - positions: [20], - queryID: 'test-query-id', - }, - widgetType: 'ais.testWidget', - }, - ]); - }); -}); diff --git a/packages/instantsearch-core/src/lib/utils/createSendEventForFacet.ts b/packages/instantsearch-core/src/lib/utils/createSendEventForFacet.ts index bb34caf6d9..c50ee4eec4 100644 --- a/packages/instantsearch-core/src/lib/utils/createSendEventForFacet.ts +++ b/packages/instantsearch-core/src/lib/utils/createSendEventForFacet.ts @@ -45,10 +45,9 @@ export function createSendEventForFacet({ } else if (__DEV__) { throw new Error( `You need to pass between two and four arguments like: - sendEvent('click', facetValue, eventName?, additionalData?); +sendEvent('click', facetValue, eventName?, additionalData?); -If you want to send a custom payload, you can pass one object: sendEvent(customPayload); -` +If you want to send a custom payload, you can pass one object: sendEvent(customPayload);` ); } }; diff --git a/packages/instantsearch-core/src/lib/utils/createSendEventForHits.ts b/packages/instantsearch-core/src/lib/utils/createSendEventForHits.ts index 78e525b966..5d05492ec3 100644 --- a/packages/instantsearch-core/src/lib/utils/createSendEventForHits.ts +++ b/packages/instantsearch-core/src/lib/utils/createSendEventForHits.ts @@ -1,11 +1,8 @@ -import { serializePayload } from './serializer'; - import type { InstantSearch } from '../../instantsearch'; import type { Hit, EscapedHits, InsightsEvent, - BindEventForHits, SendEventForHits, } from '../../types'; @@ -20,13 +17,11 @@ function chunk(arr: TItem[], chunkSize: number = 20): TItem[][] { export function _buildEventPayloadsForHits({ getIndex, widgetType, - methodName, args, instantSearchInstance, }: { widgetType: string; getIndex: () => string; - methodName: 'sendEvent' | 'bindEvent'; args: any[]; instantSearchInstance: InstantSearch; }): InsightsEvent[] { @@ -44,8 +39,7 @@ export function _buildEventPayloadsForHits({ if (__DEV__) { throw new Error( `You need to pass hit or hits as the second argument like: - ${methodName}(eventType, hit); - ` +sendEvent(eventType, hit);` ); } else { return []; @@ -55,10 +49,9 @@ export function _buildEventPayloadsForHits({ if (__DEV__) { throw new Error( `You need to pass eventName as the third argument for 'click' or 'conversion' events like: - ${methodName}('click', hit, 'Product Purchased'); +sendEvent('click', hit, 'Product Purchased'); - To learn more about event naming: https://www.algolia.com/doc/guides/getting-insights-and-analytics/search-analytics/click-through-and-conversions/in-depth/clicks-conversions-best-practices/ - ` +To learn more about event naming: https://www.algolia.com/doc/guides/getting-insights-and-analytics/search-analytics/click-through-and-conversions/in-depth/clicks-conversions-best-practices/` ); } else { return []; @@ -134,8 +127,7 @@ export function _buildEventPayloadsForHits({ }); } else if (__DEV__) { throw new Error(`eventType("${eventType}") is not supported. - If you want to send a custom payload, you can pass one object: ${methodName}(customPayload); - `); +If you want to send a custom payload, you can pass one object: sendEvent(customPayload);`); } else { return []; } @@ -157,7 +149,6 @@ export function createSendEventForHits({ const payloads = _buildEventPayloadsForHits({ widgetType, getIndex, - methodName: 'sendEvent', args, instantSearchInstance, }); @@ -182,31 +173,3 @@ export function createSendEventForHits({ }; return sendEventForHits; } - -/** - * @deprecated - */ -export function createBindEventForHits({ - getIndex, - widgetType, - instantSearchInstance, -}: { - getIndex: () => string; - widgetType: string; - instantSearchInstance: InstantSearch; -}): BindEventForHits { - const bindEventForHits: BindEventForHits = (...args: any[]) => { - const payloads = _buildEventPayloadsForHits({ - widgetType, - getIndex, - methodName: 'bindEvent', - args, - instantSearchInstance, - }); - - return payloads.length - ? `data-insights-event=${serializePayload(payloads)}` - : ''; - }; - return bindEventForHits; -} diff --git a/packages/instantsearch-core/src/lib/utils/index.ts b/packages/instantsearch-core/src/lib/utils/index.ts index d4912e484f..9c2218c33c 100644 --- a/packages/instantsearch-core/src/lib/utils/index.ts +++ b/packages/instantsearch-core/src/lib/utils/index.ts @@ -16,5 +16,4 @@ export * from './hydrateRecommendCache'; export * from './hydrateSearchClient'; export * from './mergeSearchParameters'; export * from './resolveSearchParameters'; -export * from './serializer'; export * from './setIndexHelperState'; diff --git a/packages/instantsearch-core/src/lib/utils/serializer.ts b/packages/instantsearch-core/src/lib/utils/serializer.ts deleted file mode 100644 index 03f6e95c7f..0000000000 --- a/packages/instantsearch-core/src/lib/utils/serializer.ts +++ /dev/null @@ -1,9 +0,0 @@ -// @MAJOR delete after bindEvent is removed -export function serializePayload(payload: TPayload): string { - return btoa(encodeURIComponent(JSON.stringify(payload))); -} - -// @MAJOR delete after bindEvent is removed -export function deserializePayload(serialized: string): TPayload { - return JSON.parse(decodeURIComponent(atob(serialized))); -} diff --git a/packages/instantsearch-core/src/types/insights.ts b/packages/instantsearch-core/src/types/insights.ts index 2ac1329858..07eae60b76 100644 --- a/packages/instantsearch-core/src/types/insights.ts +++ b/packages/instantsearch-core/src/types/insights.ts @@ -98,15 +98,3 @@ type BuiltInSendEventForFacet = ( type CustomSendEventForFacet = (customPayload: any) => void; export type SendEventForFacet = BuiltInSendEventForFacet & CustomSendEventForFacet; - -/** @deprecated */ -type BuiltInBindEventForHits = ( - eventType: string, - hits: Hit | Hit[], - eventName?: string, - additionalData?: Record -) => string; -/** @deprecated */ -export type CustomBindEventForHits = (customPayload: any) => string; -/** @deprecated */ -export type BindEventForHits = BuiltInBindEventForHits & CustomBindEventForHits; diff --git a/packages/instantsearch.js/src/components/InfiniteHits/InfiniteHits.tsx b/packages/instantsearch.js/src/components/InfiniteHits/InfiniteHits.tsx index 391294a009..ab81382d88 100644 --- a/packages/instantsearch.js/src/components/InfiniteHits/InfiniteHits.tsx +++ b/packages/instantsearch.js/src/components/InfiniteHits/InfiniteHits.tsx @@ -10,7 +10,6 @@ import type { Hit, InsightsClient, SendEventForHits, - BindEventForHits, } from '../../types'; import type { InfiniteHitsCSSClasses, @@ -37,7 +36,6 @@ export type InfiniteHitsProps = { isLastPage: boolean; insights?: InsightsClient; sendEvent: SendEventForHits; - bindEvent: BindEventForHits; banner?: Banner; }; diff --git a/packages/instantsearch.js/src/components/InfiniteHits/__tests__/InfiniteHits-test.tsx b/packages/instantsearch.js/src/components/InfiniteHits/__tests__/InfiniteHits-test.tsx index ab4fdbf878..0154811b73 100644 --- a/packages/instantsearch.js/src/components/InfiniteHits/__tests__/InfiniteHits-test.tsx +++ b/packages/instantsearch.js/src/components/InfiniteHits/__tests__/InfiniteHits-test.tsx @@ -34,7 +34,6 @@ describe('InfiniteHits', () => { }; const sendEvent = () => {}; - const bindEvent = () => ''; describe('markup', () => { it('should render on first page', () => { @@ -69,7 +68,6 @@ describe('InfiniteHits', () => { }, cssClasses, sendEvent, - bindEvent, }; const { container } = render(); @@ -109,7 +107,6 @@ describe('InfiniteHits', () => { }, cssClasses, sendEvent, - bindEvent, }; const { container } = render(); @@ -138,7 +135,6 @@ describe('InfiniteHits', () => { }, cssClasses, sendEvent, - bindEvent, }; const { container } = render(); @@ -167,7 +163,6 @@ describe('InfiniteHits', () => { }, cssClasses, sendEvent, - bindEvent, }; const { container } = render(); @@ -207,7 +202,6 @@ describe('InfiniteHits', () => { }, cssClasses, sendEvent, - bindEvent, }; const { container } = render(); @@ -252,7 +246,6 @@ describe('InfiniteHits', () => { }, cssClasses, sendEvent, - bindEvent, }; const { container } = render(); diff --git a/packages/instantsearch.js/src/components/InfiniteHits/__tests__/InfiniteHits.test.tsx b/packages/instantsearch.js/src/components/InfiniteHits/__tests__/InfiniteHits.test.tsx index c1eee9299f..1b5a3e6577 100644 --- a/packages/instantsearch.js/src/components/InfiniteHits/__tests__/InfiniteHits.test.tsx +++ b/packages/instantsearch.js/src/components/InfiniteHits/__tests__/InfiniteHits.test.tsx @@ -48,7 +48,6 @@ describe('InfiniteHits', () => { ]), hits: hits as THit[], sendEvent: jest.fn(), - bindEvent: jest.fn(), showPrevious: jest.fn(), showMore: jest.fn(), hasShowPrevious: true, diff --git a/packages/instantsearch.js/src/widgets/infinite-hits/infinite-hits.tsx b/packages/instantsearch.js/src/widgets/infinite-hits/infinite-hits.tsx index e83a0267af..372ccdf1db 100644 --- a/packages/instantsearch.js/src/widgets/infinite-hits/infinite-hits.tsx +++ b/packages/instantsearch.js/src/widgets/infinite-hits/infinite-hits.tsx @@ -188,7 +188,6 @@ const renderer = isFirstPage, isLastPage, insights, - bindEvent, sendEvent, banner, }, @@ -216,7 +215,6 @@ const renderer = isLastPage={isLastPage} insights={insights as InsightsClient} sendEvent={sendEvent} - bindEvent={bindEvent} banner={banner} />, containerNode diff --git a/packages/react-instantsearch-core/src/connectors/__tests__/useHits.test.tsx b/packages/react-instantsearch-core/src/connectors/__tests__/useHits.test.tsx index cab803ea45..0d200d9855 100644 --- a/packages/react-instantsearch-core/src/connectors/__tests__/useHits.test.tsx +++ b/packages/react-instantsearch-core/src/connectors/__tests__/useHits.test.tsx @@ -13,7 +13,6 @@ describe('useHits', () => { // Initial render state from manual `getWidgetRenderState` expect(result.current).toEqual({ banner: undefined, - bindEvent: expect.any(Function), hits: [], items: [], results: expect.objectContaining({ nbHits: 0 }), @@ -25,7 +24,6 @@ describe('useHits', () => { // InstantSearch.js state from the `render` lifecycle step expect(result.current).toEqual({ banner: undefined, - bindEvent: expect.any(Function), hits: [], items: [], results: expect.objectContaining({ nbHits: 0 }), diff --git a/packages/react-instantsearch-core/src/connectors/__tests__/useInfiniteHits.test.tsx b/packages/react-instantsearch-core/src/connectors/__tests__/useInfiniteHits.test.tsx index ebc8275501..4d2ca7e9d9 100644 --- a/packages/react-instantsearch-core/src/connectors/__tests__/useInfiniteHits.test.tsx +++ b/packages/react-instantsearch-core/src/connectors/__tests__/useInfiniteHits.test.tsx @@ -12,7 +12,6 @@ describe('useInfiniteHits', () => { // Initial render state from manual `getWidgetRenderState` expect(result.current).toEqual({ - bindEvent: undefined, hits: [], items: [], results: expect.objectContaining({ nbHits: 0 }), @@ -28,7 +27,6 @@ describe('useInfiniteHits', () => { // InstantSearch.js state from the `render` lifecycle step expect(result.current).toEqual({ - bindEvent: expect.any(Function), hits: [], items: [], results: expect.objectContaining({ nbHits: 0 }),