useHasDataTrackAnalytics.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031
  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 {useDomainViewFilters} from 'sentry/views/insights/pages/useFilters';
  8. import type {ModuleName} from 'sentry/views/insights/types';
  9. export function useHasDataTrackAnalytics(module: ModuleName, analyticEvent?: string) {
  10. const organization = useOrganization();
  11. const pageFilters = usePageFilters();
  12. const view = useDomainViewFilters();
  13. const hasEverSentData = useHasFirstSpan(module);
  14. Sentry.setTag(`insights.${module}.hasEverSentData`, hasEverSentData);
  15. const projects = JSON.stringify(pageFilters.selection.projects);
  16. useEffect(() => {
  17. if (pageFilters.isReady && analyticEvent) {
  18. trackAnalytics(analyticEvent, {
  19. organization,
  20. has_ever_sent_data: hasEverSentData,
  21. ...(view ? {view} : {}),
  22. });
  23. }
  24. }, [organization, hasEverSentData, analyticEvent, projects, pageFilters.isReady, view]);
  25. }