useHasDataTrackAnalytics.tsx 1.0 KB

12345678910111213141516171819202122232425262728
  1. import {useEffect} from 'react';
  2. import * as Sentry from '@sentry/react';
  3. import {trackAnalytics} from 'sentry/utils/analytics';
  4. import useOrganization from 'sentry/utils/useOrganization';
  5. import usePageFilters from 'sentry/utils/usePageFilters';
  6. import {useHasFirstSpan} from 'sentry/views/insights/common/queries/useHasFirstSpan';
  7. import type {ModuleName} from 'sentry/views/insights/types';
  8. export function useHasDataTrackAnalytics(module: ModuleName, analyticEvent?: string) {
  9. const organization = useOrganization();
  10. const pageFilters = usePageFilters();
  11. const hasEverSentData = useHasFirstSpan(module);
  12. Sentry.setTag(`insights.${module}.hasEverSentData`, hasEverSentData);
  13. const projects = JSON.stringify(pageFilters.selection.projects);
  14. useEffect(() => {
  15. if (pageFilters.isReady && analyticEvent) {
  16. trackAnalytics(analyticEvent, {
  17. organization,
  18. has_ever_sent_data: hasEverSentData,
  19. });
  20. }
  21. }, [organization, hasEverSentData, analyticEvent, projects, pageFilters.isReady]);
  22. }