Skip to content

Commit

Permalink
feat(app): add mixpanel tracking for quick transfer (#16200)
Browse files Browse the repository at this point in the history
  • Loading branch information
smb2268 authored Sep 6, 2024
1 parent 6948d93 commit 02ba906
Show file tree
Hide file tree
Showing 27 changed files with 448 additions and 37 deletions.
1 change: 1 addition & 0 deletions app/src/organisms/Devices/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export * from './useProtocolRunAnalyticsData'
export * from './useRobotAnalyticsData'
export * from './useTrackCreateProtocolRunEvent'
export * from './useTrackProtocolRunEvent'
export * from './useTrackEventWithRobotSerial'
export * from './useRunStatuses'
export * from './useSyncRobotClock'
export * from './useIsLegacySessionInProgress'
Expand Down
33 changes: 33 additions & 0 deletions app/src/organisms/Devices/hooks/useTrackEventWithRobotSerial.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { useSelector } from 'react-redux'
import { useTrackEvent } from '../../../redux/analytics'
import { getLocalRobot, getRobotSerialNumber } from '../../../redux/discovery'

interface AnalyticsEvent {
name: string
properties: { [key: string]: unknown }
}

export type TrackEventWithRobotSerial = (event: AnalyticsEvent) => void

export function useTrackEventWithRobotSerial(): {
trackEventWithRobotSerial: TrackEventWithRobotSerial
} {
const trackEvent = useTrackEvent()
const localRobot = useSelector(getLocalRobot)
const robotSerialNumber =
localRobot?.status != null ? getRobotSerialNumber(localRobot) : null
const trackEventWithRobotSerial: TrackEventWithRobotSerial = ({
name,
properties,
}) => {
trackEvent({
name,
properties: {
...properties,
robotSerial: robotSerialNumber,
},
})
}

return { trackEventWithRobotSerial }
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import {
COLORS,
ALIGN_CENTER,
} from '@opentrons/components'
import { ANALYTICS_QUICK_TRANSFER_SETTING_SAVED } from '../../../redux/analytics'
import { getTopPortalEl } from '../../../App/portal'
import { RadioButton } from '../../../atoms/buttons'
import { ChildNavigation } from '../../ChildNavigation'
import { InputField } from '../../../atoms/InputField'
import { useTrackEventWithRobotSerial } from '../../Devices/hooks'
import { ACTIONS } from '../constants'

import type {
Expand All @@ -33,6 +35,7 @@ interface AirGapProps {
export function AirGap(props: AirGapProps): JSX.Element {
const { kind, onBack, state, dispatch } = props
const { t } = useTranslation('quick_transfer')
const { trackEventWithRobotSerial } = useTrackEventWithRobotSerial()
const keyboardRef = React.useRef(null)

const [airGapEnabled, setAirGapEnabled] = React.useState<boolean>(
Expand Down Expand Up @@ -79,10 +82,22 @@ export function AirGap(props: AirGapProps): JSX.Element {
setCurrentStep(currentStep + 1)
} else {
dispatch({ type: action, volume: undefined })
trackEventWithRobotSerial({
name: ANALYTICS_QUICK_TRANSFER_SETTING_SAVED,
properties: {
setting: `AirGap_${kind}`,
},
})
onBack()
}
} else if (currentStep === 2) {
dispatch({ type: action, volume: volume ?? undefined })
trackEventWithRobotSerial({
name: ANALYTICS_QUICK_TRANSFER_SETTING_SAVED,
properties: {
setting: `AirGap_${kind}`,
},
})
onBack()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import {
FLEX_SINGLE_SLOT_BY_CUTOUT_ID,
TRASH_BIN_ADAPTER_FIXTURE,
} from '@opentrons/shared-data'
import { ANALYTICS_QUICK_TRANSFER_SETTING_SAVED } from '../../../redux/analytics'
import { getTopPortalEl } from '../../../App/portal'
import { RadioButton } from '../../../atoms/buttons'
import { useNotifyDeckConfigurationQuery } from '../../../resources/deck_configuration'
import { useTrackEventWithRobotSerial } from '../../Devices/hooks'
import { ChildNavigation } from '../../ChildNavigation'
import { ACTIONS } from '../constants'

Expand Down Expand Up @@ -91,6 +93,7 @@ export const useBlowOutLocationOptions = (
export function BlowOut(props: BlowOutProps): JSX.Element {
const { onBack, state, dispatch } = props
const { t } = useTranslation('quick_transfer')
const { trackEventWithRobotSerial } = useTrackEventWithRobotSerial()
const deckConfig = useNotifyDeckConfigurationQuery().data ?? []

const [isBlowOutEnabled, setisBlowOutEnabled] = React.useState<boolean>(
Expand Down Expand Up @@ -134,6 +137,12 @@ export function BlowOut(props: BlowOutProps): JSX.Element {
type: ACTIONS.SET_BLOW_OUT,
location: undefined,
})
trackEventWithRobotSerial({
name: ANALYTICS_QUICK_TRANSFER_SETTING_SAVED,
properties: {
settting: `BlowOut`,
},
})
onBack()
} else {
setCurrentStep(currentStep + 1)
Expand All @@ -143,6 +152,12 @@ export function BlowOut(props: BlowOutProps): JSX.Element {
type: ACTIONS.SET_BLOW_OUT,
location: blowOutLocation,
})
trackEventWithRobotSerial({
name: ANALYTICS_QUICK_TRANSFER_SETTING_SAVED,
properties: {
settting: `BlowOut`,
},
})
onBack()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import {
COLORS,
ALIGN_CENTER,
} from '@opentrons/components'
import { ANALYTICS_QUICK_TRANSFER_SETTING_SAVED } from '../../../redux/analytics'
import { getTopPortalEl } from '../../../App/portal'
import { RadioButton } from '../../../atoms/buttons'
import { ChildNavigation } from '../../ChildNavigation'
import { InputField } from '../../../atoms/InputField'
import { useTrackEventWithRobotSerial } from '../../Devices/hooks'
import { ACTIONS } from '../constants'

import type {
Expand All @@ -33,6 +35,7 @@ interface DelayProps {
export function Delay(props: DelayProps): JSX.Element {
const { kind, onBack, state, dispatch } = props
const { t } = useTranslation('quick_transfer')
const { trackEventWithRobotSerial } = useTrackEventWithRobotSerial()
const keyboardRef = React.useRef(null)

const [currentStep, setCurrentStep] = React.useState<number>(1)
Expand Down Expand Up @@ -85,6 +88,12 @@ export function Delay(props: DelayProps): JSX.Element {
type: action,
delaySettings: undefined,
})
trackEventWithRobotSerial({
name: ANALYTICS_QUICK_TRANSFER_SETTING_SAVED,
properties: {
settting: `Delay_${kind}`,
},
})
onBack()
} else {
setCurrentStep(2)
Expand All @@ -100,6 +109,12 @@ export function Delay(props: DelayProps): JSX.Element {
positionFromBottom: position,
},
})
trackEventWithRobotSerial({
name: ANALYTICS_QUICK_TRANSFER_SETTING_SAVED,
properties: {
settting: `Delay_${kind}`,
},
})
}
onBack()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ import {
LOW_VOLUME_PIPETTES,
getTipTypeFromTipRackDefinition,
} from '@opentrons/shared-data'
import { ANALYTICS_QUICK_TRANSFER_SETTING_SAVED } from '../../../redux/analytics'

import { getTopPortalEl } from '../../../App/portal'
import { ChildNavigation } from '../../ChildNavigation'
import { InputField } from '../../../atoms/InputField'
import { NumericalKeyboard } from '../../../atoms/SoftwareKeyboard'
import { useTrackEventWithRobotSerial } from '../../Devices/hooks'

import { ACTIONS } from '../constants'
import type { SupportedTip } from '@opentrons/shared-data'
Expand All @@ -37,6 +39,7 @@ interface FlowRateEntryProps {
export function FlowRateEntry(props: FlowRateEntryProps): JSX.Element {
const { onBack, state, dispatch, kind } = props
const { i18n, t } = useTranslation(['quick_transfer', 'shared'])
const { trackEventWithRobotSerial } = useTrackEventWithRobotSerial()
const keyboardRef = React.useRef(null)

const [flowRate, setFlowRate] = React.useState<number>(
Expand Down Expand Up @@ -87,6 +90,12 @@ export function FlowRateEntry(props: FlowRateEntryProps): JSX.Element {
type: flowRateAction,
rate: flowRate,
})
trackEventWithRobotSerial({
name: ANALYTICS_QUICK_TRANSFER_SETTING_SAVED,
properties: {
setting: `FlowRate_${kind}`,
},
})
}
onBack()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import {
COLORS,
ALIGN_CENTER,
} from '@opentrons/components'
import { ANALYTICS_QUICK_TRANSFER_SETTING_SAVED } from '../../../redux/analytics'
import { getTopPortalEl } from '../../../App/portal'
import { RadioButton } from '../../../atoms/buttons'
import { ChildNavigation } from '../../ChildNavigation'
import { InputField } from '../../../atoms/InputField'
import { useTrackEventWithRobotSerial } from '../../Devices/hooks'
import { ACTIONS } from '../constants'

import type {
Expand All @@ -33,6 +35,7 @@ interface MixProps {
export function Mix(props: MixProps): JSX.Element {
const { kind, onBack, state, dispatch } = props
const { t } = useTranslation('quick_transfer')
const { trackEventWithRobotSerial } = useTrackEventWithRobotSerial()
const keyboardRef = React.useRef(null)

const [mixIsEnabled, setMixIsEnabled] = React.useState<boolean>(
Expand Down Expand Up @@ -85,6 +88,12 @@ export function Mix(props: MixProps): JSX.Element {
type: mixAction,
mixSettings: undefined,
})
trackEventWithRobotSerial({
name: ANALYTICS_QUICK_TRANSFER_SETTING_SAVED,
properties: {
setting: `Mix_${kind}`,
},
})
onBack()
} else {
setCurrentStep(2)
Expand All @@ -97,6 +106,12 @@ export function Mix(props: MixProps): JSX.Element {
type: mixAction,
mixSettings: { mixVolume, repititions: mixReps },
})
trackEventWithRobotSerial({
name: ANALYTICS_QUICK_TRANSFER_SETTING_SAVED,
properties: {
setting: `Mix_${kind}`,
},
})
}
onBack()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import {
COLORS,
ALIGN_CENTER,
} from '@opentrons/components'
import { ANALYTICS_QUICK_TRANSFER_SETTING_SAVED } from '../../../redux/analytics'
import { useNotifyDeckConfigurationQuery } from '../../../resources/deck_configuration'
import { getTopPortalEl } from '../../../App/portal'
import { RadioButton } from '../../../atoms/buttons'
import { ChildNavigation } from '../../ChildNavigation'
import { useTrackEventWithRobotSerial } from '../../Devices/hooks'
import { useBlowOutLocationOptions } from './BlowOut'

import type {
Expand All @@ -36,6 +38,7 @@ interface PipettePathProps {
export function PipettePath(props: PipettePathProps): JSX.Element {
const { onBack, state, dispatch } = props
const { t } = useTranslation('quick_transfer')
const { trackEventWithRobotSerial } = useTrackEventWithRobotSerial()
const keyboardRef = React.useRef(null)
const deckConfig = useNotifyDeckConfigurationQuery().data ?? []

Expand Down Expand Up @@ -95,6 +98,12 @@ export function PipettePath(props: PipettePathProps): JSX.Element {
type: ACTIONS.SET_PIPETTE_PATH,
path: selectedPath,
})
trackEventWithRobotSerial({
name: ANALYTICS_QUICK_TRANSFER_SETTING_SAVED,
properties: {
setting: `PipettePath`,
},
})
onBack()
} else {
setCurrentStep(2)
Expand All @@ -108,6 +117,12 @@ export function PipettePath(props: PipettePathProps): JSX.Element {
disposalVolume,
blowOutLocation,
})
trackEventWithRobotSerial({
name: ANALYTICS_QUICK_TRANSFER_SETTING_SAVED,
properties: {
setting: `PipettePath`,
},
})
onBack()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import {
POSITION_FIXED,
COLORS,
} from '@opentrons/components'
import { ANALYTICS_QUICK_TRANSFER_SETTING_SAVED } from '../../../redux/analytics'
import { getTopPortalEl } from '../../../App/portal'
import { ChildNavigation } from '../../ChildNavigation'
import { InputField } from '../../../atoms/InputField'
import { NumericalKeyboard } from '../../../atoms/SoftwareKeyboard'
import { useTrackEventWithRobotSerial } from '../../Devices/hooks'

import type {
QuickTransferSummaryState,
Expand All @@ -32,6 +34,7 @@ interface TipPositionEntryProps {
export function TipPositionEntry(props: TipPositionEntryProps): JSX.Element {
const { onBack, state, dispatch, kind } = props
const { i18n, t } = useTranslation(['quick_transfer', 'shared'])
const { trackEventWithRobotSerial } = useTrackEventWithRobotSerial()
const keyboardRef = React.useRef(null)

const [tipPosition, setTipPosition] = React.useState<number>(
Expand Down Expand Up @@ -73,6 +76,12 @@ export function TipPositionEntry(props: TipPositionEntryProps): JSX.Element {
type: tipPositionAction,
position: tipPosition,
})
trackEventWithRobotSerial({
name: ANALYTICS_QUICK_TRANSFER_SETTING_SAVED,
properties: {
setting: `TipPosition_${kind}`,
},
})
}
onBack()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import {
COLORS,
ALIGN_CENTER,
} from '@opentrons/components'
import { ANALYTICS_QUICK_TRANSFER_SETTING_SAVED } from '../../../redux/analytics'
import { getTopPortalEl } from '../../../App/portal'
import { RadioButton } from '../../../atoms/buttons'
import { ChildNavigation } from '../../ChildNavigation'
import { InputField } from '../../../atoms/InputField'
import { useTrackEventWithRobotSerial } from '../../Devices/hooks'
import { ACTIONS } from '../constants'

import type {
Expand All @@ -33,6 +35,7 @@ interface TouchTipProps {
export function TouchTip(props: TouchTipProps): JSX.Element {
const { kind, onBack, state, dispatch } = props
const { t } = useTranslation('quick_transfer')
const { trackEventWithRobotSerial } = useTrackEventWithRobotSerial()
const keyboardRef = React.useRef(null)

const [touchTipIsEnabled, setTouchTipIsEnabled] = React.useState<boolean>(
Expand Down Expand Up @@ -77,12 +80,24 @@ export function TouchTip(props: TouchTipProps): JSX.Element {
if (currentStep === 1) {
if (!touchTipIsEnabled) {
dispatch({ type: touchTipAction, position: undefined })
trackEventWithRobotSerial({
name: ANALYTICS_QUICK_TRANSFER_SETTING_SAVED,
properties: {
setting: `TouchTip_${kind}`,
},
})
onBack()
} else {
setCurrentStep(2)
}
} else if (currentStep === 2) {
dispatch({ type: touchTipAction, position: position ?? undefined })
trackEventWithRobotSerial({
name: ANALYTICS_QUICK_TRANSFER_SETTING_SAVED,
properties: {
setting: `TouchTip_${kind}`,
},
})
onBack()
}
}
Expand Down
Loading

0 comments on commit 02ba906

Please sign in to comment.