Skip to content

Commit b7da457

Browse files
b-cooperSakib HossainjeraderbrenthagenVincent Abruzzo
authored
refactor(app): add analytics tracking events for new functionality introduced in 6.0
Add analytics tracking events that cover new functionality introduced in version 6.0 of the app Closes #10751 Co-authored-by: Sakib Hossain <[email protected]> Co-authored-by: Jethary Rader <[email protected]> Co-authored-by: Brent Hagen <[email protected]> Co-authored-by: Vincent Abruzzo <[email protected]>
1 parent e586bfe commit b7da457

File tree

19 files changed

+206
-19
lines changed

19 files changed

+206
-19
lines changed

app/src/organisms/AddCustomLabwareSlideout/__tests__/AddCustomLabwareSlideout.test.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
import * as React from 'react'
22
import { MemoryRouter } from 'react-router-dom'
3+
import { fireEvent } from '@testing-library/react'
34
import { renderWithProviders } from '@opentrons/components'
45
import { i18n } from '../../../i18n'
6+
import { useTrackEvent } from '../../../redux/analytics'
57
import { AddCustomLabwareSlideout } from '..'
68

79
jest.mock('../../../redux/custom-labware')
810
jest.mock('../../../pages/Labware/helpers/getAllDefs')
11+
jest.mock('../../../redux/analytics')
12+
13+
const mockUseTrackEvent = useTrackEvent as jest.MockedFunction<
14+
typeof useTrackEvent
15+
>
16+
17+
let mockTrackEvent: jest.Mock
918

