Skip to content

Commit

Permalink
Merge pull request #476 from coveo/feature/SVCC-4171
Browse files Browse the repository at this point in the history
feat(genqa): add logCitationClick event
  • Loading branch information
jelmedini authored Oct 1, 2024
2 parents d06f834 + fe30274 commit fba02a7
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export interface PreparedSearchEventRequest extends Omit<SearchEventRequest, 'se

export interface DocumentInformation {
documentUri?: string;
documentUriHash: string;
documentUriHash?: string;
collectionName?: string;
sourceName: string;
documentPosition: number;
Expand Down
34 changes: 34 additions & 0 deletions src/insight/insightClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,23 @@ describe('InsightClient', () => {
expectMatchCustomEventPayload(SearchPageEvents.openGeneratedAnswerSource, exampleGeneratedAnswerMetadata);
});

it('should send proper payload for #generatedAnswerCitationClick', async () => {
const meta = {
generativeQuestionAnsweringId: '123',
citationId: 'bar',
documentId: {contentIdKey: 'permanentid', contentIdValue: 'foo'},
};

const expectedMetadata = {
...meta,
contentIDKey: meta.documentId.contentIdKey,
contentIDValue: meta.documentId.contentIdValue,
};

await client.logGeneratedAnswerCitationClick(fakeDocInfo, meta);
expectMatchDocumentPayload(SearchPageEvents.generatedAnswerCitationClick, fakeDocInfo, expectedMetadata);
});

it('should send proper payload for #generatedAnswerSourceHover', async () => {
const exampleGeneratedAnswerMetadata = {
generativeQuestionAnsweringId: '123',
Expand Down Expand Up @@ -1331,6 +1348,23 @@ describe('InsightClient', () => {
expectMatchCustomEventPayload(SearchPageEvents.openGeneratedAnswerSource, expectedMetadata);
});

it('should send proper payload for #generatedAnswerCitationClick', async () => {
const meta = {
generativeQuestionAnsweringId: '123',
citationId: 'bar',
documentId: {contentIdKey: 'permanentid', contentIdValue: 'foo'},
};

const expectedMetadata = {
...meta,
contentIDKey: meta.documentId.contentIdKey,
contentIDValue: meta.documentId.contentIdValue,
};

await client.logGeneratedAnswerCitationClick(fakeDocInfo, meta, baseCaseMetadata);
expectMatchDocumentPayload(SearchPageEvents.generatedAnswerCitationClick, fakeDocInfo, expectedMetadata);
});

it('should send proper payload for #generatedAnswerSourceHover', async () => {
const exampleGeneratedAnswerMetadata = {
generativeQuestionAnsweringId: '123',
Expand Down
14 changes: 14 additions & 0 deletions src/insight/insightClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
DocumentIdentifier,
FacetStateMetadata,
GeneratedAnswerBaseMeta,
GeneratedAnswerCitationClickMeta,
GeneratedAnswerCitationMeta,
GeneratedAnswerFeedbackMeta,
GeneratedAnswerFeedbackMetaV2,
Expand Down Expand Up @@ -520,6 +521,19 @@ export class CoveoInsightClient {
);
}

public logGeneratedAnswerCitationClick(
info: PartialDocumentInformation,
citation: GeneratedAnswerCitationClickMeta,
metadata?: CaseMetadata
) {
return this.logClickEvent(
SearchPageEvents.generatedAnswerCitationClick,
{...info, documentPosition: 1},
{contentIDKey: citation.documentId.contentIdKey, contentIDValue: citation.documentId.contentIdValue},
metadata ? {...generateMetadataToSend(metadata, false), ...citation} : citation
);
}

public logGeneratedAnswerSourceHover(
generatedAnswerSourceMetadata: GeneratedAnswerSourceHoverMeta,
metadata?: CaseMetadata
Expand Down
29 changes: 29 additions & 0 deletions src/searchPage/searchPageClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1494,6 +1494,35 @@ describe('SearchPageClient', () => {
expectMatchDescription(built.description, SearchPageEvents.openGeneratedAnswerSource, meta);
});

it('should send proper payload for #logGeneratedAnswerCitationClick', async () => {
const meta = {
generativeQuestionAnsweringId: fakeStreamId,
citationId: 'some-document-id',
documentId: {contentIdKey: 'permanentid', contentIdValue: 'foo'},
};

await client.logGeneratedAnswerCitationClick(fakeDocInfo, meta);
expectMatchDocumentPayload(SearchPageEvents.generatedAnswerCitationClick, fakeDocInfo, {
...meta,
contentIDKey: meta.documentId.contentIdKey,
contentIDValue: meta.documentId.contentIdValue,
});
});

it('should send proper payload for #makeGeneratedAnswerCitationClick', async () => {
const meta = {
generativeQuestionAnsweringId: fakeStreamId,
citationId: 'some-document-id',
contentIDKey: 'permanentid',
contentIDValue: 'foo',
documentId: {contentIdKey: 'permanentid', contentIdValue: 'foo'},
};
const built = await client.makeGeneratedAnswerCitationClick(fakeDocInfo, meta);
await built.log({searchUID: provider.getSearchUID()});
expectMatchDocumentPayload(SearchPageEvents.generatedAnswerCitationClick, fakeDocInfo, meta);
expectMatchDescription(built.description, SearchPageEvents.generatedAnswerCitationClick, meta);
});

it('should send proper payload for #logGeneratedAnswerStreamEnd', async () => {
const meta = {generativeQuestionAnsweringId: fakeStreamId, answerGenerated: true, answerTextIsEmpty: false};
await client.logGeneratedAnswerStreamEnd(meta);
Expand Down
22 changes: 22 additions & 0 deletions src/searchPage/searchPageClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
GeneratedAnswerBaseMeta,
GeneratedAnswerRephraseMeta,
GeneratedAnswerFeedbackMetaV2,
GeneratedAnswerCitationClickMeta,
} from './searchPageEvents';
import {NoopAnalytics} from '../client/noopAnalytics';
import {formatOmniboxMetadata} from '../formatting/format-omnibox-metadata';
Expand Down Expand Up @@ -912,6 +913,27 @@ export class CoveoSearchPageClient {
});
}

public makeGeneratedAnswerCitationClick(
info: PartialDocumentInformation,
citation: GeneratedAnswerCitationClickMeta
) {
return this.makeClickEvent(
SearchPageEvents.generatedAnswerCitationClick,
{...info, documentPosition: 1},
{contentIDKey: citation.documentId.contentIdKey, contentIDValue: citation.documentId.contentIdValue},
citation
);
}

public async logGeneratedAnswerCitationClick(
info: PartialDocumentInformation,
citation: GeneratedAnswerCitationClickMeta
) {
return (await this.makeGeneratedAnswerCitationClick(info, citation)).log({
searchUID: this.provider.getSearchUID(),
});
}

public makeGeneratedAnswerSourceHover(metadata: GeneratedAnswerSourceHoverMeta) {
return this.makeCustomEvent(SearchPageEvents.generatedAnswerSourceHover, metadata);
}
Expand Down
14 changes: 14 additions & 0 deletions src/searchPage/searchPageEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,10 @@ export enum SearchPageEvents {
* Identifies the new version of custom event that gets logged when a user submits a feedback of a generated answer.
*/
generatedAnswerFeedbackSubmitV2 = 'generatedAnswerFeedbackSubmitV2',
/**
* Identifies the click event that gets logged when the user clicks on a generated answer citation.
*/
generatedAnswerCitationClick = 'generatedAnswerCitationClick',
}

export const CustomEventsTypes: Partial<Record<SearchPageEvents | InsightEvents, string>> = {
Expand Down Expand Up @@ -561,6 +565,16 @@ export type GeneratedAnswerCitationMeta = GeneratedAnswerBaseMeta & {
citationId: string;
};

export type GeneratedAnswerCitationClickMeta = GeneratedAnswerBaseMeta & {
citationId: string;
documentId: GeneratedAnswerDocumentIdentifier;
};

type GeneratedAnswerDocumentIdentifier = {
contentIdKey: string;
contentIdValue: string;
};

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

export type GeneratedAnswerRephraseFormat = 'step' | 'bullet' | 'concise' | 'default';
Expand Down

0 comments on commit fba02a7

Please sign in to comment.