Analytics: add more properties to dashboard list viewed event (#44739)

This commit is contained in:
Artur Wierzbicki
2022-02-02 13:41:10 +04:00
committed by GitHub
parent 925333bfa4
commit 46a34451d5
2 changed files with 58 additions and 10 deletions

View File

@ -1,4 +1,4 @@
import { KeyboardEvent, useEffect, useReducer } from 'react';
import { KeyboardEvent, useReducer } from 'react';
import { getLocationSrv } from '@grafana/runtime';
import { DashboardQuery, DashboardSearchItemType, DashboardSection } from '../types';
import { MOVE_SELECTION_DOWN, MOVE_SELECTION_UP } from '../reducers/actionTypes';
@ -8,6 +8,7 @@ import { useSearch } from './useSearch';
import { locationUtil } from '@grafana/data';
import { useShowDashboardPreviews } from './useShowDashboardPreviews';
import { reportDashboardListViewed } from './useManageDashboards';
import { useDebounce } from 'react-use';
export const useDashboardSearch = (query: DashboardQuery, onCloseSearch: () => void) => {
const reducer = useReducer(searchReducer, dashboardsSearchState);
@ -18,9 +19,27 @@ export const useDashboardSearch = (query: DashboardQuery, onCloseSearch: () => v
dispatch,
} = useSearch<DashboardsSearchState>(query, reducer, { queryParsing: true });
useEffect(() => {
reportDashboardListViewed('dashboard_search', showPreviews, previewFeatureEnabled, query.layout);
}, [showPreviews, previewFeatureEnabled, query.layout]);
useDebounce(
() => {
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>) => {
switch (event.key) {

View File

@ -1,4 +1,4 @@
import { useCallback, useEffect, useMemo, useReducer } from 'react';
import { useCallback, useMemo, useReducer } from 'react';
import { FolderDTO } from 'app/types';
import { contextSrv } from 'app/core/services/context_srv';
import { DashboardQuery, DashboardSection, OnDeleteItems, OnMoveItems, OnToggleChecked, SearchLayout } from '../types';
@ -8,6 +8,7 @@ import { useSearch } from './useSearch';
import { GENERAL_FOLDER_ID } from '../constants';
import { useShowDashboardPreviews } from './useShowDashboardPreviews';
import { reportInteraction } from '@grafana/runtime/src';
import { useDebounce } from 'react-use';
const hasChecked = (section: DashboardSection) => {
return section.checked || section.items.some((item) => item.checked);
@ -17,12 +18,22 @@ export const reportDashboardListViewed = (
dashboardListType: 'manage_dashboards' | 'dashboard_search',
showPreviews: boolean,
previewsEnabled: boolean,
searchLayout: SearchLayout
query: {
layout?: SearchLayout;
starred?: boolean;
sortValue?: string;
query?: string;
tagCount?: number;
}
) => {
const previews = previewsEnabled ? (showPreviews ? 'on' : 'off') : 'feature_disabled';
reportInteraction(`${dashboardListType}_viewed`, {
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();
useEffect(() => {
reportDashboardListViewed('manage_dashboards', showPreviews, previewFeatureEnabled, query.layout);
}, [showPreviews, previewFeatureEnabled, query.layout]);
useDebounce(
() => {
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 {
state: { results, loading, initialLoading, allChecked },