Skip to content

Commit 3b7058e

Browse files
authored
fix(app): add robotSerialNumber to proceedToRun event (#14976)
* fix(app): add robotSerialNumber to proceedToRun event
1 parent ff5e0c0 commit 3b7058e

File tree

7 files changed

+38
-13
lines changed

7 files changed

+38
-13
lines changed

app/src/organisms/Devices/HistoricalProtocolRunOverflowMenu.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
ANALYTICS_PROTOCOL_RUN_AGAIN,
3333
} from '../../redux/analytics'
3434
import { getRobotUpdateDisplayInfo } from '../../redux/robot-update'
35-
import { useDownloadRunLog, useTrackProtocolRunEvent } from './hooks'
35+
import { useDownloadRunLog, useTrackProtocolRunEvent, useRobot } from './hooks'
3636
import { useIsEstopNotDisengaged } from '../../resources/devices/hooks/useIsEstopNotDisengaged'
3737

3838
import type { Run } from '@opentrons/api-client'
@@ -132,6 +132,9 @@ function MenuDropdown(props: MenuDropdownProps): JSX.Element {
132132
const { trackProtocolRunEvent } = useTrackProtocolRunEvent(runId, robotName)
133133
const { reset } = useRunControls(runId, onResetSuccess)
134134
const { deleteRun } = useDeleteRunMutation()
135+
const robot = useRobot(robotName)
136+
const robotSerialNumber =
137+
robot?.health?.robot_serial ?? robot?.serverHealth?.serialNumber ?? null
135138

136139
const handleResetClick: React.MouseEventHandler<HTMLButtonElement> = (
137140
e
@@ -142,7 +145,10 @@ function MenuDropdown(props: MenuDropdownProps): JSX.Element {
142145
reset()
143146
trackEvent({
144147
name: ANALYTICS_PROTOCOL_PROCEED_TO_RUN,
145-
properties: { sourceLocation: 'HistoricalProtocolRun' },
148+
properties: {
149+
sourceLocation: 'HistoricalProtocolRun',
150+
robotSerialNumber,
151+
},
146152
})
147153
trackProtocolRunEvent({ name: ANALYTICS_PROTOCOL_RUN_AGAIN })
148154
}

app/src/organisms/Devices/__tests__/HistoricalProtocolRunOverflowMenu.test.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,24 @@ import '@testing-library/jest-dom/vitest'
55
import { renderWithProviders } from '../../../__testing-utils__'
66
import { when } from 'vitest-when'
77
import { MemoryRouter } from 'react-router-dom'
8-
import { UseQueryResult } from 'react-query'
98
import {
109
useAllCommandsQuery,
1110
useDeleteRunMutation,
1211
} from '@opentrons/react-api-client'
1312
import { i18n } from '../../../i18n'
1413
import runRecord from '../../../organisms/RunDetails/__fixtures__/runRecord.json'
15-
import { useDownloadRunLog, useTrackProtocolRunEvent } from '../hooks'
14+
import { useDownloadRunLog, useTrackProtocolRunEvent, useRobot } from '../hooks'
1615
import { useRunControls } from '../../RunTimeControl/hooks'
1716
import {
1817
useTrackEvent,
1918
ANALYTICS_PROTOCOL_PROCEED_TO_RUN,
2019
} from '../../../redux/analytics'
20+
import { mockConnectableRobot } from '../../../redux/discovery/__fixtures__'
2121
import { getRobotUpdateDisplayInfo } from '../../../redux/robot-update'
2222
import { useIsEstopNotDisengaged } from '../../../resources/devices/hooks/useIsEstopNotDisengaged'
2323
import { HistoricalProtocolRunOverflowMenu } from '../HistoricalProtocolRunOverflowMenu'
2424

25+
import type { UseQueryResult } from 'react-query'
2526
import type { CommandsData } from '@opentrons/api-client'
2627

2728
vi.mock('../../../redux/analytics')
@@ -104,6 +105,9 @@ describe('HistoricalProtocolRunOverflowMenu', () => {
104105
robotName: ROBOT_NAME,
105106
robotIsBusy: false,
106107
}
108+
when(vi.mocked(useRobot))
109+
.calledWith(ROBOT_NAME)
110+
.thenReturn(mockConnectableRobot)
107111
})
108112

109113
it('renders the correct menu when a runId is present', () => {
@@ -122,7 +126,10 @@ describe('HistoricalProtocolRunOverflowMenu', () => {
122126
fireEvent.click(rerunBtn)
123127
expect(mockTrackEvent).toHaveBeenCalledWith({
124128
name: ANALYTICS_PROTOCOL_PROCEED_TO_RUN,
125-
properties: { sourceLocation: 'HistoricalProtocolRun' },
129+
properties: {
130+
robotSerialNumber: 'mock-serial',
131+
sourceLocation: 'HistoricalProtocolRun',
132+
},
126133
})
127134
expect(useRunControls).toHaveBeenCalled()
128135
expect(mockTrackProtocolRunEvent).toHaveBeenCalled()

app/src/organisms/Devices/hooks/__tests__/useProtocolRunAnalyticsData.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ describe('useProtocolAnalysisErrors hook', () => {
131131
protocolText: 'hashedString',
132132
protocolType: '',
133133
robotType: 'OT-2 Standard',
134-
robotSerialNumber: '',
134+
robotSerialNumber: 'mock-serial',
135135
},
136136
runTime: '1:00:00',
137137
})
@@ -160,7 +160,7 @@ describe('useProtocolAnalysisErrors hook', () => {
160160
protocolText: 'hashedString',
161161
protocolType: 'json',
162162
robotType: 'OT-2 Standard',
163-
robotSerialNumber: '',
163+
robotSerialNumber: 'mock-serial',
164164
},
165165
runTime: '1:00:00',
166166
})

app/src/organisms/OnDeviceDisplay/RobotDashboard/RecentRunProtocolCard.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ import {
2929
} from '@opentrons/api-client'
3030

3131
import { ODD_FOCUS_VISIBLE } from '../../../atoms/buttons//constants'
32-
import { useTrackEvent } from '../../../redux/analytics'
32+
import {
33+
useTrackEvent,
34+
ANALYTICS_PROTOCOL_PROCEED_TO_RUN,
35+
} from '../../../redux/analytics'
3336
import { Skeleton } from '../../../atoms/Skeleton'
3437
import { useMissingProtocolHardware } from '../../../pages/Protocols/hooks'
3538
import { useCloneRun } from '../../ProtocolUpload/hooks'
@@ -147,7 +150,7 @@ export function ProtocolWithLastRun({
147150
} else {
148151
cloneRun()
149152
trackEvent({
150-
name: 'proceedToRun',
153+
name: ANALYTICS_PROTOCOL_PROCEED_TO_RUN,
151154
properties: { sourceLocation: 'RecentRunProtocolCard' },
152155
})
153156
}

app/src/organisms/OnDeviceDisplay/RobotDashboard/__tests__/RecentRunProtocolCard.test.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ import { i18n } from '../../../../i18n'
2020
import { Skeleton } from '../../../../atoms/Skeleton'
2121
import { useMissingProtocolHardware } from '../../../../pages/Protocols/hooks'
2222
import { useTrackProtocolRunEvent } from '../../../Devices/hooks'
23-
import { useTrackEvent } from '../../../../redux/analytics'
23+
import {
24+
useTrackEvent,
25+
ANALYTICS_PROTOCOL_PROCEED_TO_RUN,
26+
} from '../../../../redux/analytics'
2427
import { useCloneRun } from '../../../ProtocolUpload/hooks'
2528
import { useRerunnableStatusText } from '../hooks'
2629
import { RecentRunProtocolCard } from '../'
@@ -250,7 +253,7 @@ describe('RecentRunProtocolCard', () => {
250253
expect(button).toHaveStyle(`background-color: ${COLORS.green40}`)
251254
fireEvent.click(button)
252255
expect(mockTrackEvent).toHaveBeenCalledWith({
253-
name: 'proceedToRun',
256+
name: ANALYTICS_PROTOCOL_PROCEED_TO_RUN,
254257
properties: { sourceLocation: 'RecentRunProtocolCard' },
255258
})
256259
// TODO(BC, 08/30/23): reintroduce check for tracking when tracking is reintroduced lazily

app/src/pages/RunSummary/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import {
5757
// ANALYTICS_PROTOCOL_RUN_CANCEL,
5858
ANALYTICS_PROTOCOL_RUN_AGAIN,
5959
ANALYTICS_PROTOCOL_RUN_FINISH,
60+
ANALYTICS_PROTOCOL_PROCEED_TO_RUN,
6061
} from '../../redux/analytics'
6162
import { getLocalRobot } from '../../redux/discovery'
6263
import { RunFailedModal } from '../../organisms/OnDeviceDisplay/RunningProtocol'
@@ -124,6 +125,10 @@ export function RunSummary(): JSX.Element {
124125
const [showRunAgainSpinner, setShowRunAgainSpinner] = React.useState<boolean>(
125126
false
126127
)
128+
const robotSerialNumber =
129+
localRobot?.health?.robot_serial ??
130+
localRobot?.serverHealth?.serialNumber ??
131+
null
127132

128133
let headerText = t('run_complete_splash')
129134
if (runStatus === RUN_STATUS_FAILED) {
@@ -167,8 +172,8 @@ export function RunSummary(): JSX.Element {
167172
setShowRunAgainSpinner(true)
168173
reset()
169174
trackEvent({
170-
name: 'proceedToRun',
171-
properties: { sourceLocation: 'RunSummary' },
175+
name: ANALYTICS_PROTOCOL_PROCEED_TO_RUN,
176+
properties: { sourceLocation: 'RunSummary', robotSerialNumber },
172177
})
173178
trackProtocolRunEvent({ name: ANALYTICS_PROTOCOL_RUN_AGAIN })
174179
}

app/src/redux/discovery/__fixtures__/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const mockHealthResponse = {
1818
api_version: '0.0.0-mock',
1919
fw_version: '0.0.0-mock',
2020
system_version: '0.0.0-mock',
21+
robot_serial: 'mock-serial',
2122
logs: [] as string[],
2223
protocol_api_version: [2, 0] as [number, number],
2324
}

0 commit comments

Comments
 (0)