useHasDataTrackAnalytics.tsx 836 B

12345678910111213141516171819202122
  1. import {useEffect} from 'react';
  2. import {trackAnalytics} from 'sentry/utils/analytics';
  3. import useOrganization from 'sentry/utils/useOrganization';
  4. import usePageFilters from 'sentry/utils/usePageFilters';
  5. import {useHasFirstSpan} from 'sentry/views/insights/common/queries/useHasFirstSpan';
  6. import type {ModuleName} from 'sentry/views/insights/types';
  7. export function useHasDataTrackAnalytics(module: ModuleName, analyticEvent: string) {
  8. const organization = useOrganization();
  9. const pageFilters = usePageFilters();
  10. const hasEverSentData = useHasFirstSpan(module);
  11. const projects = JSON.stringify(pageFilters.selection.projects);
  12. useEffect(() => {
  13. trackAnalytics(analyticEvent, {
  14. organization,
  15. has_ever_sent_data: hasEverSentData,
  16. });
  17. }, [organization, hasEverSentData, analyticEvent, projects]);
  18. }