search: log lucky search events (#39329)

This commit is contained in:
Rijnard van Tonder 2022-07-25 12:18:33 -07:00 committed by GitHub
parent 98c48b28cf
commit 8a5ec31d24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 1 deletions

View File

@ -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(
() =>

View File

@ -49,3 +49,28 @@ export const LuckySearch: React.FunctionComponent<React.PropsWithChildren<LuckyS
</ul>
</div>
)
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
}