diff --git a/x-pack/plugins/remote_clusters/public/application/app.js b/x-pack/plugins/remote_clusters/public/application/app.js index a7977906631050..483b2f5b97e273 100644 --- a/x-pack/plugins/remote_clusters/public/application/app.js +++ b/x-pack/plugins/remote_clusters/public/application/app.js @@ -9,7 +9,7 @@ import PropTypes from 'prop-types'; import { Switch, Route, Redirect, withRouter } from 'react-router-dom'; import { CRUD_APP_BASE_PATH, UIM_APP_LOAD } from './constants'; -import { registerRouter, setUserHasLeftApp, trackUiMetric } from './services'; +import { registerRouter, setUserHasLeftApp, trackUiMetric, METRIC_TYPE } from './services'; import { RemoteClusterList, RemoteClusterAdd, RemoteClusterEdit } from './sections'; class AppComponent extends Component { @@ -35,7 +35,7 @@ class AppComponent extends Component { } componentDidMount() { - trackUiMetric('LOADED', UIM_APP_LOAD); + trackUiMetric(METRIC_TYPE.LOADED, UIM_APP_LOAD); } componentWillUnmount() { diff --git a/x-pack/plugins/remote_clusters/public/application/sections/remote_cluster_list/remote_cluster_table/remote_cluster_table.js b/x-pack/plugins/remote_clusters/public/application/sections/remote_cluster_list/remote_cluster_table/remote_cluster_table.js index d337109aec7118..73f32fe8bca5b6 100644 --- a/x-pack/plugins/remote_clusters/public/application/sections/remote_cluster_list/remote_cluster_table/remote_cluster_table.js +++ b/x-pack/plugins/remote_clusters/public/application/sections/remote_cluster_list/remote_cluster_table/remote_cluster_table.js @@ -22,7 +22,7 @@ import { import { CRUD_APP_BASE_PATH, UIM_SHOW_DETAILS_CLICK } from '../../../constants'; import { PROXY_MODE } from '../../../../../common/constants'; -import { getRouterLinkProps, trackUiMetric } from '../../../services'; +import { getRouterLinkProps, trackUiMetric, METRIC_TYPE } from '../../../services'; import { ConnectionStatus, RemoveClusterButtonProvider } from '../components'; export class RemoteClusterTable extends Component { @@ -89,7 +89,7 @@ export class RemoteClusterTable extends Component { { - trackUiMetric('CLICK', UIM_SHOW_DETAILS_CLICK); + trackUiMetric(METRIC_TYPE.CLICK, UIM_SHOW_DETAILS_CLICK); openDetailPanel(name); }} > diff --git a/x-pack/plugins/remote_clusters/public/application/services/index.js b/x-pack/plugins/remote_clusters/public/application/services/index.js index 67c458adbe8aa4..387a04b6e5d8c3 100644 --- a/x-pack/plugins/remote_clusters/public/application/services/index.js +++ b/x-pack/plugins/remote_clusters/public/application/services/index.js @@ -22,4 +22,4 @@ export { getRouterLinkProps, } from './routing'; -export { trackUiMetric } from './ui_metric'; +export { trackUiMetric, METRIC_TYPE } from './ui_metric'; diff --git a/x-pack/plugins/remote_clusters/public/application/services/ui_metric.ts b/x-pack/plugins/remote_clusters/public/application/services/ui_metric.ts index cc83f18e00a4e6..4fc3c438e76d6c 100644 --- a/x-pack/plugins/remote_clusters/public/application/services/ui_metric.ts +++ b/x-pack/plugins/remote_clusters/public/application/services/ui_metric.ts @@ -3,22 +3,24 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ - +import { UiStatsMetricType, METRIC_TYPE } from '@kbn/analytics'; import { UsageCollectionSetup } from 'src/plugins/usage_collection/public'; import { UIM_APP_NAME } from '../constants'; +export { METRIC_TYPE }; + export let usageCollection: UsageCollectionSetup | undefined; export function init(_usageCollection: UsageCollectionSetup): void { usageCollection = _usageCollection; } -export function trackUiMetric(type: 'COUNT' | 'CLICK' | 'LOADED', name: string) { +export function trackUiMetric(metricType: UiStatsMetricType, name: string) { if (!usageCollection) { return; } - const { reportUiStats, METRIC_TYPE } = usageCollection; - reportUiStats(UIM_APP_NAME, METRIC_TYPE[type], name); + const { reportUiStats } = usageCollection; + reportUiStats(UIM_APP_NAME, metricType, name); } /** @@ -28,7 +30,7 @@ export function trackUiMetric(type: 'COUNT' | 'CLICK' | 'LOADED', name: string) export function trackUserRequest(request: Promise, eventName: string) { // Only track successful actions. return request.then((response: any) => { - trackUiMetric('COUNT', eventName); + trackUiMetric(METRIC_TYPE.COUNT, eventName); // We return the response immediately without waiting for the tracking request to resolve, // to avoid adding additional latency. return response; diff --git a/x-pack/plugins/remote_clusters/public/application/store/actions/remove_clusters.js b/x-pack/plugins/remote_clusters/public/application/store/actions/remove_clusters.js index 4e613bde4aa8b2..8e22eac8b292bd 100644 --- a/x-pack/plugins/remote_clusters/public/application/store/actions/remove_clusters.js +++ b/x-pack/plugins/remote_clusters/public/application/store/actions/remove_clusters.js @@ -9,7 +9,11 @@ import { i18n } from '@kbn/i18n'; import { toasts } from '../../services/notification'; import { UIM_CLUSTER_REMOVE, UIM_CLUSTER_REMOVE_MANY } from '../../constants'; -import { removeClusterRequest as sendRemoveClusterRequest, trackUiMetric } from '../../services'; +import { + removeClusterRequest as sendRemoveClusterRequest, + trackUiMetric, + METRIC_TYPE, +} from '../../services'; import { REMOVE_CLUSTERS_START, REMOVE_CLUSTERS_FINISH } from '../action_types'; @@ -72,7 +76,10 @@ export const removeClusters = names => async (dispatch, getState) => { if (itemsDeleted.length > 0) { // Only track successful requests. - trackUiMetric('COUNT', names.length > 1 ? UIM_CLUSTER_REMOVE_MANY : UIM_CLUSTER_REMOVE); + trackUiMetric( + METRIC_TYPE.COUNT, + names.length > 1 ? UIM_CLUSTER_REMOVE_MANY : UIM_CLUSTER_REMOVE + ); if (itemsDeleted.length === 1) { toasts.addSuccess(