diff --git a/src/insight/insightClient.spec.ts b/src/insight/insightClient.spec.ts index 6b5d67d..b699ba5 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 #generatedAnswerExpand', async () => { + const exampleGeneratedAnswerMetadata = { + generativeQuestionAnsweringId: '123', + }; + + await client.logGeneratedAnswerExpand(exampleGeneratedAnswerMetadata); + expectMatchCustomEventPayload(SearchPageEvents.generatedAnswerExpand, exampleGeneratedAnswerMetadata); + }); + + it('should send proper payload for #generatedAnswerCollapse', async () => { + const exampleGeneratedAnswerMetadata = { + generativeQuestionAnsweringId: '123', + }; + + await client.logGeneratedAnswerCollapse(exampleGeneratedAnswerMetadata); + expectMatchCustomEventPayload(SearchPageEvents.generatedAnswerCollapse, 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 #generatedAnswerExpand', async () => { + const exampleGeneratedAnswerMetadata = { + generativeQuestionAnsweringId: '123', + }; + const expectedMetadata = { + ...exampleGeneratedAnswerMetadata, + ...expectedBaseCaseMetadata, + }; + + await client.logGeneratedAnswerExpand(exampleGeneratedAnswerMetadata, baseCaseMetadata); + expectMatchCustomEventPayload(SearchPageEvents.generatedAnswerExpand, expectedMetadata); + }); + + it('should send proper payload for #generatedAnswerCollapse', async () => { + const exampleGeneratedAnswerMetadata = { + generativeQuestionAnsweringId: '123', + }; + const expectedMetadata = { + ...exampleGeneratedAnswerMetadata, + ...expectedBaseCaseMetadata, + }; + + await client.logGeneratedAnswerCollapse(exampleGeneratedAnswerMetadata, baseCaseMetadata); + expectMatchCustomEventPayload(SearchPageEvents.generatedAnswerCollapse, 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..95f184e 100644 --- a/src/insight/insightClient.ts +++ b/src/insight/insightClient.ts @@ -560,6 +560,24 @@ export class CoveoInsightClient { ); } + public logGeneratedAnswerExpand(generatedAnswerMetadata: GeneratedAnswerBaseMeta, metadata?: CaseMetadata) { + return this.logCustomEvent( + SearchPageEvents.generatedAnswerExpand, + metadata + ? {...generateMetadataToSend(metadata, false), ...generatedAnswerMetadata} + : generatedAnswerMetadata + ); + } + + public logGeneratedAnswerCollapse(generatedAnswerMetadata: GeneratedAnswerBaseMeta, metadata?: CaseMetadata) { + return this.logCustomEvent( + SearchPageEvents.generatedAnswerCollapse, + 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..9fd090a 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 #logGeneratedAnswerExpand', async () => { + const meta = {generativeQuestionAnsweringId: fakeStreamId}; + await client.logGeneratedAnswerExpand(meta); + expectMatchCustomEventPayload(SearchPageEvents.generatedAnswerExpand, meta); + }); + + it('should send proper payload for #makeGeneratedAnswerExpand', async () => { + const meta = {generativeQuestionAnsweringId: fakeStreamId}; + const built = await client.makeGeneratedAnswerExpand(meta); + await built.log({searchUID: provider.getSearchUID()}); + expectMatchCustomEventPayload(SearchPageEvents.generatedAnswerExpand, meta); + expectMatchDescription(built.description, SearchPageEvents.generatedAnswerExpand, meta); + }); + + it('should send proper payload for #logGeneratedAnswerCollapse', async () => { + const meta = {generativeQuestionAnsweringId: fakeStreamId}; + await client.logGeneratedAnswerCollapse(meta); + expectMatchCustomEventPayload(SearchPageEvents.generatedAnswerCollapse, meta); + }); + + it('should send proper payload for #makeGeneratedAnswerCollapse', async () => { + const meta = {generativeQuestionAnsweringId: fakeStreamId}; + const built = await client.makeGeneratedAnswerCollapse(meta); + await built.log({searchUID: provider.getSearchUID()}); + expectMatchCustomEventPayload(SearchPageEvents.generatedAnswerCollapse, meta); + expectMatchDescription(built.description, SearchPageEvents.generatedAnswerCollapse, 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..b8789e2 100644 --- a/src/searchPage/searchPageClient.ts +++ b/src/searchPage/searchPageClient.ts @@ -951,6 +951,22 @@ export class CoveoSearchPageClient { }); } + public makeGeneratedAnswerExpand(metadata: GeneratedAnswerBaseMeta) { + return this.makeCustomEvent(SearchPageEvents.generatedAnswerExpand, metadata); + } + + public async logGeneratedAnswerExpand(metadata: GeneratedAnswerBaseMeta) { + return (await this.makeGeneratedAnswerExpand(metadata)).log({searchUID: this.provider.getSearchUID()}); + } + + public makeGeneratedAnswerCollapse(metadata: GeneratedAnswerBaseMeta) { + return this.makeCustomEvent(SearchPageEvents.generatedAnswerCollapse, metadata); + } + + public async logGeneratedAnswerCollapse(metadata: GeneratedAnswerBaseMeta) { + return (await this.makeGeneratedAnswerCollapse(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..15e47b8 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. + */ + generatedAnswerExpand = 'generatedAnswerExpand', + /** + * Identifies the custom event that gets logged when a user collapse a generated answer. + */ + generatedAnswerCollapse = 'generatedAnswerCollapse', /** * 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