1019
const render = (
1120
props: React.ComponentProps<typeof AddCustomLabwareSlideout>
@@ -27,12 +36,21 @@ describe('AddCustomLabwareSlideout', () => {
2736
onSuccess: jest.fn(() => null),
2837
onFailure: jest.fn(() => null),
2938
}
39+
beforeEach(() => {
40+
mockTrackEvent = jest.fn()
41+
mockUseTrackEvent.mockReturnValue(mockTrackEvent)
42+
})
3043

31-
it('renders correct title and labware cards', () => {
44+
it('renders correct title and labware cards and clicking on button triggers analytics event', () => {
3245
const [{ getByText, getByRole }] = render(props)
3346
getByText('Import a Custom Labware Definition')
3447
getByText('Or choose a file from your computer to upload.')
35-
getByRole('button', { name: 'Choose File' })
48+
const btn = getByRole('button', { name: 'Choose File' })
49+
fireEvent.click(btn)
50+
expect(mockTrackEvent).toHaveBeenCalledWith({
51+
name: 'addCustomLabware',
52+
properties: {},
53+
})
3654
})
3755

3856
it('renders drag and drop section', () => {

app/src/organisms/AddCustomLabwareSlideout/index.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
} from '../../redux/custom-labware'
1616
import { Slideout } from '../../atoms/Slideout'
1717
import { StyledText } from '../../atoms/text'
18+
import { useTrackEvent } from '../../redux/analytics'
1819
import { UploadInput } from '../../molecules/UploadInput'
1920
import type { Dispatch } from '../../redux/types'
2021

@@ -30,6 +31,7 @@ export function AddCustomLabwareSlideout(
3031
): JSX.Element {
3132
const { t } = useTranslation(['labware_landing', 'shared'])
3233
const dispatch = useDispatch<Dispatch>()
34+
const trackEvent = useTrackEvent()
3335

3436
return (
3537
<Slideout
@@ -46,7 +48,13 @@ export function AddCustomLabwareSlideout(
4648
onUpload={(file: File) => {
4749
dispatch(addCustomLabwareFile(file.path))
4850
}}
49-
onClick={() => dispatch(addCustomLabware())}
51+
onClick={() => {
52+
dispatch(addCustomLabware())
53+
trackEvent({
54+
name: 'addCustomLabware',
55+
properties: {},
56+
})
57+
}}
5058
uploadText={t('choose_file_to_upload')}
5159
dragAndDropText={
5260
<StyledText as="p">

app/src/organisms/Devices/RobotSettings/AdvancedTab/AdvancedTabSlideouts/RenameRobotSlideout.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
getReachableRobots,
1818
getUnreachableRobots,
1919
} from '../../../../../redux/discovery'
20+
import { useTrackEvent } from '../../../../../redux/analytics'
2021
import { Slideout } from '../../../../../atoms/Slideout'
2122
import { StyledText } from '../../../../../atoms/text'
2223
import { PrimaryButton } from '../../../../../atoms/buttons'
@@ -50,6 +51,7 @@ export function RenameRobotSlideout({
5051
const [previousRobotName, setPreviousRobotName] = React.useState<string>(
5152
robotName
5253
)
54+
const trackEvent = useTrackEvent()
5355
const history = useHistory()
5456
const dispatch = useDispatch<Dispatch>()
5557
const connectableRobots = useSelector((state: State) =>
@@ -111,14 +113,25 @@ export function RenameRobotSlideout({
111113
},
112114
})
113115

116+
const handleSubmitRobotRename = (): void => {
117+
trackEvent({
118+
name: 'renameRobot',
119+
properties: {
120+
previousRobotName,
121+
newRobotName: formik.values.newRobotName,
122+
},
123+
})
124+
formik.handleSubmit()
125+
}
126+
114127
return (
115128
<Slideout
116129
title={t('rename_robot_slideout_title')}
117130
onCloseClick={onCloseClick}
118131
isExpanded={isExpanded}
119132
footer={
120133
<PrimaryButton
121-
onClick={() => formik.handleSubmit()}
134+
onClick={handleSubmitRobotRename}
122135
disabled={!(formik.isValid && formik.dirty)}
123136
width="100%"
124137
>

app/src/organisms/Devices/RobotSettings/AdvancedTab/AdvancedTabSlideouts/__tests__/RenameRobotSlideout.test.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { MemoryRouter } from 'react-router-dom'
33
import { fireEvent, waitFor } from '@testing-library/react'
44
import { renderWithProviders } from '@opentrons/components'
55
import { i18n } from '../../../../../../i18n'
6+
import { useTrackEvent } from '../../../../../../redux/analytics'
67
import {
78
getConnectableRobots,
89
getReachableRobots,
@@ -15,15 +16,21 @@ import {
1516
import { RenameRobotSlideout } from '../RenameRobotSlideout'
1617

1718
jest.mock('../../../../../../redux/discovery/selectors')
19+
jest.mock('../../../../../../redux/analytics')
1820

1921
const mockGetConnectableRobots = getConnectableRobots as jest.MockedFunction<
2022
typeof getConnectableRobots
2123
>
2224
const mockGetReachableRobots = getReachableRobots as jest.MockedFunction<
2325
typeof getReachableRobots
2426
>
27+
const mockUseTrackEvent = useTrackEvent as jest.MockedFunction<
28+
typeof useTrackEvent
29+
>
2530

2631
const mockOnCloseClick = jest.fn()
32+
let mockTrackEvent: jest.Mock
33+
2734
const render = () => {
2835
return renderWithProviders(
2936
<MemoryRouter>
@@ -39,6 +46,8 @@ const render = () => {
3946

4047
describe('RobotSettings RenameRobotSlideout', () => {
4148
beforeEach(() => {
49+
mockTrackEvent = jest.fn()
50+
mockUseTrackEvent.mockReturnValue(mockTrackEvent)
4251
mockConnectableRobot.name = 'connectableOtie'
4352
mockReachableRobot.name = 'reachableOtie'
4453
mockGetConnectableRobots.mockReturnValue([mockConnectableRobot])
@@ -73,6 +82,11 @@ describe('RobotSettings RenameRobotSlideout', () => {
7382
expect(input).toHaveValue('mockInput')
7483
const renameButton = getByRole('button', { name: 'Rename robot' })
7584
expect(renameButton).not.toBeDisabled()
85+
fireEvent.click(renameButton)
86+
expect(mockTrackEvent).toHaveBeenCalledWith({
87+
name: 'renameRobot',
88+
properties: { newRobotName: 'mockInput', previousRobotName: 'otie' },
89+
})
7690
})
7791
})
7892

app/src/organisms/Devices/RobotSettings/RobotSettingsCalibration.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ export function RobotSettingsCalibration({
305305
session &&
306306
session.sessionType === Sessions.SESSION_TYPE_CALIBRATION_HEALTH_CHECK
307307
) {
308+
// TODO: add this analytics event when we deprecate this event firing in redux/analytics makeEvent
308309
return session
309310
}
310311
return null
@@ -500,6 +501,14 @@ export function RobotSettingsCalibration({
500501
true
501502
)
502503

504+
const handleHealthCheckClick = (): void => {
505+
handleHealthCheck(null)
506+
doTrackEvent({
507+
name: 'calibrationHealthCheckButtonClicked',
508+
properties: {},
509+
})
510+
}
511+
503512
return (
504513
<>
505514
<Portal level="top">
@@ -689,7 +698,7 @@ export function RobotSettingsCalibration({
689698
</Box>
690699
<TertiaryButton
691700
{...targetProps}
692-
onClick={() => handleHealthCheck(null)}
701+
onClick={handleHealthCheckClick}
693702
disabled={calCheckButtonDisabled}
694703
>
695704
{t('health_check_button')}

app/src/organisms/Devices/RobotSettings/__tests__/RobotSettingsCalibration.test.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,11 @@ describe('RobotSettingsCalibration', () => {
393393
const [{ getByRole }] = render()
394394
const button = getByRole('button', { name: 'Check health' })
395395
expect(button).not.toBeDisabled()
396+
fireEvent.click(button)
397+
expect(mockTrackEvent).toHaveBeenCalledWith({
398+
name: 'calibrationHealthCheckButtonClicked',
399+
properties: {},
400+
})
396401
})
397402

398403
it('Health check button is disabled when a robot is unreachable', () => {

app/src/organisms/LabwareCard/CustomLabwareOverflowMenu.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as React from 'react'
22
import { useDispatch } from 'react-redux'
33
import { useTranslation } from 'react-i18next'
4+
import { useTrackEvent } from '../../redux/analytics'
45
import {
56
Flex,
67
Icon,
@@ -50,6 +51,7 @@ export function CustomLabwareOverflowMenu(
5051
const overflowMenuRef = useOnClickOutside<HTMLDivElement>({
5152
onClickOutside: () => setShowOverflowMenu(false),
5253
})
54+
const trackEvent = useTrackEvent()
5355

5456
const {
5557
confirm: confirmDeleteLabware,
@@ -79,6 +81,10 @@ export function CustomLabwareOverflowMenu(
7981
const handleClickLabwareCreator: React.MouseEventHandler<HTMLButtonElement> = e => {
8082
e.preventDefault()
8183
e.stopPropagation()
84+
trackEvent({
85+
name: 'openLabwareCreatorFromLabwareOverflowMenu',
86+
properties: {},
87+
})
8288
setShowOverflowMenu(false)
8389
window.open(LABWARE_CREATOR_HREF, '_blank')
8490
}

app/src/organisms/LabwareCard/__tests__/CustomLabwareOverflowMenu.test.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import * as React from 'react'
22
import { fireEvent } from '@testing-library/react'
3+
import { useTrackEvent } from '../../../redux/analytics'
34
import {
45
renderWithProviders,
56
useConditionalConfirm,
67
} from '@opentrons/components'
78
import { i18n } from '../../../i18n'
89
import { CustomLabwareOverflowMenu } from '../CustomLabwareOverflowMenu'
910

11+
jest.mock('../../../redux/analytics')
1012
jest.mock('@opentrons/components/src/hooks')
1113

1214
const render = (
@@ -20,8 +22,13 @@ const render = (
2022
const mockUseConditionalConfirm = useConditionalConfirm as jest.MockedFunction<
2123
typeof useConditionalConfirm
2224
>
25+
const mockUseTrackEvent = useTrackEvent as jest.MockedFunction<
26+
typeof useTrackEvent
27+
>
28+
2329
const mockConfirm = jest.fn()
2430
const mockCancel = jest.fn()
31+
let mockTrackEvent: jest.Mock
2532

2633
describe('CustomLabwareOverflowMenu', () => {
2734
let props: React.ComponentProps<typeof CustomLabwareOverflowMenu>
@@ -36,6 +43,8 @@ describe('CustomLabwareOverflowMenu', () => {
3643
showConfirmation: true,
3744
cancel: mockCancel,
3845
})
46+
mockTrackEvent = jest.fn()
47+
mockUseTrackEvent.mockReturnValue(mockTrackEvent)
3948
})
4049

4150
afterEach(() => {

app/src/organisms/LabwareCard/__tests__/LabwareCard.test.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import * as React from 'react'
22
import { renderWithProviders, nestedTextMatcher } from '@opentrons/components'
33
import { i18n } from '../../../i18n'
4-
import { LabwareCard } from '..'
54
import { useAllLabware } from '../../../pages/Labware/hooks'
65
import { mockDefinition } from '../../../redux/custom-labware/__fixtures__'
6+
import { CustomLabwareOverflowMenu } from '../CustomLabwareOverflowMenu'
7+
import { LabwareCard } from '..'
78

89
jest.mock('../../../pages/Labware/hooks')
9-
jest.mock('../../../pages/Labware/helpers/getAllDefs')
10+
jest.mock('../CustomLabwareOverflowMenu')
1011
jest.mock('@opentrons/components', () => {
1112
const actualComponents = jest.requireActual('@opentrons/components')
1213
return {
@@ -15,6 +16,9 @@ jest.mock('@opentrons/components', () => {
1516
}
1617
})
1718

19+
const mockCustomLabwareOverflowMenu = CustomLabwareOverflowMenu as jest.MockedFunction<
20+
typeof CustomLabwareOverflowMenu
21+
>
1822
const mockUseAllLabware = useAllLabware as jest.MockedFunction<
1923
typeof useAllLabware
2024
>
@@ -27,6 +31,9 @@ const render = (props: React.ComponentProps<typeof LabwareCard>) => {
2731
describe('LabwareCard', () => {
2832
let props: React.ComponentProps<typeof LabwareCard>
2933
beforeEach(() => {
34+
mockCustomLabwareOverflowMenu.mockReturnValue(
35+
<div>Mock CustomLabwareOverflowMenu</div>
36+
)
3037
mockUseAllLabware.mockReturnValue([{ definition: mockDefinition }])
3138
props = {
3239
labware: {

app/src/organisms/LabwarePositionCheck/SummaryScreen.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
JUSTIFY_SPACE_BETWEEN,
1515
} from '@opentrons/components'
1616
import { useCreateLabwareOffsetMutation } from '@opentrons/react-api-client'
17+
import { useTrackEvent } from '../../redux/analytics'
1718
import { useCurrentRunId } from '../ProtocolUpload/hooks'
1819
import { useLPCSuccessToast } from '../ProtocolSetup/hooks'
1920
import { DeckMap } from './DeckMap'
@@ -35,6 +36,7 @@ export const SummaryScreen = (props: {
3536
const { t } = useTranslation('labware_position_check')
3637
const introInfo = useIntroInfo()
3738
const { protocolData } = useProtocolDetailsForRun(runId)
39+
const trackEvent = useTrackEvent()
3840
useLabwareOffsets(
3941
savePositionCommandData,
4042
protocolData as ProtocolAnalysisFile
@@ -53,6 +55,7 @@ export const SummaryScreen = (props: {
5355
const { sections, primaryPipetteMount, secondaryPipetteMount } = introInfo
5456

5557
const applyLabwareOffsets = (): void => {
58+
trackEvent({ name: 'applyLabwareOffsetData', properties: {} })
5659
if (labwareOffsets.length > 0) {
5760
labwareOffsets.forEach(labwareOffset => {
5861
createLabwareOffset({

0 commit comments

Comments
 (0)