useHasDataTrackAnalytics.tsx 987 B

123456789101112131415161718192021222324252627
  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.withScope(scope => {
  13. scope.setTag(`insights.${module}.hasEverSentData`, hasEverSentData);
  14. });
  15. const projects = JSON.stringify(pageFilters.selection.projects);
  16. useEffect(() => {
  17. trackAnalytics(analyticEvent, {
  18. organization,
  19. has_ever_sent_data: hasEverSentData,
  20. });
  21. }, [organization, hasEverSentData, analyticEvent, projects]);
  22. }