Skip to content

Commit 116430c

Browse files
committed
feat(app): add mixpanel track envet for sizes
add mixpanel track envet for sizes close AUTH-2527
1 parent a59c60f commit 116430c

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

app/src/organisms/Desktop/ProtocolVisualization/VisualizerContainer/index.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { Controls } from '/app/organisms/Desktop/ProtocolVisualization/Controls'
1515
import { DeckView } from '/app/organisms/Desktop/ProtocolVisualization/DeckView'
1616
import {
1717
ANALYTICS_LAUNCH_PROTOCOL_VISUALIZATION_SPOTLIGHT_WINDOW,
18+
ANALYTICS_NOTIFICATION_PROTOCOL_VISUALIZATION_VIEWPORT_SIZES,
1819
useTrackEvent,
1920
} from '/app/redux/analytics'
2021
import {
@@ -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 */}

app/src/redux/analytics/constants.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,16 @@ export const ANALYTICS_ODD_APP_ERROR = 'oddError'
4646
export const ANALYTICS_DESKTOP_APP_ERROR = 'desktopAppError'
4747
export const ANALYTICS_NOTIFICATION_PORT_BLOCK_ERROR =
4848
'notificationPortBlockError'
49+
50+
/**
51+
* Protocol Visualization Analytics
52+
*/
4953
export const ANALYTICS_LAUNCH_PROTOCOL_VISUALIZATION =
5054
'launchProtocolVisualization'
5155
export const ANALYTICS_LAUNCH_PROTOCOL_VISUALIZATION_SPOTLIGHT_WINDOW =
5256
'launchProtocolVisualizationSpotlightWindow'
57+
export const ANALYTICS_NOTIFICATION_PROTOCOL_VISUALIZATION_VIEWPORT_SIZES =
58+
'notificationProtocolVisualizationViewportSizes'
5359

5460
const ANALYTICS_PROTOCOL_PROCEED_BUTTON_TEXT = [
5561
ANALYTICS_PROCEED_TO_CAMERA_SETUP_STEP,

0 commit comments

Comments
 (0)