Skip to content

Commit

Permalink
Add create_first_engine_button telemetry tracking to EmptyState
Browse files Browse the repository at this point in the history
  • Loading branch information
cee-chen committed Jun 4, 2020
1 parent 73ad80b commit dabdeaa
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import React, { useContext } from 'react';
import { EuiPage, EuiPageBody, EuiPageContent, EuiEmptyPrompt, EuiButton } from '@elastic/eui';

import { sendTelemetry } from '../../../shared/telemetry';
import { SetAppSearchBreadcrumbs as SetBreadcrumbs } from '../../../shared/kibana_breadcrumbs';
import { KibanaContext, IKibanaContext } from '../../../index';

Expand All @@ -15,7 +16,19 @@ import { EngineOverviewHeader } from '../engine_overview_header';
import './empty_states.scss';

export const EmptyState: React.FC<> = () => {
const { enterpriseSearchUrl } = useContext(KibanaContext) as IKibanaContext;
const { enterpriseSearchUrl, http } = useContext(KibanaContext) as IKibanaContext;

const buttonProps = {
href: `${enterpriseSearchUrl}/as/engines/new`,
target: '_blank',
onClick: () =>
sendTelemetry({
http,
product: 'app_search',
action: 'clicked',
metric: 'create_first_engine_button',
}),
};

return (
<EuiPage restrictWidth className="empty-state">
Expand All @@ -35,12 +48,7 @@ export const EmptyState: React.FC<> = () => {
</p>
}
actions={
<EuiButton
iconType="popout"
fill
href={`${enterpriseSearchUrl}/as/engines/new`}
target="_blank"
>
<EuiButton iconType="popout" fill {...buttonProps}>
Create your first Engine
</EuiButton>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ import '../../../__mocks__/shallow_usecontext.mock';

import React from 'react';
import { shallow } from 'enzyme';
import { EuiEmptyPrompt, EuiCode, EuiLoadingContent } from '@elastic/eui';
import { EuiEmptyPrompt, EuiButton, EuiCode, EuiLoadingContent } from '@elastic/eui';

jest.mock('../../utils/get_username', () => ({ getUserName: jest.fn() }));
import { getUserName } from '../../utils/get_username';

jest.mock('../../../shared/telemetry', () => ({
sendTelemetry: jest.fn(),
SendAppSearchTelemetry: jest.fn(),
}));
import { sendTelemetry } from '../../../shared/telemetry';

import { ErrorState, NoUserState, EmptyState, LoadingState } from './';

describe('ErrorState', () => {
Expand Down Expand Up @@ -51,6 +57,16 @@ describe('EmptyState', () => {
expect(prompt).toHaveLength(1);
expect(prompt.prop('title')).toEqual(<h2>There’s nothing here yet</h2>);
});

it('sends telemetry on create first engine click', () => {
const wrapper = shallow(<EmptyState />);
const prompt = wrapper.find(EuiEmptyPrompt).dive();
const button = prompt.find(EuiButton);

button.simulate('click');
expect(sendTelemetry).toHaveBeenCalled();
sendTelemetry.mockClear();
});
});

describe('LoadingState', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe('App Search Telemetry Usage Collector', () => {
'ui_viewed.engines_overview': 20,
'ui_error.cannot_connect': 3,
'ui_error.no_as_account': 4,
'ui_clicked.create_first_engine_button': 40,
'ui_clicked.header_launch_button': 50,
'ui_clicked.engine_table_link': 60,
},
Expand Down Expand Up @@ -67,6 +68,7 @@ describe('App Search Telemetry Usage Collector', () => {
no_as_account: 4,
},
ui_clicked: {
create_first_engine_button: 40,
header_launch_button: 50,
engine_table_link: 60,
},
Expand All @@ -90,6 +92,7 @@ describe('App Search Telemetry Usage Collector', () => {
no_as_account: 0,
},
ui_clicked: {
create_first_engine_button: 0,
header_launch_button: 0,
engine_table_link: 0,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const fetchTelemetryMetrics = async (savedObjects: SavedObjectsServiceStart) =>
no_as_account: 0,
},
ui_clicked: {
create_first_engine_button: 0,
header_launch_button: 0,
engine_table_link: 0,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface ITelemetrySavedObject {
no_as_account: number;
};
ui_clicked: {
create_first_engine_button: number;
header_launch_button: number;
engine_table_link: number;
};
Expand Down Expand Up @@ -55,6 +56,10 @@ export const appSearchTelemetryType: SavedObjectsType = {
},
ui_clicked: {
properties: {
create_first_engine_button: {
type: 'long',
null_value: 0,
},
header_launch_button: {
type: 'long',
null_value: 0,
Expand Down

0 comments on commit dabdeaa

Please sign in to comment.