Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(genQA): new RGA UA events added to the search page client #438

Merged
merged 7 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions src/searchPage/searchPageClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
CustomEventsTypes,
OmniboxSuggestionsMetadata,
StaticFilterToggleValueMetadata,
GeneratedAnswerFeedbackReason,
GeneratedAnswerRephraseFormat,
} from './searchPageEvents';
import CoveoAnalyticsClient from '../client/analytics';
import {NoopAnalytics} from '../client/noopAnalytics';
Expand Down Expand Up @@ -1471,4 +1473,112 @@ describe('SearchPageClient', () => {
expectMatchCustomEventPayload(SearchPageEvents.generatedAnswerStreamEnd, meta);
expectMatchDescription(built.description, SearchPageEvents.generatedAnswerStreamEnd, meta);
});

it('should send proper payload for #logGeneratedAnswerSourceHover', async () => {
const meta = {
generativeQuestionAnsweringId: fakeStreamId,
id: 'some-document-id',
permanentId: 'perm-id',
citationHoverTimeMs: 100,
};
await client.logGeneratedAnswerSourceHover(meta);
expectMatchCustomEventPayload(SearchPageEvents.generatedAnswerSourceHover, meta);
});

it('should send proper payload for #makeGeneratedAnswerSourceHover', async () => {
const meta = {
generativeQuestionAnsweringId: fakeStreamId,
id: 'some-document-id',
permanentId: 'perm-id',
citationHoverTimeMs: 100,
};
const built = await client.makeGeneratedAnswerSourceHover(meta);
await built.log({searchUID: provider.getSearchUID()});
expectMatchCustomEventPayload(SearchPageEvents.generatedAnswerSourceHover, meta);
expectMatchDescription(built.description, SearchPageEvents.generatedAnswerSourceHover, meta);
});

it('should send proper payload for #logGeneratedAnswerCopyToClipboard', async () => {
const meta = {generativeQuestionAnsweringId: fakeStreamId};
await client.logGeneratedAnswerCopyToClipboard(meta);
expectMatchCustomEventPayload(SearchPageEvents.generatedAnswerCopyToClipboard, meta);
});

it('should send proper payload for #makeGeneratedAnswerCopyToClipboard', async () => {
const meta = {generativeQuestionAnsweringId: fakeStreamId};
const built = await client.makeGeneratedAnswerCopyToClipboard(meta);
await built.log({searchUID: provider.getSearchUID()});
expectMatchCustomEventPayload(SearchPageEvents.generatedAnswerCopyToClipboard, meta);
expectMatchDescription(built.description, SearchPageEvents.generatedAnswerCopyToClipboard, meta);
});

it('should send proper payload for #logGeneratedAnswerHideAnswers', async () => {
const meta = {generativeQuestionAnsweringId: fakeStreamId};
await client.logGeneratedAnswerHideAnswers(meta);
expectMatchCustomEventPayload(SearchPageEvents.generatedAnswerHideAnswers, meta);
});

it('should send proper payload for #makeGeneratedAnswerHideAnswers', async () => {
const meta = {generativeQuestionAnsweringId: fakeStreamId};
const built = await client.makeGeneratedAnswerHideAnswers(meta);
await built.log({searchUID: provider.getSearchUID()});
expectMatchCustomEventPayload(SearchPageEvents.generatedAnswerHideAnswers, meta);
expectMatchDescription(built.description, SearchPageEvents.generatedAnswerHideAnswers, meta);
});

it('should send proper payload for #logGeneratedAnswerShowAnswers', async () => {
const meta = {generativeQuestionAnsweringId: fakeStreamId};
await client.logGeneratedAnswerShowAnswers(meta);
expectMatchCustomEventPayload(SearchPageEvents.generatedAnswerShowAnswers, meta);
});

it('should send proper payload for #makeGeneratedAnswerShowAnswers', async () => {
const meta = {generativeQuestionAnsweringId: fakeStreamId};
const built = await client.makeGeneratedAnswerShowAnswers(meta);
await built.log({searchUID: provider.getSearchUID()});
expectMatchCustomEventPayload(SearchPageEvents.generatedAnswerShowAnswers, meta);
expectMatchDescription(built.description, SearchPageEvents.generatedAnswerShowAnswers, meta);
});

it('should send proper payload for #logGenerativeQuestionFeedbackSubmit', async () => {
const meta = {
generativeQuestionAnsweringId: fakeStreamId,
reason: <GeneratedAnswerFeedbackReason>'other',
details: 'a few additional details',
};
await client.logGenerativeQuestionFeedbackSubmit(meta);
expectMatchCustomEventPayload(SearchPageEvents.generativeQuestionFeedbackSubmit, meta);
});

