Skip to content

Commit

Permalink
[Usage Collection] Kibana Overview Page UI Metrics (#81937)
Browse files Browse the repository at this point in the history
Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
cqliu1 and kibanamachine authored Dec 8, 2020
1 parent 6757b95 commit 99ae137
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/plugins/kibana_overview/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"server": false,
"ui": true,
"requiredPlugins": ["navigation", "data", "home"],
"optionalPlugins": ["newsfeed"],
"optionalPlugins": ["newsfeed", "usageCollection"],
"requiredBundles": ["kibanaReact", "newsfeed"]
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ const mockFeatures = [
},
];

jest.mock('../../lib/ui_metric', () => ({
trackUiMetric: jest.fn(),
}));

const addBasePathMock = jest.fn((path: string) => (path ? path : 'path'));

describe('AddData', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { RedirectAppLinks, useKibana } from '../../../../../../src/plugins/kiban
import { FeatureCatalogueEntry } from '../../../../../../src/plugins/home/public';
// @ts-expect-error untyped component
import { Synopsis } from '../synopsis';
import { METRIC_TYPE, trackUiMetric } from '../../lib/ui_metric';

interface Props {
addBasePath: (path: string) => string;
Expand Down Expand Up @@ -82,6 +83,9 @@ export const AddData: FC<Props> = ({ addBasePath, features }) => {
title={feature.title}
url={addBasePath(feature.path)}
wrapInPanel
onClick={() => {
trackUiMetric(METRIC_TYPE.CLICK, `ingest_data_card_${feature.id}`);
}}
/>
</RedirectAppLinks>
</EuiFlexItem>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ const mockFeatures = [
},
];

jest.mock('../../lib/ui_metric', () => ({
trackUiMetric: jest.fn(),
}));

const addBasePathMock = jest.fn((path: string) => (path ? path : 'path'));

describe('ManageData', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { RedirectAppLinks, useKibana } from '../../../../../../src/plugins/kiban
import { FeatureCatalogueEntry } from '../../../../../../src/plugins/home/public';
// @ts-expect-error untyped component
import { Synopsis } from '../synopsis';
import { METRIC_TYPE, trackUiMetric } from '../../lib/ui_metric';

interface Props {
addBasePath: (path: string) => string;
Expand Down Expand Up @@ -68,6 +69,9 @@ export const ManageData: FC<Props> = ({ addBasePath, features }) => {
title={feature.title}
url={addBasePath(feature.path)}
wrapInPanel
onClick={() => {
trackUiMetric(METRIC_TYPE.CLICK, `ingest_data_card_${feature.id}`);
}}
/>
</RedirectAppLinks>
</EuiFlexItem>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ jest.mock('../../../../../../src/plugins/kibana_react/public', () => ({
OverviewPageHeader: jest.fn().mockReturnValue(<></>),
}));

jest.mock('../../lib/ui_metric', () => ({
trackUiMetric: jest.fn(),
}));

afterAll(() => jest.clearAllMocks());

const mockNewsFetchResult = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import { AddData } from '../add_data';
import { GettingStarted } from '../getting_started';
import { ManageData } from '../manage_data';
import { NewsFeed } from '../news_feed';
import { METRIC_TYPE, trackUiMetric } from '../../lib/ui_metric';

const sortByOrder = (featureA: FeatureCatalogueEntry, featureB: FeatureCatalogueEntry) =>
(featureA.order || Infinity) - (featureB.order || Infinity);
Expand Down Expand Up @@ -108,6 +109,9 @@ export const Overview: FC<Props> = ({ newsFetchResult, solutions, features }) =>
<EuiCard
description={app?.subtitle || ''}
href={addBasePath(app.path)}
onClick={() => {
trackUiMetric(METRIC_TYPE.CLICK, `app_card_${appId}`);
}}
image={addBasePath(
`/plugins/${PLUGIN_ID}/assets/kibana_${appId}_${IS_DARK_THEME ? 'dark' : 'light'}.svg`
)}
Expand Down Expand Up @@ -222,6 +226,9 @@ export const Overview: FC<Props> = ({ newsFetchResult, solutions, features }) =>
title={title}
titleElement="h3"
titleSize="xs"
onClick={() => {
trackUiMetric(METRIC_TYPE.CLICK, `solution_panel_${id}`);
}}
/>
</RedirectAppLinks>
</EuiFlexItem>
Expand Down Expand Up @@ -252,7 +259,16 @@ export const Overview: FC<Props> = ({ newsFetchResult, solutions, features }) =>

<EuiHorizontalRule margin="xl" aria-hidden="true" />

<OverviewPageFooter addBasePath={addBasePath} path={PLUGIN_PATH} />
<OverviewPageFooter
addBasePath={addBasePath}
path={PLUGIN_PATH}
onSetDefaultRoute={() => {
trackUiMetric(METRIC_TYPE.CLICK, 'set_kibana_overview_as_default_route');
}}
onChangeDefaultRoute={() => {
trackUiMetric(METRIC_TYPE.CLICK, 'change_to_different_default_route');
}}
/>
</div>
</main>
);
Expand Down
37 changes: 37 additions & 0 deletions src/plugins/kibana_overview/public/lib/ui_metric.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { UiCounterMetricType, METRIC_TYPE } from '@kbn/analytics';
import { UsageCollectionSetup } from 'src/plugins/usage_collection/public';

export { METRIC_TYPE };

export let reportUiCounter: UsageCollectionSetup['reportUiCounter'] | undefined;

export function init(_reportUiCounter: UsageCollectionSetup['reportUiCounter']): void {
reportUiCounter = _reportUiCounter;
}

export function trackUiMetric(metricType: UiCounterMetricType, name: string | string[]) {
if (!reportUiCounter) {
return;
}

reportUiCounter('kibana_overview', metricType, name);
}
7 changes: 6 additions & 1 deletion src/plugins/kibana_overview/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
AppPluginStartDependencies,
} from './types';
import { PLUGIN_ID, PLUGIN_NAME, PLUGIN_PATH, PLUGIN_ICON } from '../common';
import { init as initStatsReporter } from './lib/ui_metric';

export class KibanaOverviewPlugin
implements
Expand All @@ -47,8 +48,12 @@ export class KibanaOverviewPlugin
> {
public setup(
core: CoreSetup<AppPluginStartDependencies>,
{ home }: AppPluginSetupDependencies
{ home, usageCollection }: AppPluginSetupDependencies
): KibanaOverviewPluginSetup {
if (usageCollection) {
initStatsReporter(usageCollection.reportUiCounter);
}

const appUpdater$ = from(core.getStartServices()).pipe(
switchMap(([coreDeps]) => coreDeps.chrome.navLinks.getNavLinks$()),
map((navLinks) => {
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/kibana_overview/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { HomePublicPluginSetup, HomePublicPluginStart } from 'src/plugins/home/p
import { NavigationPublicPluginStart } from 'src/plugins/navigation/public';
import { DataPublicPluginStart } from 'src/plugins/data/public';
import { NewsfeedPublicPluginStart } from 'src/plugins/newsfeed/public';
import { UsageCollectionSetup } from 'src/plugins/usage_collection/public';

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface KibanaOverviewPluginSetup {}
Expand All @@ -30,6 +31,7 @@ export interface KibanaOverviewPluginStart {}

export interface AppPluginSetupDependencies {
home: HomePublicPluginSetup;
usageCollection?: UsageCollectionSetup;
}

export interface AppPluginStartDependencies {
Expand Down

0 comments on commit 99ae137

Please sign in to comment.