@@ -13,7 +13,7 @@ import '@reach/menu-button/styles.css';
1313import '@reach/tooltip/styles.css' ;
1414
1515import * as React from 'react' ;
16- import { useEffect , useLayoutEffect , useMemo , useRef } from 'react' ;
16+ import { useCallback , useEffect , useLayoutEffect , useMemo , useRef } from 'react' ;
1717import Store from '../store' ;
1818import {
1919 BridgeContext ,
@@ -47,6 +47,7 @@ import type {InspectedElement} from 'react-devtools-shared/src/devtools/views/Co
4747import type { FetchFileWithCaching } from './Components/FetchFileWithCachingContext' ;
4848import type { HookNamesModuleLoaderFunction } from 'react-devtools-shared/src/devtools/views/Components/HookNamesModuleLoaderContext' ;
4949import type { FrontendBridge } from 'react-devtools-shared/src/bridge' ;
50+ import { logEvent } from '../../Logger' ;
5051
5152export type BrowserTheme = 'dark' | 'light' ;
5253export type TabID = 'components' | 'profiler' ;
@@ -152,6 +153,24 @@ export default function DevTools({
152153 tab = overrideTab ;
153154 }
154155
156+ const selectTab = useCallback (
157+ ( tabId : TabID ) => {
158+ // We show the TabBar when DevTools is NOT rendered as a browser extension.
159+ // In this case, we want to capture when people select tabs with the TabBar.
160+ // When DevTools is rendered as an extension, we capture this event when
161+ // the browser devtools panel changes.
162+ if ( showTabBar === true ) {
163+ if ( tabId === 'components' ) {
164+ logEvent ( { event_name : 'selected-components-tab' } ) ;
165+ } else {
166+ logEvent ( { event_name : 'selected-profiler-tab' } ) ;
167+ }
168+ }
169+ setTab ( tabId ) ;
170+ } ,
171+ [ setTab , showTabBar ] ,
172+ ) ;
173+
155174 const options = useMemo (
156175 ( ) => ( {
157176 readOnly : readOnly || false ,
@@ -204,12 +223,12 @@ export default function DevTools({
204223 if ( event . ctrlKey || event . metaKey ) {
205224 switch ( event . key ) {
206225 case '1' :
207- setTab ( tabs [ 0 ] . id ) ;
226+ selectTab ( tabs [ 0 ] . id ) ;
208227 event . preventDefault ( ) ;
209228 event . stopPropagation ( ) ;
210229 break ;
211230 case '2' :
212- setTab ( tabs [ 1 ] . id ) ;
231+ selectTab ( tabs [ 1 ] . id ) ;
213232 event . preventDefault ( ) ;
214233 event . stopPropagation ( ) ;
215234 break ;
@@ -232,6 +251,10 @@ export default function DevTools({
232251 }
233252 } ;
234253 } , [ bridge ] ) ;
254+
255+ useEffect ( ( ) => {
256+ logEvent ( { event_name : 'loaded-dev-tools' } ) ;
257+ } , [ ] ) ;
235258 return (
236259 < BridgeContext . Provider value = { bridge } >
237260 < StoreContext . Provider value = { store } >
@@ -265,7 +288,7 @@ export default function DevTools({
265288 < TabBar
266289 currentTab = { tab }
267290 id = "DevTools"
268- selectTab = { setTab }
291+ selectTab = { selectTab }
269292 tabs = { tabs }
270293 type = "navigation"
271294 />
0 commit comments