diff --git a/app/src/organisms/Devices/HistoricalProtocolRunOverflowMenu.tsx b/app/src/organisms/Devices/HistoricalProtocolRunOverflowMenu.tsx index bf06e0db263..7f4bc54b6e1 100644 --- a/app/src/organisms/Devices/HistoricalProtocolRunOverflowMenu.tsx +++ b/app/src/organisms/Devices/HistoricalProtocolRunOverflowMenu.tsx @@ -32,7 +32,7 @@ import { ANALYTICS_PROTOCOL_RUN_AGAIN, } from '../../redux/analytics' import { getRobotUpdateDisplayInfo } from '../../redux/robot-update' -import { useDownloadRunLog, useTrackProtocolRunEvent } from './hooks' +import { useDownloadRunLog, useTrackProtocolRunEvent, useRobot } from './hooks' import { useIsEstopNotDisengaged } from '../../resources/devices/hooks/useIsEstopNotDisengaged' import type { Run } from '@opentrons/api-client' @@ -132,6 +132,9 @@ function MenuDropdown(props: MenuDropdownProps): JSX.Element { const { trackProtocolRunEvent } = useTrackProtocolRunEvent(runId, robotName) const { reset } = useRunControls(runId, onResetSuccess) const { deleteRun } = useDeleteRunMutation() + const robot = useRobot(robotName) + const robotSerialNumber = + robot?.health?.robot_serial ?? robot?.serverHealth?.serialNumber ?? null const handleResetClick: React.MouseEventHandler = ( e @@ -142,7 +145,10 @@ function MenuDropdown(props: MenuDropdownProps): JSX.Element { reset() trackEvent({ name: ANALYTICS_PROTOCOL_PROCEED_TO_RUN, - properties: { sourceLocation: 'HistoricalProtocolRun' }, + properties: { + sourceLocation: 'HistoricalProtocolRun', + robotSerialNumber, + }, }) trackProtocolRunEvent({ name: ANALYTICS_PROTOCOL_RUN_AGAIN }) } diff --git a/app/src/organisms/Devices/__tests__/HistoricalProtocolRunOverflowMenu.test.tsx b/app/src/organisms/Devices/__tests__/HistoricalProtocolRunOverflowMenu.test.tsx index f7d537e88ff..c436bc04960 100644 --- a/app/src/organisms/Devices/__tests__/HistoricalProtocolRunOverflowMenu.test.tsx +++ b/app/src/organisms/Devices/__tests__/HistoricalProtocolRunOverflowMenu.test.tsx @@ -5,23 +5,24 @@ import '@testing-library/jest-dom/vitest' import { renderWithProviders } from '../../../__testing-utils__' import { when } from 'vitest-when' import { MemoryRouter } from 'react-router-dom' -import { UseQueryResult } from 'react-query' import { useAllCommandsQuery, useDeleteRunMutation, } from '@opentrons/react-api-client' import { i18n } from '../../../i18n' import runRecord from '../../../organisms/RunDetails/__fixtures__/runRecord.json' -import { useDownloadRunLog, useTrackProtocolRunEvent } from '../hooks' +import { useDownloadRunLog, useTrackProtocolRunEvent, useRobot } from '../hooks' import { useRunControls } from '../../RunTimeControl/hooks' import { useTrackEvent, ANALYTICS_PROTOCOL_PROCEED_TO_RUN, } from '../../../redux/analytics' +import { mockConnectableRobot } from '../../../redux/discovery/__fixtures__' import { getRobotUpdateDisplayInfo } from '../../../redux/robot-update' import { useIsEstopNotDisengaged } from '../../../resources/devices/hooks/useIsEstopNotDisengaged' import { HistoricalProtocolRunOverflowMenu } from '../HistoricalProtocolRunOverflowMenu' +import type { UseQueryResult } from 'react-query' import type { CommandsData } from '@opentrons/api-client' vi.mock('../../../redux/analytics') @@ -104,6 +105,9 @@ describe('HistoricalProtocolRunOverflowMenu', () => { robotName: ROBOT_NAME, robotIsBusy: false, } + when(vi.mocked(useRobot)) + .calledWith(ROBOT_NAME) + .thenReturn(mockConnectableRobot) }) it('renders the correct menu when a runId is present', () => { @@ -122,7 +126,10 @@ describe('HistoricalProtocolRunOverflowMenu', () => { fireEvent.click(rerunBtn) expect(mockTrackEvent).toHaveBeenCalledWith({ name: ANALYTICS_PROTOCOL_PROCEED_TO_RUN, - properties: { sourceLocation: 'HistoricalProtocolRun' }, + properties: { + robotSerialNumber: 'mock-serial', + sourceLocation: 'HistoricalProtocolRun', + }, }) expect(useRunControls).toHaveBeenCalled() expect(mockTrackProtocolRunEvent).toHaveBeenCalled() diff --git a/app/src/organisms/Devices/hooks/__tests__/useProtocolRunAnalyticsData.test.tsx b/app/src/organisms/Devices/hooks/__tests__/useProtocolRunAnalyticsData.test.tsx index ce08a6cab90..72d8084df6b 100644 --- a/app/src/organisms/Devices/hooks/__tests__/useProtocolRunAnalyticsData.test.tsx +++ b/app/src/organisms/Devices/hooks/__tests__/useProtocolRunAnalyticsData.test.tsx @@ -131,7 +131,7 @@ describe('useProtocolAnalysisErrors hook', () => { protocolText: 'hashedString', protocolType: '', robotType: 'OT-2 Standard', - robotSerialNumber: '', + robotSerialNumber: 'mock-serial', }, runTime: '1:00:00', }) @@ -160,7 +160,7 @@ describe('useProtocolAnalysisErrors hook', () => { protocolText: 'hashedString', protocolType: 'json', robotType: 'OT-2 Standard', - robotSerialNumber: '', + robotSerialNumber: 'mock-serial', }, runTime: '1:00:00', }) diff --git a/app/src/organisms/OnDeviceDisplay/RobotDashboard/RecentRunProtocolCard.tsx b/app/src/organisms/OnDeviceDisplay/RobotDashboard/RecentRunProtocolCard.tsx index 21d293c7d5f..2f640e7e522 100644 --- a/app/src/organisms/OnDeviceDisplay/RobotDashboard/RecentRunProtocolCard.tsx +++ b/app/src/organisms/OnDeviceDisplay/RobotDashboard/RecentRunProtocolCard.tsx @@ -29,7 +29,10 @@ import { } from '@opentrons/api-client' import { ODD_FOCUS_VISIBLE } from '../../../atoms/buttons//constants' -import { useTrackEvent } from '../../../redux/analytics' +import { + useTrackEvent, + ANALYTICS_PROTOCOL_PROCEED_TO_RUN, +} from '../../../redux/analytics' import { Skeleton } from '../../../atoms/Skeleton' import { useMissingProtocolHardware } from '../../../pages/Protocols/hooks' import { useCloneRun } from '../../ProtocolUpload/hooks' @@ -147,7 +150,7 @@ export function ProtocolWithLastRun({ } else { cloneRun() trackEvent({ - name: 'proceedToRun', + name: ANALYTICS_PROTOCOL_PROCEED_TO_RUN, properties: { sourceLocation: 'RecentRunProtocolCard' }, }) } diff --git a/app/src/organisms/OnDeviceDisplay/RobotDashboard/__tests__/RecentRunProtocolCard.test.tsx b/app/src/organisms/OnDeviceDisplay/RobotDashboard/__tests__/RecentRunProtocolCard.test.tsx index 10de409948a..e1a54944a99 100644 --- a/app/src/organisms/OnDeviceDisplay/RobotDashboard/__tests__/RecentRunProtocolCard.test.tsx +++ b/app/src/organisms/OnDeviceDisplay/RobotDashboard/__tests__/RecentRunProtocolCard.test.tsx @@ -20,7 +20,10 @@ import { i18n } from '../../../../i18n' import { Skeleton } from '../../../../atoms/Skeleton' import { useMissingProtocolHardware } from '../../../../pages/Protocols/hooks' import { useTrackProtocolRunEvent } from '../../../Devices/hooks' -import { useTrackEvent } from '../../../../redux/analytics' +import { + useTrackEvent, + ANALYTICS_PROTOCOL_PROCEED_TO_RUN, +} from '../../../../redux/analytics' import { useCloneRun } from '../../../ProtocolUpload/hooks' import { useRerunnableStatusText } from '../hooks' import { RecentRunProtocolCard } from '../' @@ -250,7 +253,7 @@ describe('RecentRunProtocolCard', () => { expect(button).toHaveStyle(`background-color: ${COLORS.green40}`) fireEvent.click(button) expect(mockTrackEvent).toHaveBeenCalledWith({ - name: 'proceedToRun', + name: ANALYTICS_PROTOCOL_PROCEED_TO_RUN, properties: { sourceLocation: 'RecentRunProtocolCard' }, }) // TODO(BC, 08/30/23): reintroduce check for tracking when tracking is reintroduced lazily diff --git a/app/src/pages/RunSummary/index.tsx b/app/src/pages/RunSummary/index.tsx index e76a73ce1b9..7666cc8ada6 100644 --- a/app/src/pages/RunSummary/index.tsx +++ b/app/src/pages/RunSummary/index.tsx @@ -57,6 +57,7 @@ import { // ANALYTICS_PROTOCOL_RUN_CANCEL, ANALYTICS_PROTOCOL_RUN_AGAIN, ANALYTICS_PROTOCOL_RUN_FINISH, + ANALYTICS_PROTOCOL_PROCEED_TO_RUN, } from '../../redux/analytics' import { getLocalRobot } from '../../redux/discovery' import { RunFailedModal } from '../../organisms/OnDeviceDisplay/RunningProtocol' @@ -124,6 +125,10 @@ export function RunSummary(): JSX.Element { const [showRunAgainSpinner, setShowRunAgainSpinner] = React.useState( false ) + const robotSerialNumber = + localRobot?.health?.robot_serial ?? + localRobot?.serverHealth?.serialNumber ?? + null let headerText = t('run_complete_splash') if (runStatus === RUN_STATUS_FAILED) { @@ -167,8 +172,8 @@ export function RunSummary(): JSX.Element { setShowRunAgainSpinner(true) reset() trackEvent({ - name: 'proceedToRun', - properties: { sourceLocation: 'RunSummary' }, + name: ANALYTICS_PROTOCOL_PROCEED_TO_RUN, + properties: { sourceLocation: 'RunSummary', robotSerialNumber }, }) trackProtocolRunEvent({ name: ANALYTICS_PROTOCOL_RUN_AGAIN }) } diff --git a/app/src/redux/discovery/__fixtures__/index.ts b/app/src/redux/discovery/__fixtures__/index.ts index 329e18504dd..ea7a4e0f195 100644 --- a/app/src/redux/discovery/__fixtures__/index.ts +++ b/app/src/redux/discovery/__fixtures__/index.ts @@ -18,6 +18,7 @@ export const mockHealthResponse = { api_version: '0.0.0-mock', fw_version: '0.0.0-mock', system_version: '0.0.0-mock', + robot_serial: 'mock-serial', logs: [] as string[], protocol_api_version: [2, 0] as [number, number], }