it('should send proper payload for #makeGenerativeQuestionFeedbackSubmit', async () => {
const meta = {
generativeQuestionAnsweringId: fakeStreamId,
reason: <GeneratedAnswerFeedbackReason>'other',
details: 'a few additional details',
};
const built = await client.makeGenerativeQuestionFeedbackSubmit(meta);
await built.log({searchUID: provider.getSearchUID()});
expectMatchCustomEventPayload(SearchPageEvents.generativeQuestionFeedbackSubmit, meta);
expectMatchDescription(built.description, SearchPageEvents.generativeQuestionFeedbackSubmit, meta);
});

it('should send proper payload for #logRephraseGeneratedAnswer', async () => {
const meta = {
generativeQuestionAnsweringId: fakeStreamId,
rephraseFormat: <GeneratedAnswerRephraseFormat>'stepByStep',
};
await client.logRephraseGeneratedAnswer(meta);
expectMatchPayload(SearchPageEvents.rephraseGeneratedAnswer, meta);
});

it('should send proper payload for #makeRephraseGeneratedAnswer', async () => {
const meta = {
generativeQuestionAnsweringId: fakeStreamId,
rephraseFormat: <GeneratedAnswerRephraseFormat>'stepByStep',
};
const built = await client.makeRephraseGeneratedAnswer(meta);
await built.log({searchUID: provider.getSearchUID()});
expectMatchPayload(SearchPageEvents.rephraseGeneratedAnswer, meta);
expectMatchDescription(built.description, SearchPageEvents.rephraseGeneratedAnswer, meta);
});
});
69 changes: 65 additions & 4 deletions src/searchPage/searchPageClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ import {
GeneratedAnswerFeedbackMeta,
GeneratedAnswerCitationMeta,
GeneratedAnswerStreamEndMeta,
GeneratedAnswerSourceHoverMeta,
GeneratedAnswerBaseMeta,
GeneratedAnswerRephraseMeta,
} from './searchPageEvents';
import {NoopAnalytics} from '../client/noopAnalytics';
import {formatOmniboxMetadata} from '../formatting/format-omnibox-metadata';
Expand Down Expand Up @@ -885,19 +888,19 @@ export class CoveoSearchPageClient {
};
}

