import { UiCounterMetricType , 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 ; export function init ( _usageCollection ) { usageCollection = _usageCollection ; } export function trackUiMetric ( metricType , name ) { if ( ! usageCollection ) { return ; } const { reportUiCounter } = usageCollection ; reportUiCounter ( UIM_APP_NAME , metricType , name ) ; } /**
 * Transparently return provided request Promise, while allowing us to track
 * a successful completion of the request.
 */ export function trackUserRequest ( request , eventName ) { return request . then ( ( response ) => { trackUiMetric ( METRIC_TYPE . COUNT , eventName ) ; return response ; } ) ; }