Browse Source

chore(analytics): convert analytics for guide events (#37839)

Stephen Cefali 2 years ago
parent
commit
98d98979ca

+ 7 - 16
static/app/actionCreators/guides.tsx

@@ -3,7 +3,7 @@ import * as Sentry from '@sentry/react';
 import {Client} from 'sentry/api';
 import ConfigStore from 'sentry/stores/configStore';
 import GuideStore from 'sentry/stores/guideStore';
-import {trackAnalyticsEvent} from 'sentry/utils/analytics';
+import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
 
 const api = new Client();
 
@@ -61,14 +61,10 @@ export function recordFinish(guide: string, orgId: string | null) {
     return;
   }
 
-  const data = {
-    eventKey: 'assistant.guide_finished',
-    eventName: 'Assistant Guide Finished',
+  trackAdvancedAnalyticsEvent('assistant.guide_finished', {
+    organization: orgId,
     guide,
-    organization_id: orgId,
-    user_id: parseInt(user.id, 10),
-  };
-  trackAnalyticsEvent(data);
+  });
 }
 
 export function recordDismiss(guide: string, step: number, orgId: string | null) {
@@ -84,14 +80,9 @@ export function recordDismiss(guide: string, step: number, orgId: string | null)
   if (!user) {
     return;
   }
-
-  const data = {
-    eventKey: 'assistant.guide_dismissed',
-    eventName: 'Assistant Guide Dismissed',
+  trackAdvancedAnalyticsEvent('assistant.guide_dismissed', {
+    organization: orgId,
     guide,
     step,
-    organization_id: orgId,
-    user_id: parseInt(user.id, 10),
-  };
-  trackAnalyticsEvent(data);
+  });
 }

+ 4 - 8
static/app/stores/guideStore.tsx

@@ -7,7 +7,7 @@ import {Guide, GuidesContent, GuidesServerData} from 'sentry/components/assistan
 import {IS_ACCEPTANCE_TEST} from 'sentry/constants';
 import ConfigStore from 'sentry/stores/configStore';
 import HookStore from 'sentry/stores/hookStore';
-import {trackAnalyticsEvent} from 'sentry/utils/analytics';
+import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
 import {
   cleanupActiveRefluxSubscriptions,
   makeSafeRefluxStore,
@@ -196,14 +196,10 @@ const storeConfig: GuideStoreDefinition = {
       return;
     }
 
-    const data = {
+    trackAdvancedAnalyticsEvent('assistant.guide_cued', {
+      organization: this.state.orgId,
       guide,
-      eventKey: 'assistant.guide_cued',
-      eventName: 'Assistant Guide Cued',
-      organization_id: this.state.orgId,
-      user_id: parseInt(user.id, 10),
-    };
-    trackAnalyticsEvent(data);
+    });
   },
 
   updatePrevGuide(nextGuide) {

+ 13 - 0
static/app/utils/analytics/growthAnalyticsEvents.tsx

@@ -58,6 +58,16 @@ type VitalsAlert = {
 
 // define the event key to payload mappings
 export type GrowthEventParameters = {
+  'assistant.guide_cued': {
+    guide: string;
+  };
+  'assistant.guide_dismissed': {
+    guide: string;
+    step: number;
+  };
+  'assistant.guide_finished': {
+    guide: string;
+  };
   'growth.clicked_enter_sandbox': {
     scenario: string;
     source?: string;
@@ -153,6 +163,8 @@ export type GrowthEventParameters = {
 type GrowthAnalyticsKey = keyof GrowthEventParameters;
 
 export const growthEventMap: Record<GrowthAnalyticsKey, string | null> = {
+  'assistant.guide_finished': 'Assistant Guide Finished',
+  'assistant.guide_dismissed': 'Assistant Guide Dismissed',
   'growth.clicked_mobile_prompt_setup_project':
     'Growth: Clicked Mobile Prompt Setup Project',
   'growth.clicked_mobile_prompt_ask_teammate':
@@ -216,4 +228,5 @@ export const growthEventMap: Record<GrowthAnalyticsKey, string | null> = {
   'growth.onboarding_wizard_clicked_more_details':
     'Onboarding Wizard: Clicked More Details',
   'growth.onboarding_wizard_interacted': 'Onboarding Wizard: Interacted',
+  'assistant.guide_cued': 'Assistant Guide Cued',
 };

+ 5 - 8
tests/js/spec/stores/guideStore.spec.jsx

@@ -1,8 +1,8 @@
 import ConfigStore from 'sentry/stores/configStore';
 import GuideStore from 'sentry/stores/guideStore';
-import {trackAnalyticsEvent} from 'sentry/utils/analytics';
+import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
 
-jest.mock('sentry/utils/analytics');
+jest.mock('sentry/utils/analytics/trackAdvancedAnalyticsEvent');
 
 describe('GuideStore', function () {
   let data;
@@ -13,7 +13,7 @@ describe('GuideStore', function () {
   };
 
   beforeEach(function () {
-    trackAnalyticsEvent.mockClear();
+    trackAdvancedAnalyticsEvent.mockClear();
     ConfigStore.config = {
       user,
     };
@@ -96,12 +96,9 @@ describe('GuideStore', function () {
     GuideStore.fetchSucceeded(data);
     expect(spy).toHaveBeenCalledWith('issue');
 
-    expect(trackAnalyticsEvent).toHaveBeenCalledWith({
+    expect(trackAdvancedAnalyticsEvent).toHaveBeenCalledWith('assistant.guide_cued', {
       guide: 'issue',
-      eventKey: 'assistant.guide_cued',
-      eventName: 'Assistant Guide Cued',
-      organization_id: null,
-      user_id: parseInt(user.id, 10),
+      organization: null,
     });
 
     expect(spy).toHaveBeenCalledTimes(1);