public makeLikeGeneratedAnswer(metadata: GeneratedAnswerFeedbackMeta) {
public makeLikeGeneratedAnswer(metadata: GeneratedAnswerBaseMeta) {
return this.makeCustomEvent(SearchPageEvents.likeGeneratedAnswer, metadata);
}

public async logLikeGeneratedAnswer(metadata: GeneratedAnswerFeedbackMeta) {
public async logLikeGeneratedAnswer(metadata: GeneratedAnswerBaseMeta) {
return (await this.makeLikeGeneratedAnswer(metadata)).log({searchUID: this.provider.getSearchUID()});
}

public makeDislikeGeneratedAnswer(metadata: GeneratedAnswerFeedbackMeta) {
public makeDislikeGeneratedAnswer(metadata: GeneratedAnswerBaseMeta) {
return this.makeCustomEvent(SearchPageEvents.dislikeGeneratedAnswer, metadata);
}

public async logDislikeGeneratedAnswer(metadata: GeneratedAnswerFeedbackMeta) {
public async logDislikeGeneratedAnswer(metadata: GeneratedAnswerBaseMeta) {
return (await this.makeDislikeGeneratedAnswer(metadata)).log({searchUID: this.provider.getSearchUID()});
}

Expand All @@ -911,6 +914,64 @@ export class CoveoSearchPageClient {
});
}

public makeGeneratedAnswerSourceHover(metadata: GeneratedAnswerSourceHoverMeta) {
return this.makeCustomEvent(SearchPageEvents.generatedAnswerSourceHover, metadata);
}

public async logGeneratedAnswerSourceHover(metadata: GeneratedAnswerSourceHoverMeta) {
return (await this.makeGeneratedAnswerSourceHover(metadata)).log({
searchUID: this.provider.getSearchUID(),
});
}

public makeGeneratedAnswerCopyToClipboard(metadata: GeneratedAnswerBaseMeta) {
return this.makeCustomEvent(SearchPageEvents.generatedAnswerCopyToClipboard, metadata);
}

public async logGeneratedAnswerCopyToClipboard(metadata: GeneratedAnswerBaseMeta) {
return (await this.makeGeneratedAnswerCopyToClipboard(metadata)).log({
searchUID: this.provider.getSearchUID(),
});
}

public makeGeneratedAnswerHideAnswers(metadata: GeneratedAnswerBaseMeta) {
return this.makeCustomEvent(SearchPageEvents.generatedAnswerHideAnswers, metadata);
}

public async logGeneratedAnswerHideAnswers(metadata: GeneratedAnswerBaseMeta) {
return (await this.makeGeneratedAnswerHideAnswers(metadata)).log({
searchUID: this.provider.getSearchUID(),
});
}

public makeGeneratedAnswerShowAnswers(metadata: GeneratedAnswerBaseMeta) {
return this.makeCustomEvent(SearchPageEvents.generatedAnswerShowAnswers, metadata);
}

public async logGeneratedAnswerShowAnswers(metadata: GeneratedAnswerBaseMeta) {
return (await this.makeGeneratedAnswerShowAnswers(metadata)).log({
searchUID: this.provider.getSearchUID(),
});
}

public makeGenerativeQuestionFeedbackSubmit(meta: GeneratedAnswerFeedbackMeta) {
return this.makeCustomEvent(SearchPageEvents.generativeQuestionFeedbackSubmit, meta);
}

public async logGenerativeQuestionFeedbackSubmit(meta: GeneratedAnswerFeedbackMeta) {
return (await this.makeGenerativeQuestionFeedbackSubmit(meta)).log({
searchUID: this.provider.getSearchUID(),
});
}

public makeRephraseGeneratedAnswer(meta: GeneratedAnswerRephraseMeta) {
return this.makeSearchEvent(SearchPageEvents.rephraseGeneratedAnswer, meta);
}

public async logRephraseGeneratedAnswer(meta: GeneratedAnswerRephraseMeta) {
return (await this.makeRephraseGeneratedAnswer(meta)).log({searchUID: this.provider.getSearchUID()});
}

public makeRetryGeneratedAnswer() {
return this.makeSearchEvent(SearchPageEvents.retryGeneratedAnswer);
}
Expand Down
50 changes: 47 additions & 3 deletions src/searchPage/searchPageEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,30 @@ export enum SearchPageEvents {
* Identified the custom event that gets logged when a generated answer stream is completed.
*/
generatedAnswerStreamEnd = 'generatedAnswerStreamEnd',
/**
* Identifies the custom event that gets logged when a user hovers over a generated answer citation.
*/
generatedAnswerSourceHover = 'generatedAnswerSourceHover',
/**
* Identifies the custom event that gets logged when a user clicks the copy to clip board button of a generated answer.
*/
generatedAnswerCopyToClipboard = 'generatedAnswerCopyToClipboard',
/**
* Identifies the custom event that gets logged when a user deactivates the genQA feature.
*/
generatedAnswerHideAnswers = 'generatedAnswerHideAnswers',
/**
* 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 submits a feedback of a generated answer.
*/
generativeQuestionFeedbackSubmit = 'generativeQuestionFeedbackSubmit',
/**
* Identifies the search event that gets logged when a user clicks the rephrase button in a generated answer.
*/
rephraseGeneratedAnswer = 'rephraseGeneratedAnswer',
}

export const CustomEventsTypes: Partial<Record<SearchPageEvents | InsightEvents, string>> = {
Expand Down Expand Up @@ -360,6 +384,11 @@ export const CustomEventsTypes: Partial<Record<SearchPageEvents | InsightEvents,
[SearchPageEvents.dislikeGeneratedAnswer]: 'generatedAnswer',
[SearchPageEvents.openGeneratedAnswerSource]: 'generatedAnswer',
[SearchPageEvents.generatedAnswerStreamEnd]: 'generatedAnswer',
[SearchPageEvents.generatedAnswerSourceHover]: 'generatedAnswer',
[SearchPageEvents.generatedAnswerCopyToClipboard]: 'generatedAnswer',
[SearchPageEvents.generatedAnswerHideAnswers]: 'generatedAnswer',
[SearchPageEvents.generatedAnswerShowAnswers]: 'generatedAnswer',
[SearchPageEvents.generativeQuestionFeedbackSubmit]: 'generatedAnswer',
};

export interface StaticFilterMetadata {
Expand Down Expand Up @@ -494,12 +523,10 @@ export interface SmartSnippetDocumentIdentifier {

export type PartialDocumentInformation = Omit<DocumentInformation, 'actionCause' | 'searchQueryUid'>;

interface GeneratedAnswerBaseMeta {
export interface GeneratedAnswerBaseMeta {
generativeQuestionAnsweringId: string;
}

export interface GeneratedAnswerFeedbackMeta extends GeneratedAnswerBaseMeta {}

export interface GeneratedAnswerStreamEndMeta extends GeneratedAnswerBaseMeta {
answerGenerated: boolean;
}
Expand All @@ -509,3 +536,20 @@ export interface GeneratedAnswerCitationMeta {
permanentId: string;
id: string;
mmitiche marked this conversation as resolved.
Show resolved Hide resolved
}

export type GeneratedAnswerFeedbackReason = 'irrelevant' | 'notAccurate' | 'outOfDate' | 'harmful' | 'other';

export type GeneratedAnswerRephraseFormat = 'stepByStep' | 'bulletPoints' | 'summarize';

export interface GeneratedAnswerSourceHoverMeta extends GeneratedAnswerCitationMeta {
citationHoverTimeMs: number;
}

export interface GeneratedAnswerRephraseMeta extends GeneratedAnswerBaseMeta {
rephraseFormat: GeneratedAnswerRephraseFormat;
}

export interface GeneratedAnswerFeedbackMeta extends GeneratedAnswerBaseMeta {
reason: GeneratedAnswerFeedbackReason;
details?: string;
}