From 8a5ec31d24823bb26f8a5cf792189ca03953dfc1 Mon Sep 17 00:00:00 2001 From: Rijnard van Tonder Date: Mon, 25 Jul 2022 12:18:33 -0700 Subject: [PATCH] search: log lucky search events (#39329) --- .../search/results/StreamingSearchResults.tsx | 15 ++++++++++- .../web/src/search/suggestion/LuckySearch.tsx | 25 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/client/web/src/search/results/StreamingSearchResults.tsx b/client/web/src/search/results/StreamingSearchResults.tsx index 6dd5191632b..d3c930eb2dc 100644 --- a/client/web/src/search/results/StreamingSearchResults.tsx +++ b/client/web/src/search/results/StreamingSearchResults.tsx @@ -41,7 +41,7 @@ import { GettingStartedTour } from '../../tour/GettingStartedTour' import { SearchUserNeedsCodeHost } from '../../user/settings/codeHosts/OrgUserNeedsCodeHost' import { submitSearch } from '../helpers' import { DidYouMean } from '../suggestion/DidYouMean' -import { LuckySearch } from '../suggestion/LuckySearch' +import { LuckySearch, luckySearchEvent } from '../suggestion/LuckySearch' import { SearchAlert } from './SearchAlert' import { useCachedSearchResults } from './SearchResultsCacheProvider' @@ -167,6 +167,19 @@ export const StreamingSearchResults: React.FunctionComponent< } }, [results, telemetryService]) + // Log lucky search events + useEffect(() => { + if (results?.alert?.kind === 'lucky-search-queries' && results?.alert?.title && results.alert.proposedQueries) { + const events = luckySearchEvent( + results.alert.title, + results.alert.proposedQueries.map(entry => entry.description || '') + ) + for (const event of events) { + telemetryService.log(event) + } + } + }, [results, telemetryService]) + useNotepad( useMemo( () => diff --git a/client/web/src/search/suggestion/LuckySearch.tsx b/client/web/src/search/suggestion/LuckySearch.tsx index c0cea4b8067..72c468760c0 100644 --- a/client/web/src/search/suggestion/LuckySearch.tsx +++ b/client/web/src/search/suggestion/LuckySearch.tsx @@ -49,3 +49,28 @@ export const LuckySearch: React.FunctionComponent ) + +export const luckySearchEvent = (alertTitle: string, descriptions: string[]): string[] => { + const rules = descriptions.map(entry => { + if (entry.match(/patterns as regular expressions/)) { + return 'Regexp' + } + if (entry.match(/unquote patterns/)) { + return 'Unquote' + } + if (entry.match(/AND patterns together/)) { + return 'And' + } + return 'Other' + }) + + const prefix = alertTitle.match(/No results for original query/) + ? 'SearchResultsAutoPure' + : 'SearchResultsAutoAdded' + + const events = [] + for (const rule of rules) { + events.push(`${prefix}${rule}`) + } + return events +}