diff --git a/src/plugins/discover/public/application/main/hooks/use_adhoc_data_views.ts b/src/plugins/discover/public/application/main/hooks/use_adhoc_data_views.ts index fdd6624200711..e3782c698fd33 100644 --- a/src/plugins/discover/public/application/main/hooks/use_adhoc_data_views.ts +++ b/src/plugins/discover/public/application/main/hooks/use_adhoc_data_views.ts @@ -9,6 +9,7 @@ import { useCallback, useEffect, useState } from 'react'; import type { DataView, DataViewsContract } from '@kbn/data-views-plugin/public'; import { SavedSearch } from '@kbn/saved-search-plugin/public'; +import { METRIC_TYPE } from '@kbn/analytics'; import { UPDATE_FILTER_REFERENCES_ACTION, UPDATE_FILTER_REFERENCES_TRIGGER, @@ -16,6 +17,7 @@ import { import { ActionExecutionContext } from '@kbn/ui-actions-plugin/public'; import type { FilterManager } from '@kbn/data-plugin/public'; import type { ToastsStart } from '@kbn/core-notifications-browser'; +import { ADHOC_DATA_VIEW_RENDER_EVENT } from '../../../constants'; import { getUiActions } from '../../../kibana_services'; import { useConfirmPersistencePrompt } from '../../../hooks/use_confirm_persistence_prompt'; import { GetStateReturn } from '../services/discover_state'; @@ -29,6 +31,7 @@ export const useAdHocDataViews = ({ filterManager, dataViews, toastNotifications, + trackUiMetric, }: { dataView: DataView; savedSearch: SavedSearch; @@ -37,6 +40,7 @@ export const useAdHocDataViews = ({ dataViews: DataViewsContract; filterManager: FilterManager; toastNotifications: ToastsStart; + trackUiMetric?: (metricType: string, eventName: string | string[], count?: number) => void; }) => { const [adHocDataViewList, setAdHocDataViewList] = useState( !dataView.isPersisted() ? [dataView] : [] @@ -48,8 +52,9 @@ export const useAdHocDataViews = ({ const existing = prev.find((prevDataView) => prevDataView.id === dataView.id); return existing ? prev : [...prev, dataView]; }); + trackUiMetric?.(METRIC_TYPE.COUNT, ADHOC_DATA_VIEW_RENDER_EVENT); } - }, [dataView]); + }, [dataView, trackUiMetric]); /** * Takes care of checking data view id references in filters diff --git a/src/plugins/discover/public/application/main/hooks/use_discover_state.ts b/src/plugins/discover/public/application/main/hooks/use_discover_state.ts index d050ce414de39..8d40b20fbc9cd 100644 --- a/src/plugins/discover/public/application/main/hooks/use_discover_state.ts +++ b/src/plugins/discover/public/application/main/hooks/use_discover_state.ts @@ -44,7 +44,8 @@ export function useDiscoverState({ setExpandedDoc: (doc?: DataTableRecord) => void; dataViewList: DataViewListItem[]; }) { - const { uiSettings, data, filterManager, dataViews, toastNotifications } = services; + const { uiSettings, data, filterManager, dataViews, toastNotifications, trackUiMetric } = + services; const useNewFieldsApi = useMemo(() => !uiSettings.get(SEARCH_FIELDS_FROM_SOURCE), [uiSettings]); const { timefilter } = data.query.timefilter; @@ -133,6 +134,7 @@ export function useDiscoverState({ setUrlTracking, filterManager, toastNotifications, + trackUiMetric, }); const [savedDataViewList, setSavedDataViewList] = useState(initialDataViewList); diff --git a/src/plugins/discover/public/constants.ts b/src/plugins/discover/public/constants.ts index 1a36ca6972a51..038b0eb678ec1 100644 --- a/src/plugins/discover/public/constants.ts +++ b/src/plugins/discover/public/constants.ts @@ -6,4 +6,6 @@ * Side Public License, v 1. */ +export const ADHOC_DATA_VIEW_RENDER_EVENT = 'ad_hoc_data_view'; + export const SEARCH_SESSION_ID_QUERY_PARAM = 'searchSessionId'; diff --git a/src/plugins/discover/public/embeddable/saved_search_embeddable.tsx b/src/plugins/discover/public/embeddable/saved_search_embeddable.tsx index 92fe7a1de5206..2fdf48086a75a 100644 --- a/src/plugins/discover/public/embeddable/saved_search_embeddable.tsx +++ b/src/plugins/discover/public/embeddable/saved_search_embeddable.tsx @@ -34,6 +34,7 @@ import { DataView, DataViewField } from '@kbn/data-views-plugin/public'; import { UiActionsStart } from '@kbn/ui-actions-plugin/public'; import { KibanaContextProvider, KibanaThemeProvider } from '@kbn/kibana-react-plugin/public'; import { SavedSearch } from '@kbn/saved-search-plugin/public'; +import { METRIC_TYPE } from '@kbn/analytics'; import { getSortForEmbeddable, SortPair } from '../utils/sorting'; import { RecordRawType } from '../application/main/hooks/use_saved_search'; import { buildDataTableRecord } from '../utils/build_data_record'; @@ -60,6 +61,7 @@ import { updateSearchSource } from './utils/update_search_source'; import { FieldStatisticsTable } from '../application/main/components/field_stats_table'; import { getRawRecordType } from '../application/main/utils/get_raw_record_type'; import { fetchSql } from '../application/main/utils/fetch_sql'; +import { ADHOC_DATA_VIEW_RENDER_EVENT } from '../constants'; export type SearchProps = Partial & Partial & { @@ -302,6 +304,11 @@ export class SavedSearchEmbeddable } const sort = this.getSort(this.savedSearch.sort, dataView); + if (!dataView.isPersisted()) { + // one used adhoc data view + this.services.trackUiMetric?.(METRIC_TYPE.COUNT, ADHOC_DATA_VIEW_RENDER_EVENT); + } + const props: SearchProps = { columns: this.savedSearch.columns, savedSearchId: this.savedSearch.id,