Browse Source

ref(analytics): convert more discover2 analytics (#47051)

Stephen Cefali 1 year ago
parent
commit
3bbd710de3

+ 12 - 0
static/app/utils/analytics/discoverAnalyticsEvents.tsx

@@ -28,7 +28,9 @@ export type DiscoverEventParameters = SaveQueryEventParameters & {
   'discover_v2.add_equation': {};
   'discover_v2.build_new_query': {};
   'discover_v2.change_sort': {sort: string};
+  'discover_v2.column_editor.open': {};
   'discover_v2.create_alert_clicked': {status: string};
+  'discover_v2.event_details': {event_type: EventOrGroupType};
   'discover_v2.facet_map.clicked': {tag: string};
   'discover_v2.prebuilt_query_click': {query_name?: string};
   'discover_v2.processed_baseline_toggle.clicked': {toggled: string};
@@ -40,6 +42,9 @@ export type DiscoverEventParameters = SaveQueryEventParameters & {
   };
   'discover_v2.quick_context_update_query': {queryKey: string};
   'discover_v2.remove_default': {source: 'homepage' | 'prebuilt-query' | 'saved-query'};
+  'discover_v2.results.cellaction': {action: string};
+  'discover_v2.results.download_csv': {};
+  'discover_v2.results.drilldown': {};
   'discover_v2.results.toggle_tag_facets': {};
   'discover_v2.save_existing_query_failed': SaveQueryParams & {error: string};
   'discover_v2.saved_query_click': {};
@@ -51,6 +56,7 @@ export type DiscoverEventParameters = SaveQueryEventParameters & {
   'discover_v2.tour.advance': {duration: number; step: number};
   'discover_v2.tour.close': {duration: number; step: number};
   'discover_v2.tour.start': {};
+  'discover_v2.update_columns': {};
   'discover_v2.view_saved_queries': {};
   'discover_v2.y_axis_change': {y_axis_value: string[]};
   'discover_views.add_to_dashboard.confirm': {};
@@ -105,4 +111,10 @@ export const discoverEventMap: Record<DiscoverEventKey, string | null> = {
   'discover_v2.delete_query_failed': 'Discoverv2: Failed to delete a saved query',
   'discover_v2.delete_query_request': 'Discoverv2: Request to delete a saved query',
   'discover_v2.create_alert_clicked': 'Discoverv2: Create alert clicked',
+  'discover_v2.event_details': 'Discoverv2: Opened Event Details',
+  'discover_v2.column_editor.open': 'Discoverv2: Open column editor',
+  'discover_v2.results.download_csv': 'Discoverv2: Download CSV',
+  'discover_v2.results.cellaction': 'Discoverv2: Cell Action Clicked',
+  'discover_v2.results.drilldown': 'Discoverv2: Click aggregate drilldown',
+  'discover_v2.update_columns': 'Discoverv2: Update columns',
 };

+ 2 - 5
static/app/views/discover/eventDetails/content.tsx

@@ -25,7 +25,6 @@ import {t} from 'sentry/locale';
 import {space} from 'sentry/styles/space';
 import {Organization, Project} from 'sentry/types';
 import {Event, EventTag} from 'sentry/types/event';
-import {trackAnalyticsEvent} from 'sentry/utils/analytics';
 import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
 import EventView from 'sentry/utils/discover/eventView';
 import {formatTagKey} from 'sentry/utils/discover/fields';
@@ -131,11 +130,9 @@ class EventDetailsContent extends AsyncComponent<Props, State> {
     const {isSidebarVisible} = this.state;
 
     // metrics
-    trackAnalyticsEvent({
-      eventKey: 'discover_v2.event_details',
-      eventName: 'Discoverv2: Opened Event Details',
+    trackAdvancedAnalyticsEvent('discover_v2.event_details', {
       event_type: event.type,
-      organization_id: parseInt(organization.id, 10),
+      organization,
     });
 
     const transactionName = event.tags.find(tag => tag.key === 'transaction')?.value;

+ 3 - 7
static/app/views/discover/table/columnEditModal.tsx

@@ -10,7 +10,7 @@ import {DISCOVER2_DOCS_URL} from 'sentry/constants';
 import {t, tct} from 'sentry/locale';
 import {space} from 'sentry/styles/space';
 import {Organization} from 'sentry/types';
-import {trackAnalyticsEvent} from 'sentry/utils/analytics';
+import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
 import {CustomMeasurementCollection} from 'sentry/utils/customMeasurements/customMeasurements';
 import {Column} from 'sentry/utils/discover/fields';
 import {FieldKey} from 'sentry/utils/fields';
@@ -45,12 +45,8 @@ function ColumnEditModal(props: Props) {
 
   // Only run once for each organization.id.
   useEffect(() => {
-    trackAnalyticsEvent({
-      eventKey: 'discover_v2.column_editor.open',
-      eventName: 'Discoverv2: Open column editor',
-      organization_id: parseInt(organization.id, 10),
-    });
-  }, [organization.id]);
+    trackAdvancedAnalyticsEvent('discover_v2.column_editor.open', {organization});
+  }, [organization]);
 
   const tags = useTags();
   const tagKeys = Object.keys(tags);

+ 3 - 5
static/app/views/discover/table/tableActions.tsx

@@ -10,7 +10,7 @@ import {Hovercard} from 'sentry/components/hovercard';
 import {IconDownload, IconStack, IconTag} from 'sentry/icons';
 import {t} from 'sentry/locale';
 import {OrganizationSummary} from 'sentry/types';
-import {trackAnalyticsEvent} from 'sentry/utils/analytics';
+import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
 import {TableData} from 'sentry/utils/discover/discoverQuery';
 import EventView from 'sentry/utils/discover/eventView';
 
@@ -30,10 +30,8 @@ type Props = {
 };
 
 function handleDownloadAsCsv(title: string, {organization, eventView, tableData}: Props) {
-  trackAnalyticsEvent({
-    eventKey: 'discover_v2.results.download_csv',
-    eventName: 'Discoverv2: Download CSV',
-    organization_id: parseInt(organization.id, 10),
+  trackAdvancedAnalyticsEvent('discover_v2.results.download_csv', {
+    organization: organization.id, // org summary
   });
   downloadAsCsv(tableData, eventView.getColumns(), title);
 }

+ 6 - 15
static/app/views/discover/table/tableView.tsx

@@ -18,7 +18,6 @@ import {IconStack} from 'sentry/icons';
 import {t} from 'sentry/locale';
 import {Organization} from 'sentry/types';
 import {defined} from 'sentry/utils';
-import {trackAnalyticsEvent} from 'sentry/utils/analytics';
 import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
 import {CustomMeasurementCollection} from 'sentry/utils/customMeasurements/customMeasurements';
 import {TableData, TableDataRow} from 'sentry/utils/discover/discoverQuery';
@@ -459,11 +458,8 @@ function TableView(props: TableViewProps) {
       const query = new MutableSearch(eventView.query);
 
       let nextView = eventView.clone();
-
-      trackAnalyticsEvent({
-        eventKey: 'discover_v2.results.cellaction',
-        eventName: 'Discoverv2: Cell Action Clicked',
-        organization_id: parseInt(organization.id, 10),
+      trackAdvancedAnalyticsEvent('discover_v2.results.cellaction', {
+        organization,
         action,
       });
 
@@ -508,11 +504,8 @@ function TableView(props: TableViewProps) {
         }
         case Actions.DRILLDOWN: {
           // count_unique(column) drilldown
-
-          trackAnalyticsEvent({
-            eventKey: 'discover_v2.results.drilldown',
-            eventName: 'Discoverv2: Click aggregate drilldown',
-            organization_id: parseInt(organization.id, 10),
+          trackAdvancedAnalyticsEvent('discover_v2.results.drilldown', {
+            organization,
           });
 
           // Drilldown into each distinct value and get a count() for each value.
@@ -555,10 +548,8 @@ function TableView(props: TableViewProps) {
     const {organization, eventView, location, isHomepage} = props;
 
     // metrics
-    trackAnalyticsEvent({
-      eventKey: 'discover_v2.update_columns',
-      eventName: 'Discoverv2: Update columns',
-      organization_id: parseInt(organization.id, 10),
+    trackAdvancedAnalyticsEvent('discover_v2.update_columns', {
+      organization,
     });
 
     const nextView = eventView.withColumns(columns);