@@ -36,6 +36,21 @@ interface SandboxPageProps {
3636 availableSandboxes : SandboxLab [ ]
3737 otherSandboxes : SandboxLab [ ]
3838}
39+ export const trackSandboxInteraction = (
40+ interactionType : string ,
41+ sandboxId : string ,
42+ additionalProps : Record < string , unknown > = { }
43+ ) => {
44+ if ( typeof window !== 'undefined' && posthog ?. capture ) {
45+ posthog . capture ( SANDBOX_EVENT . SANDBOX_OPEN , {
46+ interaction_type : interactionType ,
47+ sandbox_id : sandboxId ,
48+ ...additionalProps ,
49+ timestamp : new Date ( ) . toISOString ( ) ,
50+ page_url : window . location . href ,
51+ } )
52+ }
53+ }
3954
4055const trackSandboxPageError = (
4156 errorType : string ,
@@ -70,12 +85,17 @@ export const SandboxView = ({
7085 const handleLabClick = useCallback (
7186 ( lab : SandboxLab ) => {
7287 try {
88+ trackSandboxInteraction ( SANDBOX_EVENT . SANDBOX_OPEN , lab . labId , {
89+ lab_title : lab . title ,
90+ products : lab . products ,
91+ } )
92+
7393 const primaryProduct = lab . products [ 0 ]
7494 if ( primaryProduct !== product . slug ) {
7595 // Redirect to the lab's primary product sandbox page with auto-launch
7696 const targetUrl = `/${ primaryProduct } /sandbox?launch=${ lab . labId } `
7797
78- trackSandboxEvent ( SANDBOX_EVENT . SANDBOX_STARTED , {
98+ trackSandboxEvent ( SANDBOX_EVENT . SANDBOX_OPEN , {
7999 labId : lab . labId ,
80100 page : targetUrl ,
81101 } )
@@ -86,7 +106,7 @@ export const SandboxView = ({
86106
87107 if ( hasConfigError ) {
88108 trackSandboxPageError (
89- 'config_error_lab_launch' ,
109+ SANDBOX_EVENT . SANDBOX_ERROR ,
90110 'Cannot launch lab due to configuration error' ,
91111 {
92112 lab_id : lab . labId ,
@@ -106,7 +126,7 @@ export const SandboxView = ({
106126
107127 if ( ! openLab ) {
108128 trackSandboxPageError (
109- 'open_lab_function_missing' ,
129+ SANDBOX_EVENT . SANDBOX_ERROR ,
110130 'openLab function is not available' ,
111131 {
112132 lab_id : lab . labId ,
@@ -128,7 +148,7 @@ export const SandboxView = ({
128148
129149 if ( ! embedLabId ) {
130150 trackSandboxPageError (
131- 'missing_lab_id' ,
151+ SANDBOX_EVENT . SANDBOX_ERROR ,
132152 'Lab embed ID is missing or invalid' ,
133153 {
134154 lab_id : lab . labId ,
@@ -149,7 +169,7 @@ export const SandboxView = ({
149169 openLab ( embedLabId )
150170 setActive ( true )
151171
152- trackSandboxEvent ( SANDBOX_EVENT . SANDBOX_STARTED , {
172+ trackSandboxEvent ( SANDBOX_EVENT . SANDBOX_OPEN , {
153173 labId : lab . labId ,
154174 page : `/${ product . slug } /sandbox` ,
155175 } )
@@ -236,7 +256,7 @@ export const SandboxView = ({
236256 )
237257 } catch ( error ) {
238258 trackSandboxPageError (
239- 'documentation_render_failed' ,
259+ SANDBOX_EVENT . SANDBOX_ERROR ,
240260 'Failed to render sandbox documentation' ,
241261 {
242262 error_message : error instanceof Error ? error . message : String ( error ) ,
@@ -313,6 +333,7 @@ export const SandboxView = ({
313333 labId = { lab . labId }
314334 products = { lab . products }
315335 onLaunch = { ( ) => handleLabClick ( lab ) }
336+ clickBehavior = "button"
316337 />
317338 )
318339 } ) }
0 commit comments