Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Discover] Track adhoc data views usage #144244

Merged
merged 8 commits into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
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,
} from '@kbn/unified-search-plugin/public';
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';
Expand All @@ -29,6 +31,7 @@ export const useAdHocDataViews = ({
filterManager,
dataViews,
toastNotifications,
trackUiMetric,
}: {
dataView: DataView;
savedSearch: SavedSearch;
Expand All @@ -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[]>(
!dataView.isPersisted() ? [dataView] : []
Expand All @@ -48,8 +52,9 @@ export const useAdHocDataViews = ({
const existing = prev.find((prevDataView) => prevDataView.id === dataView.id);
return existing ? prev : [...prev, dataView];
});
trackUiMetric?.(METRIC_TYPE.CLICK, ADHOC_DATA_VIEW_RENDER_EVENT);
dimaanj marked this conversation as resolved.
Show resolved Hide resolved
}
}, [dataView]);
}, [dataView, trackUiMetric]);

/**
* Takes care of checking data view id references in filters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -133,6 +134,7 @@ export function useDiscoverState({
setUrlTracking,
filterManager,
toastNotifications,
trackUiMetric,
});

const [savedDataViewList, setSavedDataViewList] = useState(initialDataViewList);
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/discover/public/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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<DiscoverGridProps> &
Partial<DocTableProps> & {
Expand Down Expand Up @@ -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.CLICK, ADHOC_DATA_VIEW_RENDER_EVENT);
}

const props: SearchProps = {
columns: this.savedSearch.columns,
savedSearchId: this.savedSearch.id,
Expand Down