trackMarketingEvent.tsx 731 B

123456789101112131415161718192021222324252627282930313233
  1. import ConfigStore from 'sentry/stores/configStore';
  2. function trackMarketingEvent(
  3. event_type: string,
  4. options?: {event_label?: string; plan?: string}
  5. ) {
  6. // quit early if analytics is disabled
  7. if (!ConfigStore.get('enableAnalytics')) {
  8. return;
  9. }
  10. // Google
  11. window.ga =
  12. window.ga ||
  13. function (...args: any[]) {
  14. (window.ga.q = window.ga.q || []).push(args);
  15. };
  16. window.ga.l = +new Date();
  17. window.ga('send', {
  18. hitType: 'event',
  19. eventCategory: 'User',
  20. eventAction: event_type,
  21. eventLabel: options?.event_label,
  22. });
  23. // GA4
  24. window.gtag?.('event', event_type, {
  25. event_category: 'User',
  26. event_label: options?.event_label,
  27. });
  28. }
  29. export default trackMarketingEvent;