Browse Source

feat(ecosystem): Move stacktrace analytics to match others (#47551)

Scott Cooper 1 year ago
parent
commit
483fe35ded

+ 2 - 2
static/app/components/events/interfaces/frame/stacktraceLink.spec.tsx

@@ -3,7 +3,7 @@ import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrar
 import HookStore from 'sentry/stores/hookStore';
 import ProjectsStore from 'sentry/stores/projectsStore';
 import {CodecovStatusCode, Frame} from 'sentry/types';
-import * as analytics from 'sentry/utils/integrationUtil';
+import * as analytics from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
 
 import {StacktraceLink} from './stacktraceLink';
 
@@ -23,7 +23,7 @@ describe('StacktraceLink', function () {
   const config = TestStubs.RepositoryProjectPathConfig({project, repo, integration});
   let promptActivity: jest.Mock;
 
-  const analyticsSpy = jest.spyOn(analytics, 'trackIntegrationAnalytics');
+  const analyticsSpy = jest.spyOn(analytics, 'default');
 
   beforeEach(function () {
     jest.clearAllMocks();

+ 10 - 11
static/app/components/events/interfaces/frame/stacktraceLink.tsx

@@ -27,12 +27,9 @@ import {
   StacktraceLinkResult,
 } from 'sentry/types';
 import {defined} from 'sentry/utils';
-import {StacktraceLinkEvents} from 'sentry/utils/analytics/integrations/stacktraceLinkAnalyticsEvents';
+import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
 import {getAnalyticsDataForEvent} from 'sentry/utils/events';
-import {
-  getIntegrationIcon,
-  trackIntegrationAnalytics,
-} from 'sentry/utils/integrationUtil';
+import {getIntegrationIcon} from 'sentry/utils/integrationUtil';
 import {promptIsDismissed} from 'sentry/utils/promptIsDismissed';
 import {useQueryClient} from 'sentry/utils/queryClient';
 import useRouteAnalyticsParams from 'sentry/utils/routeAnalytics/useRouteAnalyticsParams';
@@ -92,7 +89,7 @@ function StacktraceLinkSetup({organization, project, event}: StacktraceLinkSetup
       }
     );
 
-    trackIntegrationAnalytics(StacktraceLinkEvents.DISMISS_CTA, {
+    trackAdvancedAnalyticsEvent('integrations.stacktrace_link_cta_dismissed', {
       view: 'stacktrace_issue_details',
       organization,
       ...getAnalyticsDataForEvent(event),
@@ -161,7 +158,7 @@ function CodecovLink({
   }
 
   const onOpenCodecovLink = () => {
-    trackIntegrationAnalytics(StacktraceLinkEvents.CODECOV_LINK_CLICKED, {
+    trackAdvancedAnalyticsEvent('integrations.stacktrace_codecov_link_clicked', {
       view: 'stacktrace_issue_details',
       organization,
       group_id: event.groupID ? parseInt(event.groupID, 10) : -1,
@@ -240,8 +237,8 @@ export function StacktraceLink({frame, event, line}: StacktraceLinkProps) {
   const onOpenLink = () => {
     const provider = match!.config?.provider;
     if (provider) {
-      trackIntegrationAnalytics(
-        StacktraceLinkEvents.OPEN_LINK,
+      trackAdvancedAnalyticsEvent(
+        'integrations.stacktrace_link_clicked',
         {
           view: 'stacktrace_issue_details',
           provider: provider.key,
@@ -322,11 +319,13 @@ export function StacktraceLink({frame, event, line}: StacktraceLinkProps) {
               : undefined
           }
           onClick={() => {
-            trackIntegrationAnalytics(
-              StacktraceLinkEvents.START_SETUP,
+            trackAdvancedAnalyticsEvent(
+              'integrations.stacktrace_start_setup',
               {
                 view: 'stacktrace_issue_details',
                 platform: event.platform,
+                provider: sourceCodeProviders[0]?.provider.key,
+                setup_type: 'automatic',
                 organization,
                 ...getAnalyticsDataForEvent(event),
               },

+ 2 - 4
static/app/components/events/interfaces/frame/stacktraceLinkModal.spec.tsx

@@ -8,9 +8,7 @@ import {
 
 import {openModal} from 'sentry/actionCreators/modal';
 import StacktraceLinkModal from 'sentry/components/events/interfaces/frame/stacktraceLinkModal';
-import * as analytics from 'sentry/utils/integrationUtil';
-
-jest.mock('sentry/utils/analytics/trackAdvancedAnalyticsEvent');
+import * as analytics from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
 
 describe('StacktraceLinkModal', () => {
   const org = TestStubs.Organization();
@@ -29,7 +27,7 @@ describe('StacktraceLinkModal', () => {
   };
   const onSubmit = jest.fn();
   const closeModal = jest.fn();
-  const analyticsSpy = jest.spyOn(analytics, 'trackIntegrationAnalytics');
+  const analyticsSpy = jest.spyOn(analytics, 'default');
 
   beforeEach(() => {
     MockApiClient.addMockResponse({

+ 5 - 4
static/app/components/events/interfaces/frame/stacktraceLinkModal.tsx

@@ -17,7 +17,7 @@ import {IconCopy} from 'sentry/icons';
 import {t, tct} from 'sentry/locale';
 import {space} from 'sentry/styles/space';
 import type {Integration, Organization, Project} from 'sentry/types';
-import {trackIntegrationAnalytics} from 'sentry/utils/integrationUtil';
+import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
 import {useApiQuery} from 'sentry/utils/queryClient';
 import useApi from 'sentry/utils/useApi';
 
@@ -93,7 +93,7 @@ function StacktraceLinkModal({
     : t('source code');
 
   const onManualSetup = () => {
-    trackIntegrationAnalytics('integrations.stacktrace_manual_option_clicked', {
+    trackAdvancedAnalyticsEvent('integrations.stacktrace_manual_option_clicked', {
       view: 'stacktrace_issue_details',
       setup_type: 'manual',
       provider:
@@ -105,9 +105,10 @@ function StacktraceLinkModal({
   };
 
   const handleSubmit = async () => {
-    trackIntegrationAnalytics('integrations.stacktrace_submit_config', {
+    trackAdvancedAnalyticsEvent('integrations.stacktrace_submit_config', {
       setup_type: 'automatic',
       view: 'stacktrace_issue_details',
+      provider: sourceCodeProviders[0]?.provider.name ?? 'unknown',
       organization,
     });
     const parsingEndpoint = `/projects/${organization.slug}/${project.slug}/repo-path-parsing/`;
@@ -131,7 +132,7 @@ function StacktraceLinkModal({
       });
 
       addSuccessMessage(t('Stack trace configuration saved.'));
-      trackIntegrationAnalytics('integrations.stacktrace_complete_setup', {
+      trackAdvancedAnalyticsEvent('integrations.stacktrace_complete_setup', {
         setup_type: 'automatic',
         provider: configData.config?.provider.key,
         view: 'stacktrace_issue_details',

+ 63 - 0
static/app/utils/analytics/ecosystemAnalyticsEvents.tsx

@@ -0,0 +1,63 @@
+import type {PlatformType} from 'sentry/types';
+import type {BaseEventAnalyticsParams} from 'sentry/utils/analytics/workflowAnalyticsEvents';
+
+type SetupType = 'automatic' | 'manual';
+type StackTraceView = 'stacktrace_issue_details' | 'integration_configuration_detail';
+
+export type EcosystemEventParameters = {
+  'integrations.stacktrace_codecov_link_clicked': {
+    group_id: number;
+    view: StackTraceView;
+  } & BaseEventAnalyticsParams;
+  'integrations.stacktrace_complete_setup': {
+    provider: string;
+    setup_type: SetupType;
+    view: StackTraceView;
+    is_suggestion?: boolean;
+  };
+  'integrations.stacktrace_docs_clicked': {
+    provider: string;
+    view: StackTraceView;
+  };
+  'integrations.stacktrace_link_clicked': {
+    group_id: number;
+    provider: string;
+    view: StackTraceView;
+  } & BaseEventAnalyticsParams;
+  'integrations.stacktrace_link_cta_dismissed': {
+    view: StackTraceView;
+  } & BaseEventAnalyticsParams;
+  'integrations.stacktrace_manual_option_clicked': {
+    provider: string;
+    setup_type: SetupType;
+    view: StackTraceView;
+  };
+  'integrations.stacktrace_start_setup': {
+    provider: string;
+    setup_type: SetupType;
+    view: StackTraceView;
+    platform?: PlatformType;
+    // BaseEventAnalyticsParams partial because it is not always present
+  } & Partial<BaseEventAnalyticsParams>;
+  'integrations.stacktrace_submit_config': {
+    provider: string;
+    setup_type: SetupType;
+    view: StackTraceView;
+  };
+};
+
+type EcosystemEventKeys = keyof EcosystemEventParameters;
+
+export const ecosystemEventMap: Record<EcosystemEventKeys, string | null> = {
+  'integrations.stacktrace_complete_setup': 'Integrations: Stacktrace Complete Setup',
+  'integrations.stacktrace_docs_clicked': 'Integrations: Stacktrace Docs Clicked',
+  'integrations.stacktrace_link_clicked': 'Integrations: Stacktrace Link Clicked',
+  'integrations.stacktrace_link_cta_dismissed':
+    'Integrations: Stacktrace Link CTA Dismissed',
+  'integrations.stacktrace_manual_option_clicked':
+    'Integrations: Stacktrace Manual Option Clicked',
+  'integrations.stacktrace_start_setup': 'Integrations: Stacktrace Start Setup',
+  'integrations.stacktrace_submit_config': 'Integrations: Stacktrace Submit Config',
+  'integrations.stacktrace_codecov_link_clicked':
+    'Integrations: Stacktrace Codecov Link Clicked',
+};

+ 0 - 6
static/app/utils/analytics/integrations/index.ts

@@ -2,10 +2,6 @@ import {IntegrationType, SentryAppStatus} from 'sentry/types';
 
 import {codeownersEventMap, CodeownersEventParameters} from './codeownersAnalyticsEvents';
 import {platformEventMap, PlatformEventParameters} from './platformAnalyticsEvents';
-import {
-  stacktraceLinkEventMap,
-  StacktraceLinkEventParameters,
-} from './stacktraceLinkAnalyticsEvents';
 
 export type IntegrationView = {
   view?:
@@ -91,7 +87,6 @@ export type IntegrationEventParameters = {
   'project_ownership.modal_opened': ProjectOwnershipModalParams;
   'project_ownership.saved': ProjectOwnershipModalParams;
 } & CodeownersEventParameters &
-  StacktraceLinkEventParameters &
   PlatformEventParameters;
 
 export type IntegrationAnalyticsKey = keyof IntegrationEventParameters;
@@ -126,6 +121,5 @@ export const integrationEventMap: Record<IntegrationAnalyticsKey, string> = {
   'project_ownership.modal_opened': 'Project Ownership: Modal Opened',
   'project_ownership.saved': 'Project Ownership: Saved',
   ...codeownersEventMap,
-  ...stacktraceLinkEventMap,
   ...platformEventMap,
 };

+ 0 - 50
static/app/utils/analytics/integrations/stacktraceLinkAnalyticsEvents.ts

@@ -1,50 +0,0 @@
-import type {StacktraceErrorMessage} from 'sentry/types';
-import {PlatformType} from 'sentry/types';
-import {BaseEventAnalyticsParams} from 'sentry/utils/analytics/workflowAnalyticsEvents';
-
-import {IntegrationView} from './index';
-
-export enum StacktraceLinkEvents {
-  COMPLETE_SETUP = 'integrations.stacktrace_complete_setup',
-  OPEN_DOCS = 'integrations.stacktrace_docs_clicked',
-  OPEN_LINK = 'integrations.stacktrace_link_clicked',
-  DISMISS_CTA = 'integrations.stacktrace_link_cta_dismissed',
-  MANUAL_OPTION = 'integrations.stacktrace_manual_option_clicked',
-  START_SETUP = 'integrations.stacktrace_start_setup',
-  SUBMIT = 'integrations.stacktrace_submit_config',
-  CODECOV_LINK_CLICKED = 'integrations.stacktrace_codecov_link_clicked',
-  CODECOV_PROMPT_CLICKED = 'integrations.stacktrace_codecov_prompt_clicked',
-  CODECOV_PROMPT_DISMISSED = 'integrations.stacktrace_codecov_prompt_dismissed',
-}
-
-// This type allows analytics functions to use the string literal or enum.KEY
-type StacktraceLinkEventsLiterals = `${StacktraceLinkEvents}`;
-
-export type StacktraceLinkEventParameters = {
-  [key in StacktraceLinkEventsLiterals]: {
-    error_reason?: StacktraceErrorMessage;
-    is_suggestion?: boolean;
-    platform?: PlatformType;
-    project_id?: string;
-    provider?: string;
-    setup_type?: 'automatic' | 'manual';
-    state?: 'match' | 'no_match' | 'prompt' | 'empty';
-  } & IntegrationView &
-    Partial<BaseEventAnalyticsParams & {group_id?: number}>; // make optional
-};
-
-export const stacktraceLinkEventMap: Record<StacktraceLinkEventsLiterals, string> = {
-  [StacktraceLinkEvents.COMPLETE_SETUP]: 'Integrations: Stacktrace Complete Setup',
-  [StacktraceLinkEvents.OPEN_DOCS]: 'Integrations: Stacktrace Docs Clicked',
-  [StacktraceLinkEvents.OPEN_LINK]: 'Integrations: Stacktrace Link Clicked',
-  [StacktraceLinkEvents.DISMISS_CTA]: 'Integrations: Stacktrace Link CTA Dismissed',
-  [StacktraceLinkEvents.MANUAL_OPTION]: 'Integrations: Stacktrace Manual Option Clicked',
-  [StacktraceLinkEvents.START_SETUP]: 'Integrations: Stacktrace Start Setup',
-  [StacktraceLinkEvents.SUBMIT]: 'Integrations: Stacktrace Submit Config',
-  [StacktraceLinkEvents.CODECOV_LINK_CLICKED]:
-    'Integrations: Stacktrace Codecov Link Clicked',
-  [StacktraceLinkEvents.CODECOV_PROMPT_CLICKED]:
-    'Integrations: Stacktrace Codecov Prompt Clicked',
-  [StacktraceLinkEvents.CODECOV_PROMPT_DISMISSED]:
-    'Integrations: Stacktrace Codecov Prompt Dismissed',
-};

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

@@ -9,6 +9,7 @@ import {
   dynamicSamplingEventMap,
   DynamicSamplingEventParameters,
 } from './dynamicSamplingAnalyticsEvents';
+import {ecosystemEventMap, EcosystemEventParameters} from './ecosystemAnalyticsEvents';
 import {growthEventMap, GrowthEventParameters} from './growthAnalyticsEvents';
 import {integrationEventMap, IntegrationEventParameters} from './integrations';
 import {issueEventMap, IssueEventParameters} from './issueAnalyticsEvents';
@@ -44,6 +45,7 @@ type EventParameters = GrowthEventParameters &
   OnboardingEventParameters &
   StackTraceEventParameters &
   AiSuggestedSolutionEventParameters &
+  EcosystemEventParameters &
   IntegrationEventParameters;
 
 const allEventMap: Record<string, string | null> = {
@@ -64,6 +66,7 @@ const allEventMap: Record<string, string | null> = {
   ...onboardingEventMap,
   ...stackTraceEventMap,
   ...aiSuggestedSolutionEventMap,
+  ...ecosystemEventMap,
   ...integrationEventMap,
 };
 

+ 5 - 7
static/app/views/settings/organizationIntegrations/integrationCodeMappings.tsx

@@ -20,10 +20,8 @@ import {
   Repository,
   RepositoryProjectPathConfig,
 } from 'sentry/types';
-import {
-  getIntegrationIcon,
-  trackIntegrationAnalytics,
-} from 'sentry/utils/integrationUtil';
+import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
+import {getIntegrationIcon} from 'sentry/utils/integrationUtil';
 import withRouteAnalytics, {
   WithRouteAnalyticsProps,
 } from 'sentry/utils/routeAnalytics/withRouteAnalytics';
@@ -107,7 +105,7 @@ class IntegrationCodeMappings extends AsyncComponent<Props, State> {
   }
 
   trackDocsClick = () => {
-    trackIntegrationAnalytics('integrations.stacktrace_docs_clicked', {
+    trackAdvancedAnalyticsEvent('integrations.stacktrace_docs_clicked', {
       view: 'integration_configuration_detail',
       provider: this.props.integration.provider.key,
       organization: this.props.organization,
@@ -137,7 +135,7 @@ class IntegrationCodeMappings extends AsyncComponent<Props, State> {
   };
 
   handleSubmitSuccess = (pathConfig: RepositoryProjectPathConfig) => {
-    trackIntegrationAnalytics('integrations.stacktrace_complete_setup', {
+    trackAdvancedAnalyticsEvent('integrations.stacktrace_complete_setup', {
       setup_type: 'manual',
       view: 'integration_configuration_detail',
       provider: this.props.integration.provider.key,
@@ -153,7 +151,7 @@ class IntegrationCodeMappings extends AsyncComponent<Props, State> {
 
   openModal = (pathConfig?: RepositoryProjectPathConfig) => {
     const {organization, projects, integration} = this.props;
-    trackIntegrationAnalytics('integrations.stacktrace_start_setup', {
+    trackAdvancedAnalyticsEvent('integrations.stacktrace_start_setup', {
       setup_type: 'manual',
       view: 'integration_configuration_detail',
       provider: this.props.integration.provider.key,

+ 3 - 5
static/app/views/settings/organizationIntegrations/repositoryProjectPathConfigForm.tsx

@@ -14,10 +14,8 @@ import type {
   Repository,
   RepositoryProjectPathConfig,
 } from 'sentry/types';
-import {
-  sentryNameToOption,
-  trackIntegrationAnalytics,
-} from 'sentry/utils/integrationUtil';
+import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
+import {sentryNameToOption} from 'sentry/utils/integrationUtil';
 import useApi from 'sentry/utils/useApi';
 
 type Props = {
@@ -123,7 +121,7 @@ function RepositoryProjectPathConfigForm({
   ];
 
   function handlePreSubmit() {
-    trackIntegrationAnalytics('integrations.stacktrace_submit_config', {
+    trackAdvancedAnalyticsEvent('integrations.stacktrace_submit_config', {
       setup_type: 'manual',
       view: 'integration_configuration_detail',
       provider: integration.provider.key,