search-events.ts 948 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import { sendMB } from '@/infrastructure/event-tracking'
  2. type SearchEventSegmentation = {
  3. 'search-open':
  4. | ({
  5. searchType: 'full-project'
  6. } & (
  7. | { method: 'keyboard' }
  8. | { method: 'button'; location: 'toolbar' | 'search-form' | 'rail' }
  9. ))
  10. | ({
  11. searchType: 'document'
  12. mode: 'visual' | 'source'
  13. } & ({ method: 'keyboard' } | { method: 'button'; location: 'toolbar' }))
  14. 'search-execute': {
  15. searchType: 'full-project'
  16. totalDocs: number
  17. totalResults: number
  18. 'editor-redesign'?: 'enabled'
  19. }
  20. 'search-result-click': {
  21. searchType: 'full-project'
  22. }
  23. 'search-replace-click': {
  24. searchType: 'document'
  25. method: 'keyboard' | 'button'
  26. action: 'replace' | 'replace-all'
  27. }
  28. }
  29. export const sendSearchEvent = <T extends keyof SearchEventSegmentation>(
  30. eventName: T,
  31. segmentation: SearchEventSegmentation[T]
  32. ) => {
  33. sendMB(eventName, segmentation)
  34. }