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): add logCitationClick event #476

Merged
merged 3 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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 () => {
jelmedini marked this conversation as resolved.
Show resolved Hide resolved
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,
jelmedini marked this conversation as resolved.
Show resolved Hide resolved
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