Browse Source

feat(codecov): Add analytics event for codecovAccess setting (#43419)

Track when users enable/disable the codecovAccess setting.
Snigdha Sharma 2 years ago
parent
commit
a93dbc0ef0

+ 3 - 0
static/app/utils/analytics/settingsAnalyticsEvents.tsx

@@ -7,6 +7,7 @@ export type SettingsEventParameters = {
     notification_type: string;
     tuning_field_type: string;
   };
+  'organization_settings.codecov_access_updated': {has_access: boolean};
 };
 
 export type SettingsEventKey = keyof SettingsEventParameters;
@@ -16,4 +17,6 @@ export const settingsEventMap: Record<SettingsEventKey, string | null> = {
   'notification_settings.tuning_page_viewed': 'Notification Settings: Tuning Page Viewed',
   'notification_settings.updated_tuning_setting':
     'Notification Settings: Updated Tuning Setting',
+  'organization_settings.codecov_access_updated':
+    'Organization Settings: Codecov Access Updated',
 };

+ 6 - 0
static/app/views/settings/organizationGeneralSettings/index.spec.tsx

@@ -13,8 +13,11 @@ import {
 
 import OrganizationsStore from 'sentry/stores/organizationsStore';
 import ProjectsStore from 'sentry/stores/projectsStore';
+import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
 import OrganizationGeneralSettings from 'sentry/views/settings/organizationGeneralSettings';
 
+jest.mock('sentry/utils/analytics/trackAdvancedAnalyticsEvent');
+
 describe('OrganizationGeneralSettings', function () {
   const ENDPOINT = '/organizations/org-slug/';
   const {organization, router} = initializeOrg();
@@ -58,6 +61,7 @@ describe('OrganizationGeneralSettings', function () {
 
   it('can enable "codecov access"', async function () {
     defaultProps.organization.features.push('codecov-stacktrace-integration');
+    organization.codecovAccess = false;
     render(<OrganizationGeneralSettings {...defaultProps} />);
     const mock = MockApiClient.addMockResponse({
       url: ENDPOINT,
@@ -74,6 +78,8 @@ describe('OrganizationGeneralSettings', function () {
         })
       );
     });
+
+    expect(trackAdvancedAnalyticsEvent).toHaveBeenCalled();
   });
 
   it('changes org slug and redirects to new slug', async function () {

+ 8 - 0
static/app/views/settings/organizationGeneralSettings/index.tsx

@@ -16,6 +16,7 @@ import {Panel, PanelHeader} from 'sentry/components/panels';
 import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
 import {t, tct} from 'sentry/locale';
 import {Organization, Project} from 'sentry/types';
+import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
 import useApi from 'sentry/utils/useApi';
 import withOrganization from 'sentry/utils/withOrganization';
 import withProjects from 'sentry/utils/withProjects';
@@ -77,6 +78,13 @@ function OrganizationGeneralSettings(props: Props) {
     } else {
       // This will update OrganizationStore (as well as OrganizationsStore
       // which is slightly incorrect because it has summaries vs a detailed org)
+      if (prevData.codecovAccess !== updated.codecovAccess) {
+        trackAdvancedAnalyticsEvent('organization_settings.codecov_access_updated', {
+          organization: updated,
+          has_access: updated.codecovAccess,
+        });
+      }
+
       updateOrganization(updated);
     }
   };