@@ -15,6 +15,7 @@ import { Controls } from '/app/organisms/Desktop/ProtocolVisualization/Controls'
1515import { DeckView } from '/app/organisms/Desktop/ProtocolVisualization/DeckView'
1616import {
1717 ANALYTICS_LAUNCH_PROTOCOL_VISUALIZATION_SPOTLIGHT_WINDOW ,
18+ ANALYTICS_NOTIFICATION_PROTOCOL_VISUALIZATION_VIEWPORT_SIZES ,
1819 useTrackEvent ,
1920} from '/app/redux/analytics'
2021import {
@@ -59,6 +60,7 @@ export function VisualizerContainer(
5960 const createdDate = new Date ( analysisOutput . createdAt )
6061 const completedProtocolAnalysis = useMostRecentCompletedAnalysis ( runId )
6162 const trackEvent = useTrackEvent ( )
63+ const trackEventRef = useRef ( trackEvent )
6264 const analysis = completedProtocolAnalysis ?? analysisOutput
6365 const { commands, robotType, liquids } = analysis
6466 const [ isPlaying , setIsPlaying ] = useState < boolean > ( false )
@@ -90,6 +92,12 @@ export function VisualizerContainer(
9092 rightWidthRef . current = rightWidth
9193 } , [ rightWidth ] )
9294
95+ // Note: This useEffect is used to update the trackEventRef.current with the trackEvent prop.
96+ // This prevents sending duplicate events when the trackEvent prop changes.
97+ useEffect ( ( ) => {
98+ trackEventRef . current = trackEvent
99+ } , [ trackEvent ] )
100+
93101 // temporarily filter out loadCommands and home commands for the PV MVP
94102 const filteredCommands = commands . filter (
95103 command =>
@@ -281,6 +289,20 @@ export function VisualizerContainer(
281289 }
282290 } , [ dispatch , protocolKey ] )
283291
292+ useEffect ( ( ) => {
293+ return ( ) => {
294+ trackEventRef . current ( {
295+ name : ANALYTICS_NOTIFICATION_PROTOCOL_VISUALIZATION_VIEWPORT_SIZES ,
296+ properties : {
297+ 'Window Width' : window . innerWidth ,
298+ 'Window Height' : window . innerHeight ,
299+ 'Left Column Width' : leftWidthRef . current ,
300+ 'Right Column Width' : rightWidthRef . current ,
301+ } ,
302+ } )
303+ }
304+ } , [ ] )
305+
284306 return (
285307 < div ref = { containerRef } className = { styles . layout_container } >
286308 { /* Left Column is resizable */ }
0 commit comments