From c9cd604d93334be6e31edbfd301a4fbd086a777d Mon Sep 17 00:00:00 2001 From: mmitiche Date: Thu, 18 Apr 2024 07:48:11 +0100 Subject: [PATCH 1/2] new method to expand and collapse generated answer added to search and insight client --- src/insight/insightClient.spec.ts | 44 +++++++++++++++++++++++++ src/insight/insightClient.ts | 18 ++++++++++ src/searchPage/searchPageClient.spec.ts | 28 ++++++++++++++++ src/searchPage/searchPageClient.ts | 16 +++++++++ src/searchPage/searchPageEvents.ts | 10 ++++++ 5 files changed, 116 insertions(+) diff --git a/src/insight/insightClient.spec.ts b/src/insight/insightClient.spec.ts index 6b5d67d..8452c00 100644 --- a/src/insight/insightClient.spec.ts +++ b/src/insight/insightClient.spec.ts @@ -585,6 +585,24 @@ describe('InsightClient', () => { expectMatchCustomEventPayload(SearchPageEvents.generatedAnswerShowAnswers, exampleGeneratedAnswerMetadata); }); + it('should send proper payload for #expandGeneratedAnswer', async () => { + const exampleGeneratedAnswerMetadata = { + generativeQuestionAnsweringId: '123', + }; + + await client.logExpandGeneratedAnswer(exampleGeneratedAnswerMetadata); + expectMatchCustomEventPayload(SearchPageEvents.expandGeneratedAnswer, exampleGeneratedAnswerMetadata); + }); + + it('should send proper payload for #collapseGeneratedAnswer', async () => { + const exampleGeneratedAnswerMetadata = { + generativeQuestionAnsweringId: '123', + }; + + await client.logCollapseGeneratedAnswer(exampleGeneratedAnswerMetadata); + expectMatchCustomEventPayload(SearchPageEvents.collapseGeneratedAnswer, exampleGeneratedAnswerMetadata); + }); + it('should send proper payload for #generatedAnswerFeedbackSubmit', async () => { const exampleGeneratedAnswerMetadata = { generativeQuestionAnsweringId: '123', @@ -1340,6 +1358,32 @@ describe('InsightClient', () => { expectMatchCustomEventPayload(SearchPageEvents.generatedAnswerShowAnswers, expectedMetadata); }); + it('should send proper payload for #expandGeneratedAnswer', async () => { + const exampleGeneratedAnswerMetadata = { + generativeQuestionAnsweringId: '123', + }; + const expectedMetadata = { + ...exampleGeneratedAnswerMetadata, + ...expectedBaseCaseMetadata, + }; + + await client.logExpandGeneratedAnswer(exampleGeneratedAnswerMetadata, baseCaseMetadata); + expectMatchCustomEventPayload(SearchPageEvents.expandGeneratedAnswer, expectedMetadata); + }); + + it('should send proper payload for #collapseGeneratedAnswer', async () => { + const exampleGeneratedAnswerMetadata = { + generativeQuestionAnsweringId: '123', + }; + const expectedMetadata = { + ...exampleGeneratedAnswerMetadata, + ...expectedBaseCaseMetadata, + }; + + await client.logCollapseGeneratedAnswer(exampleGeneratedAnswerMetadata, baseCaseMetadata); + expectMatchCustomEventPayload(SearchPageEvents.collapseGeneratedAnswer, expectedMetadata); + }); + it('should send proper payload for #generatedAnswerFeedbackSubmit', async () => { const exampleGeneratedAnswerMetadata = { generativeQuestionAnsweringId: '123', diff --git a/src/insight/insightClient.ts b/src/insight/insightClient.ts index c36942a..e767b11 100644 --- a/src/insight/insightClient.ts +++ b/src/insight/insightClient.ts @@ -560,6 +560,24 @@ export class CoveoInsightClient { ); } + public logExpandGeneratedAnswer(generatedAnswerMetadata: GeneratedAnswerBaseMeta, metadata?: CaseMetadata) { + return this.logCustomEvent( + SearchPageEvents.expandGeneratedAnswer, + metadata + ? {...generateMetadataToSend(metadata, false), ...generatedAnswerMetadata} + : generatedAnswerMetadata + ); + } + + public logCollapseGeneratedAnswer(generatedAnswerMetadata: GeneratedAnswerBaseMeta, metadata?: CaseMetadata) { + return this.logCustomEvent( + SearchPageEvents.collapseGeneratedAnswer, + metadata + ? {...generateMetadataToSend(metadata, false), ...generatedAnswerMetadata} + : generatedAnswerMetadata + ); + } + public logGeneratedAnswerFeedbackSubmit( generatedAnswerFeedbackMetadata: GeneratedAnswerFeedbackMeta, metadata?: CaseMetadata diff --git a/src/searchPage/searchPageClient.spec.ts b/src/searchPage/searchPageClient.spec.ts index cb73144..92bbbb3 100644 --- a/src/searchPage/searchPageClient.spec.ts +++ b/src/searchPage/searchPageClient.spec.ts @@ -1573,6 +1573,34 @@ describe('SearchPageClient', () => { expectMatchDescription(built.description, SearchPageEvents.generatedAnswerShowAnswers, meta); }); + it('should send proper payload for #logExpandGeneratedAnswer', async () => { + const meta = {generativeQuestionAnsweringId: fakeStreamId}; + await client.logExpandGeneratedAnswer(meta); + expectMatchCustomEventPayload(SearchPageEvents.expandGeneratedAnswer, meta); + }); + + it('should send proper payload for #makeExpandGeneratedAnswer', async () => { + const meta = {generativeQuestionAnsweringId: fakeStreamId}; + const built = await client.makeExpandGeneratedAnswer(meta); + await built.log({searchUID: provider.getSearchUID()}); + expectMatchCustomEventPayload(SearchPageEvents.expandGeneratedAnswer, meta); + expectMatchDescription(built.description, SearchPageEvents.expandGeneratedAnswer, meta); + }); + + it('should send proper payload for #logCollapseGeneratedAnswer', async () => { + const meta = {generativeQuestionAnsweringId: fakeStreamId}; + await client.logCollapseGeneratedAnswer(meta); + expectMatchCustomEventPayload(SearchPageEvents.collapseGeneratedAnswer, meta); + }); + + it('should send proper payload for #makeCollapseGeneratedAnswer', async () => { + const meta = {generativeQuestionAnsweringId: fakeStreamId}; + const built = await client.makeCollapseGeneratedAnswer(meta); + await built.log({searchUID: provider.getSearchUID()}); + expectMatchCustomEventPayload(SearchPageEvents.collapseGeneratedAnswer, meta); + expectMatchDescription(built.description, SearchPageEvents.collapseGeneratedAnswer, meta); + }); + it('should send proper payload for #logGeneratedAnswerFeedbackSubmit', async () => { const meta = { generativeQuestionAnsweringId: fakeStreamId, diff --git a/src/searchPage/searchPageClient.ts b/src/searchPage/searchPageClient.ts index 44f3243..08fae0d 100644 --- a/src/searchPage/searchPageClient.ts +++ b/src/searchPage/searchPageClient.ts @@ -951,6 +951,22 @@ export class CoveoSearchPageClient { }); } + public makeExpandGeneratedAnswer(metadata: GeneratedAnswerBaseMeta) { + return this.makeCustomEvent(SearchPageEvents.expandGeneratedAnswer, metadata); + } + + public async logExpandGeneratedAnswer(metadata: GeneratedAnswerBaseMeta) { + return (await this.makeExpandGeneratedAnswer(metadata)).log({searchUID: this.provider.getSearchUID()}); + } + + public makeCollapseGeneratedAnswer(metadata: GeneratedAnswerBaseMeta) { + return this.makeCustomEvent(SearchPageEvents.collapseGeneratedAnswer, metadata); + } + + public async logCollapseGeneratedAnswer(metadata: GeneratedAnswerBaseMeta) { + return (await this.makeCollapseGeneratedAnswer(metadata)).log({searchUID: this.provider.getSearchUID()}); + } + public makeGeneratedAnswerFeedbackSubmit(meta: GeneratedAnswerFeedbackMeta) { return this.makeCustomEvent(SearchPageEvents.generatedAnswerFeedbackSubmit, meta); } diff --git a/src/searchPage/searchPageEvents.ts b/src/searchPage/searchPageEvents.ts index a8693f6..128be85 100644 --- a/src/searchPage/searchPageEvents.ts +++ b/src/searchPage/searchPageEvents.ts @@ -330,6 +330,14 @@ export enum SearchPageEvents { * Identifies the custom event that gets logged when a user activates the genQA feature. */ generatedAnswerShowAnswers = 'generatedAnswerShowAnswers', + /** + * Identifies the custom event that gets logged when a user expand a generated answer. + */ + expandGeneratedAnswer = 'expandGeneratedAnswer', + /** + * Identifies the custom event that gets logged when a user collapse a generated answer. + */ + collapseGeneratedAnswer = 'collapseGeneratedAnswer', /** * Identifies the custom event that gets logged when a user submits a feedback of a generated answer. */ @@ -382,6 +390,8 @@ export const CustomEventsTypes: Partial Date: Fri, 19 Apr 2024 12:44:45 +0100 Subject: [PATCH 2/2] method name updated --- src/insight/insightClient.spec.ts | 24 ++++++++++----------- src/insight/insightClient.ts | 8 +++---- src/searchPage/searchPageClient.spec.ts | 28 ++++++++++++------------- src/searchPage/searchPageClient.ts | 16 +++++++------- src/searchPage/searchPageEvents.ts | 8 +++---- 5 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/insight/insightClient.spec.ts b/src/insight/insightClient.spec.ts index 8452c00..b699ba5 100644 --- a/src/insight/insightClient.spec.ts +++ b/src/insight/insightClient.spec.ts @@ -585,22 +585,22 @@ describe('InsightClient', () => { expectMatchCustomEventPayload(SearchPageEvents.generatedAnswerShowAnswers, exampleGeneratedAnswerMetadata); }); - it('should send proper payload for #expandGeneratedAnswer', async () => { + it('should send proper payload for #generatedAnswerExpand', async () => { const exampleGeneratedAnswerMetadata = { generativeQuestionAnsweringId: '123', }; - await client.logExpandGeneratedAnswer(exampleGeneratedAnswerMetadata); - expectMatchCustomEventPayload(SearchPageEvents.expandGeneratedAnswer, exampleGeneratedAnswerMetadata); + await client.logGeneratedAnswerExpand(exampleGeneratedAnswerMetadata); + expectMatchCustomEventPayload(SearchPageEvents.generatedAnswerExpand, exampleGeneratedAnswerMetadata); }); - it('should send proper payload for #collapseGeneratedAnswer', async () => { + it('should send proper payload for #generatedAnswerCollapse', async () => { const exampleGeneratedAnswerMetadata = { generativeQuestionAnsweringId: '123', }; - await client.logCollapseGeneratedAnswer(exampleGeneratedAnswerMetadata); - expectMatchCustomEventPayload(SearchPageEvents.collapseGeneratedAnswer, exampleGeneratedAnswerMetadata); + await client.logGeneratedAnswerCollapse(exampleGeneratedAnswerMetadata); + expectMatchCustomEventPayload(SearchPageEvents.generatedAnswerCollapse, exampleGeneratedAnswerMetadata); }); it('should send proper payload for #generatedAnswerFeedbackSubmit', async () => { @@ -1358,7 +1358,7 @@ describe('InsightClient', () => { expectMatchCustomEventPayload(SearchPageEvents.generatedAnswerShowAnswers, expectedMetadata); }); - it('should send proper payload for #expandGeneratedAnswer', async () => { + it('should send proper payload for #generatedAnswerExpand', async () => { const exampleGeneratedAnswerMetadata = { generativeQuestionAnsweringId: '123', }; @@ -1367,11 +1367,11 @@ describe('InsightClient', () => { ...expectedBaseCaseMetadata, }; - await client.logExpandGeneratedAnswer(exampleGeneratedAnswerMetadata, baseCaseMetadata); - expectMatchCustomEventPayload(SearchPageEvents.expandGeneratedAnswer, expectedMetadata); + await client.logGeneratedAnswerExpand(exampleGeneratedAnswerMetadata, baseCaseMetadata); + expectMatchCustomEventPayload(SearchPageEvents.generatedAnswerExpand, expectedMetadata); }); - it('should send proper payload for #collapseGeneratedAnswer', async () => { + it('should send proper payload for #generatedAnswerCollapse', async () => { const exampleGeneratedAnswerMetadata = { generativeQuestionAnsweringId: '123', }; @@ -1380,8 +1380,8 @@ describe('InsightClient', () => { ...expectedBaseCaseMetadata, }; - await client.logCollapseGeneratedAnswer(exampleGeneratedAnswerMetadata, baseCaseMetadata); - expectMatchCustomEventPayload(SearchPageEvents.collapseGeneratedAnswer, expectedMetadata); + await client.logGeneratedAnswerCollapse(exampleGeneratedAnswerMetadata, baseCaseMetadata); + expectMatchCustomEventPayload(SearchPageEvents.generatedAnswerCollapse, expectedMetadata); }); it('should send proper payload for #generatedAnswerFeedbackSubmit', async () => { diff --git a/src/insight/insightClient.ts b/src/insight/insightClient.ts index e767b11..95f184e 100644 --- a/src/insight/insightClient.ts +++ b/src/insight/insightClient.ts @@ -560,18 +560,18 @@ export class CoveoInsightClient { ); } - public logExpandGeneratedAnswer(generatedAnswerMetadata: GeneratedAnswerBaseMeta, metadata?: CaseMetadata) { + public logGeneratedAnswerExpand(generatedAnswerMetadata: GeneratedAnswerBaseMeta, metadata?: CaseMetadata) { return this.logCustomEvent( - SearchPageEvents.expandGeneratedAnswer, + SearchPageEvents.generatedAnswerExpand, metadata ? {...generateMetadataToSend(metadata, false), ...generatedAnswerMetadata} : generatedAnswerMetadata ); } - public logCollapseGeneratedAnswer(generatedAnswerMetadata: GeneratedAnswerBaseMeta, metadata?: CaseMetadata) { + public logGeneratedAnswerCollapse(generatedAnswerMetadata: GeneratedAnswerBaseMeta, metadata?: CaseMetadata) { return this.logCustomEvent( - SearchPageEvents.collapseGeneratedAnswer, + SearchPageEvents.generatedAnswerCollapse, metadata ? {...generateMetadataToSend(metadata, false), ...generatedAnswerMetadata} : generatedAnswerMetadata diff --git a/src/searchPage/searchPageClient.spec.ts b/src/searchPage/searchPageClient.spec.ts index 92bbbb3..9fd090a 100644 --- a/src/searchPage/searchPageClient.spec.ts +++ b/src/searchPage/searchPageClient.spec.ts @@ -1573,32 +1573,32 @@ describe('SearchPageClient', () => { expectMatchDescription(built.description, SearchPageEvents.generatedAnswerShowAnswers, meta); }); - it('should send proper payload for #logExpandGeneratedAnswer', async () => { + it('should send proper payload for #logGeneratedAnswerExpand', async () => { const meta = {generativeQuestionAnsweringId: fakeStreamId}; - await client.logExpandGeneratedAnswer(meta); - expectMatchCustomEventPayload(SearchPageEvents.expandGeneratedAnswer, meta); + await client.logGeneratedAnswerExpand(meta); + expectMatchCustomEventPayload(SearchPageEvents.generatedAnswerExpand, meta); }); - it('should send proper payload for #makeExpandGeneratedAnswer', async () => { + it('should send proper payload for #makeGeneratedAnswerExpand', async () => { const meta = {generativeQuestionAnsweringId: fakeStreamId}; - const built = await client.makeExpandGeneratedAnswer(meta); + const built = await client.makeGeneratedAnswerExpand(meta); await built.log({searchUID: provider.getSearchUID()}); - expectMatchCustomEventPayload(SearchPageEvents.expandGeneratedAnswer, meta); - expectMatchDescription(built.description, SearchPageEvents.expandGeneratedAnswer, meta); + expectMatchCustomEventPayload(SearchPageEvents.generatedAnswerExpand, meta); + expectMatchDescription(built.description, SearchPageEvents.generatedAnswerExpand, meta); }); - it('should send proper payload for #logCollapseGeneratedAnswer', async () => { + it('should send proper payload for #logGeneratedAnswerCollapse', async () => { const meta = {generativeQuestionAnsweringId: fakeStreamId}; - await client.logCollapseGeneratedAnswer(meta); - expectMatchCustomEventPayload(SearchPageEvents.collapseGeneratedAnswer, meta); + await client.logGeneratedAnswerCollapse(meta); + expectMatchCustomEventPayload(SearchPageEvents.generatedAnswerCollapse, meta); }); - it('should send proper payload for #makeCollapseGeneratedAnswer', async () => { + it('should send proper payload for #makeGeneratedAnswerCollapse', async () => { const meta = {generativeQuestionAnsweringId: fakeStreamId}; - const built = await client.makeCollapseGeneratedAnswer(meta); + const built = await client.makeGeneratedAnswerCollapse(meta); await built.log({searchUID: provider.getSearchUID()}); - expectMatchCustomEventPayload(SearchPageEvents.collapseGeneratedAnswer, meta); - expectMatchDescription(built.description, SearchPageEvents.collapseGeneratedAnswer, meta); + expectMatchCustomEventPayload(SearchPageEvents.generatedAnswerCollapse, meta); + expectMatchDescription(built.description, SearchPageEvents.generatedAnswerCollapse, meta); }); it('should send proper payload for #logGeneratedAnswerFeedbackSubmit', async () => { diff --git a/src/searchPage/searchPageClient.ts b/src/searchPage/searchPageClient.ts index 08fae0d..b8789e2 100644 --- a/src/searchPage/searchPageClient.ts +++ b/src/searchPage/searchPageClient.ts @@ -951,20 +951,20 @@ export class CoveoSearchPageClient { }); } - public makeExpandGeneratedAnswer(metadata: GeneratedAnswerBaseMeta) { - return this.makeCustomEvent(SearchPageEvents.expandGeneratedAnswer, metadata); + public makeGeneratedAnswerExpand(metadata: GeneratedAnswerBaseMeta) { + return this.makeCustomEvent(SearchPageEvents.generatedAnswerExpand, metadata); } - public async logExpandGeneratedAnswer(metadata: GeneratedAnswerBaseMeta) { - return (await this.makeExpandGeneratedAnswer(metadata)).log({searchUID: this.provider.getSearchUID()}); + public async logGeneratedAnswerExpand(metadata: GeneratedAnswerBaseMeta) { + return (await this.makeGeneratedAnswerExpand(metadata)).log({searchUID: this.provider.getSearchUID()}); } - public makeCollapseGeneratedAnswer(metadata: GeneratedAnswerBaseMeta) { - return this.makeCustomEvent(SearchPageEvents.collapseGeneratedAnswer, metadata); + public makeGeneratedAnswerCollapse(metadata: GeneratedAnswerBaseMeta) { + return this.makeCustomEvent(SearchPageEvents.generatedAnswerCollapse, metadata); } - public async logCollapseGeneratedAnswer(metadata: GeneratedAnswerBaseMeta) { - return (await this.makeCollapseGeneratedAnswer(metadata)).log({searchUID: this.provider.getSearchUID()}); + public async logGeneratedAnswerCollapse(metadata: GeneratedAnswerBaseMeta) { + return (await this.makeGeneratedAnswerCollapse(metadata)).log({searchUID: this.provider.getSearchUID()}); } public makeGeneratedAnswerFeedbackSubmit(meta: GeneratedAnswerFeedbackMeta) { diff --git a/src/searchPage/searchPageEvents.ts b/src/searchPage/searchPageEvents.ts index 128be85..15e47b8 100644 --- a/src/searchPage/searchPageEvents.ts +++ b/src/searchPage/searchPageEvents.ts @@ -333,11 +333,11 @@ export enum SearchPageEvents { /** * Identifies the custom event that gets logged when a user expand a generated answer. */ - expandGeneratedAnswer = 'expandGeneratedAnswer', + generatedAnswerExpand = 'generatedAnswerExpand', /** * Identifies the custom event that gets logged when a user collapse a generated answer. */ - collapseGeneratedAnswer = 'collapseGeneratedAnswer', + generatedAnswerCollapse = 'generatedAnswerCollapse', /** * Identifies the custom event that gets logged when a user submits a feedback of a generated answer. */ @@ -390,8 +390,8 @@ export const CustomEventsTypes: Partial