search-events.ts 914 B

123456789101112131415161718192021222324252627282930313233343536
  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. }
  19. 'search-result-click': {
  20. searchType: 'full-project'
  21. }
  22. 'search-replace-click': {
  23. searchType: 'document'
  24. method: 'keyboard' | 'button'
  25. action: 'replace' | 'replace-all'
  26. }
  27. }
  28. export const sendSearchEvent = <T extends keyof SearchEventSegmentation>(
  29. eventName: T,
  30. segmentation: SearchEventSegmentation[T]
  31. ) => {
  32. sendMB(eventName, segmentation)
  33. }