From 4397ffb71bf1bc0b91dba759cd6ca31d31719bad Mon Sep 17 00:00:00 2001 From: Olga Bulat Date: Fri, 13 Dec 2024 07:31:05 +0300 Subject: [PATCH] Make analytics tests stricter; replace collectionValue with query (#5267) --- frontend/shared/types/analytics.ts | 68 +++++++++---------- .../src/components/VImageCell/VImageCell.vue | 7 +- .../VMediaInfo/VLicenseTabPanel.vue | 4 +- .../VSearchResultsGrid/VAudioResult.vue | 7 +- frontend/src/stores/search.ts | 6 +- .../e2e/all-results-analytics.spec.ts | 57 +++++++++------- .../test/playwright/e2e/audio-detail.spec.ts | 25 ++++--- .../test/playwright/e2e/image-detail.spec.ts | 20 +++--- .../test/playwright/e2e/load-more.spec.ts | 43 ++++++------ frontend/test/playwright/utils/analytics.ts | 10 ++- 10 files changed, 136 insertions(+), 111 deletions(-) diff --git a/frontend/shared/types/analytics.ts b/frontend/shared/types/analytics.ts index 3d10fed25a9..bf4340938b1 100644 --- a/frontend/shared/types/analytics.ts +++ b/frontend/shared/types/analytics.ts @@ -28,17 +28,21 @@ export type AudioComponent = */ export type SearchParamsForEvent = { kind: "search" | "collection" + /** The search type of the current results page */ searchType: SupportedSearchType + /** The search term, or a string representing a unique identifier for the collection */ query: string - - /** - * Common properties related to searches on collection pages, added in the - * "Additional Search Views" project. - */ /** If a collection page, the type of collection */ collectionType: Collection | "null" - /** A string representing a unique identifier for the collection */ - collectionValue: string | "null" +} + +/** + * Common properties for search result events, used to link the result to + * assess relevancy. + */ +export type SearchResultParams = { + /** The unique ID of the media */ + id: string } /** @@ -75,7 +79,7 @@ export type Events = { * - How many results do most searches yield? */ GET_SEARCH_RESULTS: { - /** the media type being searched */ + /** the media type of the results. Is different from `searchType` when searchType is "all media" */ mediaType: SupportedMediaType /** The search term */ query: string @@ -108,9 +112,7 @@ export type Events = { * - Do users right-click images often? Does this suggest downloading them directly, * when not paired with a `GET_MEDIA` event? */ - RIGHT_CLICK_IMAGE: { - id: string - } + RIGHT_CLICK_IMAGE: SearchResultParams /** * Click on the 'back to search' link on a single result * @@ -155,9 +157,7 @@ export type Events = { * Questions: * - How often do users go to the source after viewing a result? */ - GET_MEDIA: { - /** the unique ID of the media */ - id: string + GET_MEDIA: SearchResultParams & { /** The slug (not the prettified name) of the provider */ provider: string /** The media type being searched */ @@ -169,9 +169,7 @@ export type Events = { * - How often do users use our attribution tool? * - Which format is the most popular? */ - COPY_ATTRIBUTION: { - /** The unique ID of the media */ - id: string + COPY_ATTRIBUTION: SearchResultParams & { /** The format of the copied attribution */ format: "plain" | "rich" | "html" | "xml" /** The media type being searched */ @@ -296,22 +294,23 @@ export type Events = { * - How often do searches lead to clicking a result? * - Are there popular searches that do not result in result selection? */ - SELECT_SEARCH_RESULT: Omit & { - /** The unique ID of the media */ - id: string - /** If the result is a related result, provide the ID of the 'original' result */ - relatedTo: string | "null" - /** Kind of the result selected: search/related/collection */ - kind: ResultKind - /** The media type being searched */ - mediaType: SearchType - /** The slug (not the prettified name) of the provider */ - provider: string - /** the reasons for why this result is considered sensitive */ - sensitivities: string - /** whether the result was blurred or visible when selected by the user */ - isBlurred: boolean | "null" - } + SELECT_SEARCH_RESULT: SearchResultParams & + Pick & { + /** If the result is a related result, provide the ID of the 'original' result */ + relatedTo: string | "null" + /** Kind of the result selected: search/related/collection */ + kind: ResultKind + /** The media type of the selected result */ + mediaType: SupportedMediaType + /** The search type of the current results page */ + searchType: SupportedSearchType + /** The slug (not the prettified name) of the provider */ + provider: string + /** the reasons for why this result is considered sensitive */ + sensitivities: string + /** whether the result was blurred or visible when selected by the user */ + isBlurred: boolean | "null" + } /** * Description: When a user opens the external sources popover. * Questions: @@ -337,8 +336,7 @@ export type Events = { * from anyway? */ LOAD_MORE_RESULTS: { - /** The current page of results the user is on, - * *before* loading more results.. */ + /** The current page of results the user is on, *before* loading more results. */ resultPage: number } & SearchParamsForEvent /** diff --git a/frontend/src/components/VImageCell/VImageCell.vue b/frontend/src/components/VImageCell/VImageCell.vue index a80d9a47db3..b69f9ea4905 100644 --- a/frontend/src/components/VImageCell/VImageCell.vue +++ b/frontend/src/components/VImageCell/VImageCell.vue @@ -111,18 +111,17 @@ const sendSelectSearchResultEvent = (event: MouseEvent) => { return } + const { searchType, collectionType } = searchStore.searchParamsForEvent $sendCustomEvent("SELECT_SEARCH_RESULT", { + searchType, + collectionType, id: props.image.id, kind: props.kind, mediaType: IMAGE, provider: props.image.provider, - query: props.searchTerm || "", relatedTo: props.relatedTo ?? "null", sensitivities: props.image.sensitivity?.join(",") ?? "", isBlurred: shouldBlur.value ?? "null", - collectionType: - searchStore.strategy !== "default" ? searchStore.strategy : "null", - collectionValue: searchStore.collectionValue ?? "null", }) } diff --git a/frontend/src/components/VMediaInfo/VLicenseTabPanel.vue b/frontend/src/components/VMediaInfo/VLicenseTabPanel.vue index 02ef9df5036..1ecc8b4d7b1 100644 --- a/frontend/src/components/VMediaInfo/VLicenseTabPanel.vue +++ b/frontend/src/components/VMediaInfo/VLicenseTabPanel.vue @@ -1,7 +1,7 @@