mirror of https://github.com/grafana/grafana.git
				
				
				
			Analytics: add more properties to dashboard list viewed event (#44739)
This commit is contained in:
		
							parent
							
								
									925333bfa4
								
							
						
					
					
						commit
						46a34451d5
					
				|  | @ -1,4 +1,4 @@ | ||||||
| import { KeyboardEvent, useEffect, useReducer } from 'react'; | import { KeyboardEvent, useReducer } from 'react'; | ||||||
| import { getLocationSrv } from '@grafana/runtime'; | import { getLocationSrv } from '@grafana/runtime'; | ||||||
| import { DashboardQuery, DashboardSearchItemType, DashboardSection } from '../types'; | import { DashboardQuery, DashboardSearchItemType, DashboardSection } from '../types'; | ||||||
| import { MOVE_SELECTION_DOWN, MOVE_SELECTION_UP } from '../reducers/actionTypes'; | import { MOVE_SELECTION_DOWN, MOVE_SELECTION_UP } from '../reducers/actionTypes'; | ||||||
|  | @ -8,6 +8,7 @@ import { useSearch } from './useSearch'; | ||||||
| import { locationUtil } from '@grafana/data'; | import { locationUtil } from '@grafana/data'; | ||||||
| import { useShowDashboardPreviews } from './useShowDashboardPreviews'; | import { useShowDashboardPreviews } from './useShowDashboardPreviews'; | ||||||
| import { reportDashboardListViewed } from './useManageDashboards'; | import { reportDashboardListViewed } from './useManageDashboards'; | ||||||
|  | import { useDebounce } from 'react-use'; | ||||||
| 
 | 
 | ||||||
| export const useDashboardSearch = (query: DashboardQuery, onCloseSearch: () => void) => { | export const useDashboardSearch = (query: DashboardQuery, onCloseSearch: () => void) => { | ||||||
|   const reducer = useReducer(searchReducer, dashboardsSearchState); |   const reducer = useReducer(searchReducer, dashboardsSearchState); | ||||||
|  | @ -18,9 +19,27 @@ export const useDashboardSearch = (query: DashboardQuery, onCloseSearch: () => v | ||||||
|     dispatch, |     dispatch, | ||||||
|   } = useSearch<DashboardsSearchState>(query, reducer, { queryParsing: true }); |   } = useSearch<DashboardsSearchState>(query, reducer, { queryParsing: true }); | ||||||
| 
 | 
 | ||||||
|   useEffect(() => { |   useDebounce( | ||||||
|     reportDashboardListViewed('dashboard_search', showPreviews, previewFeatureEnabled, query.layout); |     () => { | ||||||
|   }, [showPreviews, previewFeatureEnabled, query.layout]); |       reportDashboardListViewed('dashboard_search', showPreviews, previewFeatureEnabled, { | ||||||
|  |         layout: query.layout, | ||||||
|  |         starred: query.starred, | ||||||
|  |         sortValue: query.sort?.value, | ||||||
|  |         query: query.query, | ||||||
|  |         tagCount: query.tag?.length, | ||||||
|  |       }); | ||||||
|  |     }, | ||||||
|  |     1000, | ||||||
|  |     [ | ||||||
|  |       showPreviews, | ||||||
|  |       previewFeatureEnabled, | ||||||
|  |       query.layout, | ||||||
|  |       query.starred, | ||||||
|  |       query.sort?.value, | ||||||
|  |       query.query?.length, | ||||||
|  |       query.tag?.length, | ||||||
|  |     ] | ||||||
|  |   ); | ||||||
| 
 | 
 | ||||||
|   const onKeyDown = (event: KeyboardEvent<HTMLInputElement>) => { |   const onKeyDown = (event: KeyboardEvent<HTMLInputElement>) => { | ||||||
|     switch (event.key) { |     switch (event.key) { | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { useCallback, useEffect, useMemo, useReducer } from 'react'; | import { useCallback, useMemo, useReducer } from 'react'; | ||||||
| import { FolderDTO } from 'app/types'; | import { FolderDTO } from 'app/types'; | ||||||
| import { contextSrv } from 'app/core/services/context_srv'; | import { contextSrv } from 'app/core/services/context_srv'; | ||||||
| import { DashboardQuery, DashboardSection, OnDeleteItems, OnMoveItems, OnToggleChecked, SearchLayout } from '../types'; | import { DashboardQuery, DashboardSection, OnDeleteItems, OnMoveItems, OnToggleChecked, SearchLayout } from '../types'; | ||||||
|  | @ -8,6 +8,7 @@ import { useSearch } from './useSearch'; | ||||||
| import { GENERAL_FOLDER_ID } from '../constants'; | import { GENERAL_FOLDER_ID } from '../constants'; | ||||||
| import { useShowDashboardPreviews } from './useShowDashboardPreviews'; | import { useShowDashboardPreviews } from './useShowDashboardPreviews'; | ||||||
| import { reportInteraction } from '@grafana/runtime/src'; | import { reportInteraction } from '@grafana/runtime/src'; | ||||||
|  | import { useDebounce } from 'react-use'; | ||||||
| 
 | 
 | ||||||
| const hasChecked = (section: DashboardSection) => { | const hasChecked = (section: DashboardSection) => { | ||||||
|   return section.checked || section.items.some((item) => item.checked); |   return section.checked || section.items.some((item) => item.checked); | ||||||
|  | @ -17,12 +18,22 @@ export const reportDashboardListViewed = ( | ||||||
|   dashboardListType: 'manage_dashboards' | 'dashboard_search', |   dashboardListType: 'manage_dashboards' | 'dashboard_search', | ||||||
|   showPreviews: boolean, |   showPreviews: boolean, | ||||||
|   previewsEnabled: boolean, |   previewsEnabled: boolean, | ||||||
|   searchLayout: SearchLayout |   query: { | ||||||
|  |     layout?: SearchLayout; | ||||||
|  |     starred?: boolean; | ||||||
|  |     sortValue?: string; | ||||||
|  |     query?: string; | ||||||
|  |     tagCount?: number; | ||||||
|  |   } | ||||||
| ) => { | ) => { | ||||||
|   const previews = previewsEnabled ? (showPreviews ? 'on' : 'off') : 'feature_disabled'; |   const previews = previewsEnabled ? (showPreviews ? 'on' : 'off') : 'feature_disabled'; | ||||||
|   reportInteraction(`${dashboardListType}_viewed`, { |   reportInteraction(`${dashboardListType}_viewed`, { | ||||||
|     previews, |     previews, | ||||||
|     layout: searchLayout, |     layout: query.layout, | ||||||
|  |     starredFilter: query.starred ?? false, | ||||||
|  |     sort: query.sortValue ?? '', | ||||||
|  |     tagCount: query.tagCount ?? 0, | ||||||
|  |     queryLength: query.query?.length ?? 0, | ||||||
|   }); |   }); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | @ -37,9 +48,27 @@ export const useManageDashboards = ( | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|   const { showPreviews, onShowPreviewsChange, previewFeatureEnabled } = useShowDashboardPreviews(); |   const { showPreviews, onShowPreviewsChange, previewFeatureEnabled } = useShowDashboardPreviews(); | ||||||
|   useEffect(() => { |   useDebounce( | ||||||
|     reportDashboardListViewed('manage_dashboards', showPreviews, previewFeatureEnabled, query.layout); |     () => { | ||||||
|   }, [showPreviews, previewFeatureEnabled, query.layout]); |       reportDashboardListViewed('manage_dashboards', showPreviews, previewFeatureEnabled, { | ||||||
|  |         layout: query.layout, | ||||||
|  |         starred: query.starred, | ||||||
|  |         sortValue: query.sort?.value, | ||||||
|  |         query: query.query, | ||||||
|  |         tagCount: query.tag?.length, | ||||||
|  |       }); | ||||||
|  |     }, | ||||||
|  |     1000, | ||||||
|  |     [ | ||||||
|  |       showPreviews, | ||||||
|  |       previewFeatureEnabled, | ||||||
|  |       query.layout, | ||||||
|  |       query.starred, | ||||||
|  |       query.sort?.value, | ||||||
|  |       query.query?.length, | ||||||
|  |       query.tag?.length, | ||||||
|  |     ] | ||||||
|  |   ); | ||||||
| 
 | 
 | ||||||
|   const { |   const { | ||||||
|     state: { results, loading, initialLoading, allChecked }, |     state: { results, loading, initialLoading, allChecked }, | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue