Skip to content

Commit

Permalink
generated answer metadata added to the ua search events
Browse files Browse the repository at this point in the history
  • Loading branch information
mmitiche committed Oct 10, 2023
1 parent d8d024f commit 81f1833
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 31 deletions.
71 changes: 42 additions & 29 deletions src/searchPage/searchPageClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ describe('SearchPageClient', () => {

const provider: SearchPageClientProvider = {
getBaseMetadata: () => ({foo: 'bar'}),
getGeneratedAnswerMetadata: () => ({genQaMetadata: 'bar'}),
getSearchEventRequestPayload: () => ({
queryText: 'queryText',
responseTime: 123,
Expand Down Expand Up @@ -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,
Expand All @@ -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};
Expand Down Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -1565,7 +1578,7 @@ describe('SearchPageClient', () => {
it('should send proper payload for #logRephraseGeneratedAnswer', async () => {
const meta = {
generativeQuestionAnsweringId: fakeStreamId,
rephraseFormat: <GeneratedAnswerRephraseFormat>'stepByStep',
rephraseFormat: <GeneratedAnswerRephraseFormat>'step',
};
await client.logRephraseGeneratedAnswer(meta);
expectMatchPayload(SearchPageEvents.rephraseGeneratedAnswer, meta);
Expand All @@ -1574,11 +1587,11 @@ describe('SearchPageClient', () => {
it('should send proper payload for #makeRephraseGeneratedAnswer', async () => {
const meta = {
generativeQuestionAnsweringId: fakeStreamId,
rephraseFormat: <GeneratedAnswerRephraseFormat>'stepByStep',
rephraseFormat: <GeneratedAnswerRephraseFormat>'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);
});
});
3 changes: 2 additions & 1 deletion src/searchPage/searchPageClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export interface SearchPageClientProvider {
getFacetState?: () => FacetStateMetadata[];
getSplitTestRunName?: () => string | undefined;
getSplitTestRunVersion?: () => string | undefined;
getGeneratedAnswerMetadata?: () => Record<string, any>;
}

export interface SearchPageClientOptions extends ClientOptions {
Expand Down Expand Up @@ -844,7 +845,7 @@ export class CoveoSearchPageClient {
metadata?: Record<string, any>
): Promise<PreparedSearchEventRequest> {
return {
...(await this.getBaseEventRequest(metadata)),
...(await this.getBaseEventRequest({...metadata, ...this.provider.getGeneratedAnswerMetadata?.()})),
...this.provider.getSearchEventRequestPayload(),
queryPipeline: this.provider.getPipeline(),
actionCause: event,
Expand Down
2 changes: 1 addition & 1 deletion src/searchPage/searchPageEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 81f1833

Please sign in to comment.