From c67bafbd5ad6fe408a35a4153aa1a9d7f927d6dd Mon Sep 17 00:00:00 2001 From: Virginia Cepeda Date: Wed, 10 May 2023 13:26:57 -0300 Subject: [PATCH] Alerting: Survey changes (#68043) * Track alert rule list navigation * Change min user creation date to 7 days * Fix tests --- .../features/alerting/unified/Analytics.test.ts | 5 +++-- .../app/features/alerting/unified/Analytics.ts | 17 ++++++++++++++++- .../app/features/alerting/unified/RuleList.tsx | 3 ++- .../components/rule-editor/AlertRuleForm.tsx | 9 +-------- .../features/alerting/unified/state/actions.ts | 13 ++----------- 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/public/app/features/alerting/unified/Analytics.test.ts b/public/app/features/alerting/unified/Analytics.test.ts index bea69a3ade4..e6223fc4292 100644 --- a/public/app/features/alerting/unified/Analytics.test.ts +++ b/public/app/features/alerting/unified/Analytics.test.ts @@ -4,16 +4,17 @@ import { getBackendSrv } from '@grafana/runtime'; import { isNewUser, USER_CREATION_MIN_DAYS } from './Analytics'; jest.mock('@grafana/runtime', () => ({ + ...jest.requireActual('@grafana/runtime'), getBackendSrv: jest.fn().mockReturnValue({ get: jest.fn(), }), })); describe('isNewUser', function () { - it('should return true if the user has been created within the last two weeks', async () => { + it('should return true if the user has been created within the last week', async () => { const newUser = { id: 1, - createdAt: dateTime().subtract(14, 'days'), + createdAt: dateTime().subtract(6, 'days'), }; getBackendSrv().get = jest.fn().mockResolvedValue(newUser); diff --git a/public/app/features/alerting/unified/Analytics.ts b/public/app/features/alerting/unified/Analytics.ts index 8ce2236f361..fd12ddf6c6e 100644 --- a/public/app/features/alerting/unified/Analytics.ts +++ b/public/app/features/alerting/unified/Analytics.ts @@ -2,8 +2,9 @@ import { dateTime } from '@grafana/data'; import { faro, LogLevel as GrafanaLogLevel } from '@grafana/faro-web-sdk'; import { getBackendSrv } from '@grafana/runtime'; import { config, reportInteraction } from '@grafana/runtime/src'; +import { contextSrv } from 'app/core/core'; -export const USER_CREATION_MIN_DAYS = 15; +export const USER_CREATION_MIN_DAYS = 7; export const LogMessages = { filterByLabel: 'filtering alert instances by label', @@ -60,6 +61,20 @@ export async function isNewUser() { } } +export const trackRuleListNavigation = async ( + props: AlertRuleTrackingProps = { + grafana_version: config.buildInfo.version, + org_id: contextSrv.user.orgId, + user_id: contextSrv.user.id, + } +) => { + const isNew = await isNewUser(); + if (isNew) { + return; + } + reportInteraction('grafana_alerting_navigation', props); +}; + export const trackNewAlerRuleFormSaved = async (props: AlertRuleTrackingProps) => { const isNew = await isNewUser(); if (isNew) { diff --git a/public/app/features/alerting/unified/RuleList.tsx b/public/app/features/alerting/unified/RuleList.tsx index 7baeadeeb44..946c06bb913 100644 --- a/public/app/features/alerting/unified/RuleList.tsx +++ b/public/app/features/alerting/unified/RuleList.tsx @@ -12,7 +12,7 @@ import { useDispatch } from 'app/types'; import { CombinedRuleNamespace } from '../../../types/unified-alerting'; -import { LogMessages } from './Analytics'; +import { LogMessages, trackRuleListNavigation } from './Analytics'; import { AlertingPageWrapper } from './components/AlertingPageWrapper'; import { NoRulesSplash } from './components/rules/NoRulesCTA'; import { INSTANCES_DISPLAY_LIMIT } from './components/rules/RuleDetails'; @@ -76,6 +76,7 @@ const RuleList = withErrorBoundary( // Trigger data refresh only when the RULE_LIST_POLL_INTERVAL_MS elapsed since the previous load FINISHED const [_, fetchRules] = useAsyncFn(async () => { if (!loading) { + trackRuleListNavigation(); await dispatch(fetchAllPromAndRulerRulesAction(false, { limitAlerts })); } }, [loading, limitAlerts, dispatch]); diff --git a/public/app/features/alerting/unified/components/rule-editor/AlertRuleForm.tsx b/public/app/features/alerting/unified/components/rule-editor/AlertRuleForm.tsx index 42428c584b8..aee899e9964 100644 --- a/public/app/features/alerting/unified/components/rule-editor/AlertRuleForm.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/AlertRuleForm.tsx @@ -13,7 +13,7 @@ import { useQueryParams } from 'app/core/hooks/useQueryParams'; import { useDispatch } from 'app/types'; import { RuleWithLocation } from 'app/types/unified-alerting'; -import { LogMessages, trackNewAlerRuleFormCancelled, trackNewAlerRuleFormError } from '../../Analytics'; +import { LogMessages, trackNewAlerRuleFormError } from '../../Analytics'; import { useUnifiedAlertingSelector } from '../../hooks/useUnifiedAlertingSelector'; import { deleteRuleAction, saveRuleFormAction } from '../../state/actions'; import { RuleFormType, RuleFormValues } from '../../types/rule-form'; @@ -183,13 +183,6 @@ export const AlertRuleForm = ({ existing, prefill }: Props) => { const cancelRuleCreation = () => { logInfo(LogMessages.cancelSavingAlertRule); - if (!existing) { - trackNewAlerRuleFormCancelled({ - grafana_version: config.buildInfo.version, - org_id: contextSrv.user.orgId, - user_id: contextSrv.user.id, - }); - } }; const evaluateEveryInForm = watch('evaluateEvery'); useEffect(() => setEvaluateEvery(evaluateEveryInForm), [evaluateEveryInForm]); diff --git a/public/app/features/alerting/unified/state/actions.ts b/public/app/features/alerting/unified/state/actions.ts index 3e15c9ed9bc..471603c3478 100644 --- a/public/app/features/alerting/unified/state/actions.ts +++ b/public/app/features/alerting/unified/state/actions.ts @@ -1,7 +1,7 @@ import { AsyncThunk, createAsyncThunk } from '@reduxjs/toolkit'; import { isEmpty } from 'lodash'; -import { config, locationService } from '@grafana/runtime'; +import { locationService } from '@grafana/runtime'; import { AlertmanagerAlert, AlertManagerCortexConfig, @@ -32,9 +32,8 @@ import { RulerRulesConfigDTO, } from 'app/types/unified-alerting-dto'; -import { contextSrv } from '../../../../core/core'; import { backendSrv } from '../../../../core/services/backend_srv'; -import { logInfo, LogMessages, trackNewAlerRuleFormSaved, withPerformanceLogging } from '../Analytics'; +import { logInfo, LogMessages, withPerformanceLogging } from '../Analytics'; import { addAlertManagers, createOrUpdateSilence, @@ -512,14 +511,6 @@ export const saveRuleFormAction = createAsyncThunk( logInfo(LogMessages.successSavingAlertRule, { type, isNew: (!existing).toString() }); - if (!existing) { - trackNewAlerRuleFormSaved({ - grafana_version: config.buildInfo.version, - org_id: contextSrv.user.orgId, - user_id: contextSrv.user.id, - }); - } - if (redirectOnSave) { locationService.push(redirectOnSave); } else {