diff --git a/src/searchPage/searchPageClient.spec.ts b/src/searchPage/searchPageClient.spec.ts index 2be95462..28a519fb 100644 --- a/src/searchPage/searchPageClient.spec.ts +++ b/src/searchPage/searchPageClient.spec.ts @@ -59,6 +59,7 @@ describe('SearchPageClient', () => { const provider: SearchPageClientProvider = { getBaseMetadata: () => ({foo: 'bar'}), + getGeneratedAnswerMetadata: () => ({genQaMetadata: 'bar'}), getSearchEventRequestPayload: () => ({ queryText: 'queryText', responseTime: 123, @@ -118,7 +119,7 @@ describe('SearchPageClient', () => { const expectMatchPayload = (actionCause: SearchPageEvents, meta = {}) => { const body: string = lastCallBody(fetchMock); - const customData = {foo: 'bar', ...customDataFromMiddleware, ...meta}; + const customData = {foo: 'bar', genQaMetadata: 'bar', ...customDataFromMiddleware, ...meta}; expect(JSON.parse(body)).toEqual({ queryText: 'queryText', responseTime: 123, @@ -144,6 +145,14 @@ describe('SearchPageClient', () => { }); }; + const expectSearchEventToMatchDescription = ( + description: EventDescription, + actionCause: SearchPageEvents, + meta = {} + ) => { + expectMatchDescription(description, actionCause, {...meta, genQaMetadata: 'bar'}); + }; + const expectMatchDocumentPayload = (actionCause: SearchPageEvents, doc: PartialDocumentInformation, meta = {}) => { const body: string = lastCallBody(fetchMock); const customData = {foo: 'bar', ...customDataFromMiddleware, ...meta}; @@ -211,7 +220,7 @@ describe('SearchPageClient', () => { const built = await client.makeInterfaceLoad(); await built.log({searchUID: provider.getSearchUID()}); expectMatchPayload(SearchPageEvents.interfaceLoad); - expectMatchDescription(built.description, SearchPageEvents.interfaceLoad); + expectSearchEventToMatchDescription(built.description, SearchPageEvents.interfaceLoad); }); it('should send proper payload for #interfaceChange', async () => { @@ -225,7 +234,9 @@ describe('SearchPageClient', () => { const built = await client.makeInterfaceChange({interfaceChangeTo: 'bob'}); await built.log({searchUID: provider.getSearchUID()}); expectMatchPayload(SearchPageEvents.interfaceChange, {interfaceChangeTo: 'bob'}); - expectMatchDescription(built.description, SearchPageEvents.interfaceChange, {interfaceChangeTo: 'bob'}); + expectSearchEventToMatchDescription(built.description, SearchPageEvents.interfaceChange, { + interfaceChangeTo: 'bob', + }); }); it('should send proper payload for #didyoumeanAutomatic', async () => { @@ -237,7 +248,7 @@ describe('SearchPageClient', () => { const built = await client.makeDidYouMeanAutomatic(); await built.log({searchUID: provider.getSearchUID()}); expectMatchPayload(SearchPageEvents.didyoumeanAutomatic); - expectMatchDescription(built.description, SearchPageEvents.didyoumeanAutomatic); + expectSearchEventToMatchDescription(built.description, SearchPageEvents.didyoumeanAutomatic); }); it('should send proper payload for #didyoumeanClick', async () => { @@ -249,7 +260,7 @@ describe('SearchPageClient', () => { const built = await client.makeDidYouMeanClick(); await built.log({searchUID: provider.getSearchUID()}); expectMatchPayload(SearchPageEvents.didyoumeanClick); - expectMatchDescription(built.description, SearchPageEvents.didyoumeanClick); + expectSearchEventToMatchDescription(built.description, SearchPageEvents.didyoumeanClick); }); it('should send proper payload for #resultsSort', async () => { @@ -261,7 +272,9 @@ describe('SearchPageClient', () => { const built = await client.makeResultsSort({resultsSortBy: 'date ascending'}); await built.log({searchUID: provider.getSearchUID()}); expectMatchPayload(SearchPageEvents.resultsSort, {resultsSortBy: 'date ascending'}); - expectMatchDescription(built.description, SearchPageEvents.resultsSort, {resultsSortBy: 'date ascending'}); + expectSearchEventToMatchDescription(built.description, SearchPageEvents.resultsSort, { + resultsSortBy: 'date ascending', + }); }); it('should send proper payload for #searchboxSubmit', async () => { @@ -273,7 +286,7 @@ describe('SearchPageClient', () => { const built = await client.makeSearchboxSubmit(); await built.log({searchUID: provider.getSearchUID()}); expectMatchPayload(SearchPageEvents.searchboxSubmit); - expectMatchDescription(built.description, SearchPageEvents.searchboxSubmit); + expectSearchEventToMatchDescription(built.description, SearchPageEvents.searchboxSubmit); }); it('should send proper payload for #searchboxClear', async () => { @@ -285,7 +298,7 @@ describe('SearchPageClient', () => { const built = await client.makeSearchboxClear(); await built.log({searchUID: provider.getSearchUID()}); expectMatchPayload(SearchPageEvents.searchboxClear); - expectMatchDescription(built.description, SearchPageEvents.searchboxClear); + expectSearchEventToMatchDescription(built.description, SearchPageEvents.searchboxClear); }); it('should send proper payload for #searchboxAsYouType', async () => { @@ -297,7 +310,7 @@ describe('SearchPageClient', () => { const built = await client.makeSearchboxAsYouType(); await built.log({searchUID: provider.getSearchUID()}); expectMatchPayload(SearchPageEvents.searchboxAsYouType); - expectMatchDescription(built.description, SearchPageEvents.searchboxAsYouType); + expectSearchEventToMatchDescription(built.description, SearchPageEvents.searchboxAsYouType); }); it('should send proper payload for #documentQuickview', async () => { @@ -371,7 +384,7 @@ describe('SearchPageClient', () => { const built = await client.makeOmniboxAnalytics(meta); await built.log({searchUID: provider.getSearchUID()}); expectMatchPayload(SearchPageEvents.omniboxAnalytics, meta); - expectMatchDescription(built.description, SearchPageEvents.omniboxAnalytics, meta); + expectSearchEventToMatchDescription(built.description, SearchPageEvents.omniboxAnalytics, meta); }); it('should send proper payload for #logOmniboxFromLink', async () => { @@ -397,7 +410,7 @@ describe('SearchPageClient', () => { const built = await client.makeOmniboxFromLink(meta); await built.log({searchUID: provider.getSearchUID()}); expectMatchPayload(SearchPageEvents.omniboxFromLink, meta); - expectMatchDescription(built.description, SearchPageEvents.omniboxFromLink, meta); + expectSearchEventToMatchDescription(built.description, SearchPageEvents.omniboxFromLink, meta); }); it('should send proper payload for #logSearchFromLink', async () => { @@ -409,7 +422,7 @@ describe('SearchPageClient', () => { const built = await client.makeSearchFromLink(); await built.log({searchUID: provider.getSearchUID()}); expectMatchPayload(SearchPageEvents.searchFromLink); - expectMatchDescription(built.description, SearchPageEvents.searchFromLink); + expectSearchEventToMatchDescription(built.description, SearchPageEvents.searchFromLink); }); it('should send proper payload for #logTriggerNotify', async () => { @@ -487,7 +500,7 @@ describe('SearchPageClient', () => { const built = await client.makeUndoTriggerQuery(meta); await built.log({searchUID: provider.getSearchUID()}); expectMatchPayload(SearchPageEvents.undoTriggerQuery, meta); - expectMatchDescription(built.description, SearchPageEvents.undoTriggerQuery, meta); + expectSearchEventToMatchDescription(built.description, SearchPageEvents.undoTriggerQuery, meta); }); it('should send proper payload for #logTriggerRedirect', async () => { @@ -594,7 +607,7 @@ describe('SearchPageClient', () => { const built = await client.makeStaticFilterClearAll({staticFilterId}); await built.log({searchUID: provider.getSearchUID()}); expectMatchPayload(SearchPageEvents.staticFilterClearAll, {staticFilterId}); - expectMatchDescription(built.description, SearchPageEvents.staticFilterClearAll, {staticFilterId}); + expectSearchEventToMatchDescription(built.description, SearchPageEvents.staticFilterClearAll, {staticFilterId}); }); it('should send the proper payload for #logStaticFilterSelect', async () => { @@ -622,7 +635,7 @@ describe('SearchPageClient', () => { await built.log({searchUID: provider.getSearchUID()}); expectMatchPayload(SearchPageEvents.staticFilterSelect, meta); - expectMatchDescription(built.description, SearchPageEvents.staticFilterSelect, meta); + expectSearchEventToMatchDescription(built.description, SearchPageEvents.staticFilterSelect, meta); }); it('should send the proper payload for #logStaticFilterDeselect', async () => { @@ -649,7 +662,7 @@ describe('SearchPageClient', () => { const built = await client.makeStaticFilterDeselect(meta); await built.log({searchUID: provider.getSearchUID()}); expectMatchPayload(SearchPageEvents.staticFilterDeselect, meta); - expectMatchDescription(built.description, SearchPageEvents.staticFilterDeselect, meta); + expectSearchEventToMatchDescription(built.description, SearchPageEvents.staticFilterDeselect, meta); }); it('should send proper payload for #logFacetSearch', async () => { @@ -671,7 +684,7 @@ describe('SearchPageClient', () => { const built = await client.makeFacetSearch(meta); await built.log({searchUID: provider.getSearchUID()}); expectMatchPayload(SearchPageEvents.facetSearch, meta); - expectMatchDescription(built.description, SearchPageEvents.facetSearch, meta); + expectSearchEventToMatchDescription(built.description, SearchPageEvents.facetSearch, meta); }); it('should send proper payload for #logFacetSelect', async () => { @@ -696,7 +709,7 @@ describe('SearchPageClient', () => { const built = await client.makeFacetSelect(meta); await built.log({searchUID: provider.getSearchUID()}); expectMatchPayload(SearchPageEvents.facetSelect, meta); - expectMatchDescription(built.description, SearchPageEvents.facetSelect, meta); + expectSearchEventToMatchDescription(built.description, SearchPageEvents.facetSelect, meta); }); it('should send proper payload for #logFacetDeselect', async () => { @@ -722,7 +735,7 @@ describe('SearchPageClient', () => { const built = await client.makeFacetDeselect(meta); await built.log({searchUID: provider.getSearchUID()}); expectMatchPayload(SearchPageEvents.facetDeselect, meta); - expectMatchDescription(built.description, SearchPageEvents.facetDeselect, meta); + expectSearchEventToMatchDescription(built.description, SearchPageEvents.facetDeselect, meta); }); it('should send proper payload for #logFacetExclude', async () => { @@ -746,7 +759,7 @@ describe('SearchPageClient', () => { const built = await client.makeFacetExclude(meta); await built.log({searchUID: provider.getSearchUID()}); expectMatchPayload(SearchPageEvents.facetExclude, meta); - expectMatchDescription(built.description, SearchPageEvents.facetExclude, meta); + expectSearchEventToMatchDescription(built.description, SearchPageEvents.facetExclude, meta); }); it('should send proper payload for #logFacetUnexclude', async () => { @@ -770,7 +783,7 @@ describe('SearchPageClient', () => { const built = await client.makeFacetUnexclude(meta); await built.log({searchUID: provider.getSearchUID()}); expectMatchPayload(SearchPageEvents.facetUnexclude, meta); - expectMatchDescription(built.description, SearchPageEvents.facetUnexclude, meta); + expectSearchEventToMatchDescription(built.description, SearchPageEvents.facetUnexclude, meta); }); it('should send proper payload for #logFacetSelectAll', async () => { @@ -792,7 +805,7 @@ describe('SearchPageClient', () => { const built = await client.makeFacetSelectAll(meta); await built.log({searchUID: provider.getSearchUID()}); expectMatchPayload(SearchPageEvents.facetSelectAll, meta); - expectMatchDescription(built.description, SearchPageEvents.facetSelectAll, meta); + expectSearchEventToMatchDescription(built.description, SearchPageEvents.facetSelectAll, meta); }); it('should send proper payload for #logFacetUpdateSort', async () => { @@ -816,7 +829,7 @@ describe('SearchPageClient', () => { const built = await client.makeFacetUpdateSort(meta); await built.log({searchUID: provider.getSearchUID()}); expectMatchPayload(SearchPageEvents.facetUpdateSort, meta); - expectMatchDescription(built.description, SearchPageEvents.facetUpdateSort, meta); + expectSearchEventToMatchDescription(built.description, SearchPageEvents.facetUpdateSort, meta); }); it('should send proper payload for #logFacetShowMore', async () => { @@ -937,7 +950,7 @@ describe('SearchPageClient', () => { const built = await client.makeRecommendationInterfaceLoad(); await built.log({searchUID: provider.getSearchUID()}); expectMatchPayload(SearchPageEvents.recommendationInterfaceLoad); - expectMatchDescription(built.description, SearchPageEvents.recommendationInterfaceLoad); + expectSearchEventToMatchDescription(built.description, SearchPageEvents.recommendationInterfaceLoad); }); it('should send proper payload for #logRecommendation', async () => { @@ -1309,7 +1322,7 @@ describe('SearchPageClient', () => { await built.log({searchUID: provider.getSearchUID()}); expectMatchPayload(SearchPageEvents.recentQueryClick); - expectMatchDescription(built.description, SearchPageEvents.recentQueryClick); + expectSearchEventToMatchDescription(built.description, SearchPageEvents.recentQueryClick); }); it('should send proper payload for #logClearRecentQueries', async () => { @@ -1358,7 +1371,7 @@ describe('SearchPageClient', () => { await built.log({searchUID: provider.getSearchUID()}); expectMatchPayload(SearchPageEvents.noResultsBack); - expectMatchDescription(built.description, SearchPageEvents.noResultsBack); + expectSearchEventToMatchDescription(built.description, SearchPageEvents.noResultsBack); }); it('should send proper payload for #logClearRecentResults', async () => { @@ -1565,7 +1578,7 @@ describe('SearchPageClient', () => { it('should send proper payload for #logRephraseGeneratedAnswer', async () => { const meta = { generativeQuestionAnsweringId: fakeStreamId, - rephraseFormat: 'stepByStep', + rephraseFormat: 'step', }; await client.logRephraseGeneratedAnswer(meta); expectMatchPayload(SearchPageEvents.rephraseGeneratedAnswer, meta); @@ -1574,11 +1587,11 @@ describe('SearchPageClient', () => { it('should send proper payload for #makeRephraseGeneratedAnswer', async () => { const meta = { generativeQuestionAnsweringId: fakeStreamId, - rephraseFormat: 'stepByStep', + rephraseFormat: 'step', }; const built = await client.makeRephraseGeneratedAnswer(meta); await built.log({searchUID: provider.getSearchUID()}); expectMatchPayload(SearchPageEvents.rephraseGeneratedAnswer, meta); - expectMatchDescription(built.description, SearchPageEvents.rephraseGeneratedAnswer, meta); + expectSearchEventToMatchDescription(built.description, SearchPageEvents.rephraseGeneratedAnswer, meta); }); }); diff --git a/src/searchPage/searchPageClient.ts b/src/searchPage/searchPageClient.ts index 63112665..1176a27c 100644 --- a/src/searchPage/searchPageClient.ts +++ b/src/searchPage/searchPageClient.ts @@ -61,6 +61,7 @@ export interface SearchPageClientProvider { getFacetState?: () => FacetStateMetadata[]; getSplitTestRunName?: () => string | undefined; getSplitTestRunVersion?: () => string | undefined; + getGeneratedAnswerMetadata?: () => Record; } export interface SearchPageClientOptions extends ClientOptions { @@ -844,7 +845,7 @@ export class CoveoSearchPageClient { metadata?: Record ): Promise { return { - ...(await this.getBaseEventRequest(metadata)), + ...(await this.getBaseEventRequest({...metadata, ...this.provider.getGeneratedAnswerMetadata?.()})), ...this.provider.getSearchEventRequestPayload(), queryPipeline: this.provider.getPipeline(), actionCause: event, diff --git a/src/searchPage/searchPageEvents.ts b/src/searchPage/searchPageEvents.ts index 05914695..0586a7dc 100644 --- a/src/searchPage/searchPageEvents.ts +++ b/src/searchPage/searchPageEvents.ts @@ -539,7 +539,7 @@ export interface GeneratedAnswerCitationMeta { export type GeneratedAnswerFeedbackReason = 'irrelevant' | 'notAccurate' | 'outOfDate' | 'harmful' | 'other'; -export type GeneratedAnswerRephraseFormat = 'stepByStep' | 'bulletPoints' | 'summarize'; +export type GeneratedAnswerRephraseFormat = 'step' | 'bullet' | 'concise' | 'default'; export interface GeneratedAnswerSourceHoverMeta extends GeneratedAnswerCitationMeta { citationHoverTimeMs: number;