Browse Source

feat(priority-alerts): Add analytic event for alert rule row deleted (#72280)

Add an analytic event `edit_alert_rule.delete_row` to track when rows
are deleted from an alert rule in the edit view. This will help us track
how often users remove the new high priority alert conditions.
Snigdha Sharma 9 months ago
parent
commit
1a1dc47460

+ 6 - 0
static/app/utils/analytics/workflowAnalyticsEvents.tsx

@@ -73,6 +73,11 @@ export type TeamInsightsEventParameters = {
     project_id: string;
     type: string;
   };
+  'edit_alert_rule.delete_row': {
+    name: string;
+    project_id: string;
+    type: string;
+  };
   'edit_alert_rule.incompatible_rule': {};
   'edit_alert_rule.notification_test': {success: boolean};
   'edit_alert_rule.viewed': RuleViewed;
@@ -166,6 +171,7 @@ export const workflowEventMap: Record<TeamInsightsEventKey, string | null> = {
   'alert_stream.viewed': 'Alert Stream: Viewed',
   'alert_wizard.option_selected': 'Alert Wizard: Option Selected',
   'edit_alert_rule.add_row': 'Edit Alert Rule: Add Row',
+  'edit_alert_rule.delete_row': 'Edit Alert Rule: Delete Row',
   'edit_alert_rule.viewed': 'Edit Alert Rule: Viewed',
   'edit_alert_rule.incompatible_rule': 'Edit Alert Rule: Incompatible Rule',
   'edit_alert_rule.notification_test': 'Edit Alert Rule: Notification Test',

+ 9 - 0
static/app/views/alerts/create.spec.tsx

@@ -218,6 +218,15 @@ describe('ProjectAlertsCreate', function () {
         });
       });
 
+      await waitFor(() => {
+        expect(trackAnalytics).toHaveBeenCalledWith('edit_alert_rule.delete_row', {
+          name: 'sentry.rules.conditions.first_seen_event.FirstSeenEventCondition',
+          organization,
+          project_id: '2',
+          type: 'conditions',
+        });
+      });
+
       await userEvent.click(screen.getByText('Save Rule'));
 
       await waitFor(() => {

+ 10 - 0
static/app/views/alerts/rules/issue/index.tsx

@@ -731,6 +731,16 @@ class IssueRuleEditor extends DeprecatedAsyncView<Props, State> {
       newTypeList.splice(idx, 1);
 
       set(clonedState, `rule[${type}]`, newTypeList);
+
+      const {organization} = this.props;
+      const {project} = this.state;
+      const deletedItem = prevState.rule ? prevState.rule[type][idx] : null;
+      trackAnalytics('edit_alert_rule.delete_row', {
+        organization,
+        project_id: project.id,
+        type,
+        name: deletedItem?.id ?? '',
+      });
       return clonedState;
     });
   };