Skip to content

Commit

Permalink
Track a more complete set of metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
wylieconlon committed Oct 12, 2019
1 parent 5281cbd commit bf26faa
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 15 deletions.
12 changes: 10 additions & 2 deletions x-pack/legacy/plugins/lens/public/app_plugin/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,16 @@ export function App({
screenTitle={'lens'}
onQuerySubmit={payload => {
const { dateRange, query } = payload;

if (
dateRange.from !== state.dateRange.fromDate ||
dateRange.to !== state.dateRange.toDate
) {
trackUiEvent('app_date_change');
} else {
trackUiEvent('app_query_change');
}

setState(s => ({
...s,
dateRange: {
Expand All @@ -226,8 +236,6 @@ export function App({
},
query: query || s.query,
}));

trackUiEvent('date_or_query_change');
}}
appName={'lens'}
indexPatterns={state.indexPatternsForTopNav}
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/lens/public/app_plugin/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class AppPlugin {
};

function NotFound() {
trackUiEvent('loaded-404');
trackUiEvent('loaded_404');
return <FormattedMessage id="xpack.lens.app404" defaultMessage="404 Not Found" />;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function ChartSwitch(props: Props) {
const commitSelection = (selection: VisualizationSelection) => {
setFlyoutOpen(false);

trackUiEvent(`chart-switch-${selection.subVisualizationId || selection.visualizationId}`);
trackUiEvent(`chart_switch`);

switchToSuggestion(
props.framePublicAPI,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { getSuggestions, switchToSuggestion } from './suggestion_helpers';
import { ExpressionRenderer } from '../../../../../../../src/legacy/core_plugins/expressions/public';
import { prependDatasourceExpression, prependKibanaContext } from './expression_helpers';
import { debouncedComponent } from '../../debounced_component';
import { trackSuggestionEvent } from '../../lens_ui_telemetry';
import { trackUiEvent, trackSuggestionEvent } from '../../lens_ui_telemetry';

const MAX_SUGGESTIONS_DISPLAYED = 5;

Expand Down Expand Up @@ -227,8 +227,8 @@ export function SuggestionPanel({
}

function rollbackToCurrentVisualization() {
trackSuggestionEvent('rollback');
if (lastSelectedSuggestion !== -1) {
trackSuggestionEvent('back_to_current');
setLastSelectedSuggestion(-1);
dispatch({
type: 'ROLLBACK_SUGGESTION',
Expand Down Expand Up @@ -263,6 +263,7 @@ export function SuggestionPanel({
data-test-subj="lensSubmitSuggestion"
size="xs"
onClick={() => {
trackUiEvent('suggestion_confirmed');
dispatch({
type: 'SUBMIT_SUGGESTION',
});
Expand Down Expand Up @@ -309,10 +310,11 @@ export function SuggestionPanel({
ExpressionRenderer={ExpressionRendererComponent}
key={index}
onSelect={() => {
trackUiEvent('suggestion_clicked');
if (lastSelectedSuggestion === index) {
rollbackToCurrentVisualization();
} else {
trackSuggestionEvent(`${suggestion.visualizationId}-${suggestion.changeType}`);
trackSuggestionEvent(`index_${index}_of_${suggestions.length}`);
setLastSelectedSuggestion(index);
switchToSuggestion(frame, dispatch, suggestion);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export function InnerWorkspacePanel({
core,
ExpressionRenderer: ExpressionRendererComponent,
}: WorkspacePanelProps) {
const [isEmpty, setIsEmpty] = useState(true);
const IS_DARK_THEME = core.uiSettings.get('theme:darkMode');
const emptyStateGraphicURL = IS_DARK_THEME
? '/plugins/lens/assets/lens_app_graphic_dark_2x.png'
Expand Down Expand Up @@ -85,15 +86,13 @@ export function InnerWorkspacePanel({

function onDrop() {
if (suggestionForDraggedField) {
trackUiEvent('workspace-drop-success');
trackUiEvent(isEmpty ? 'workspace_drop_on_empty' : 'workspace_drop_non_empty');
switchToSuggestion(
framePublicAPI,
dispatch,
suggestionForDraggedField,
'SWITCH_VISUALIZATION'
);
} else {
trackUiEvent('workspace-drop-failure');
}
}

Expand Down Expand Up @@ -129,13 +128,19 @@ export function InnerWorkspacePanel({
: null;
const expression = useMemo(() => {
try {
return buildExpression({
const tempExpression = buildExpression({
visualization: activeVisualization,
visualizationState,
datasourceMap,
datasourceStates,
framePublicAPI,
});
if (tempExpression) {
setIsEmpty(false);
} else {
setIsEmpty(true);
}
return tempExpression;
} catch (e) {
setExpressionError(e.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import React, { useState } from 'react';
import { EuiButtonEmpty, EuiPopover, EuiSelectable, EuiButtonEmptyProps } from '@elastic/eui';
import { EuiSelectableProps } from '@elastic/eui/src/components/selectable/selectable';
import { IndexPatternRef } from './types';
import { trackUiEvent } from '../lens_ui_telemetry';

export interface ChangeIndexPatternTriggerProps extends EuiButtonEmptyProps {
label: string;
Expand Down Expand Up @@ -74,6 +75,7 @@ export function ChangeIndexPattern({
const choice = (choices.find(({ checked }) => checked) as unknown) as {
value: string;
};
trackUiEvent('indexpattern_changed');
onChangeIndexPattern(choice.value);
setPopoverIsOpen(false);
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
IndexPatternField,
IndexPatternRef,
} from './types';
import { trackUiEvent } from '../lens_ui_telemetry';

type Props = DatasourceDataPanelProps<IndexPatternPrivateState> & {
changeIndexPattern: (
Expand Down Expand Up @@ -358,6 +359,7 @@ export const InnerIndexPatternDataPanel = function InnerIndexPatternDataPanel({
defaultMessage: 'Clear name and type filters',
}),
onClick: () => {
trackUiEvent('indexpattern_filters_cleared');
setLocalState(s => ({
...s,
nameFilter: '',
Expand Down Expand Up @@ -427,14 +429,15 @@ export const InnerIndexPatternDataPanel = function InnerIndexPatternDataPanel({
key={type}
icon={localState.typeFilter.includes(type) ? 'check' : 'empty'}
data-test-subj={`typeFilter-${type}`}
onClick={() =>
onClick={() => {
trackUiEvent('indexpattern_type_filter_toggled');
setLocalState(s => ({
...s,
typeFilter: localState.typeFilter.includes(type)
? localState.typeFilter.filter(t => t !== type)
: [...localState.typeFilter, type],
}))
}
}));
}}
>
<LensFieldIcon type={type} /> {fieldTypeNames[type]}
</EuiContextMenuItem>
Expand All @@ -445,6 +448,7 @@ export const InnerIndexPatternDataPanel = function InnerIndexPatternDataPanel({
compressed
checked={!showEmptyFields}
onChange={() => {
trackUiEvent('indexpattern_existence_toggled');
onToggleEmptyFields();
}}
label={i18n.translate('xpack.lens.indexPatterns.toggleEmptyFieldsSwitch', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { DragContextState, ChildDragDropProvider, DragDrop } from '../../drag_dr
import { changeColumn, deleteColumn } from '../state_helpers';
import { isDraggedField, hasField } from '../utils';
import { IndexPatternPrivateState, IndexPatternField } from '../types';
import { trackUiEvent } from '../../lens_ui_telemetry';

export type IndexPatternDimensionPanelProps = DatasourceDimensionPanelProps & {
state: IndexPatternPrivateState;
Expand Down Expand Up @@ -137,6 +138,8 @@ export const IndexPatternDimensionPanel = memo(function IndexPatternDimensionPan
field: droppedItem.field,
});

trackUiEvent('drop_onto_dimension');

props.setState(
changeColumn({
state: props.state,
Expand Down Expand Up @@ -170,6 +173,7 @@ export const IndexPatternDimensionPanel = memo(function IndexPatternDimensionPan
defaultMessage: 'Remove configuration',
})}
onClick={() => {
trackUiEvent('indexpattern_dimension_removed');
props.setState(
deleteColumn({
state: props.state,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { LensFieldIcon } from '../lens_field_icon';
import { DataType } from '../../types';
import { OperationFieldSupportMatrix } from './dimension_panel';
import { IndexPattern, IndexPatternField } from '../types';
import { trackUiEvent } from '../../lens_ui_telemetry';

export type FieldChoice =
| { type: 'field'; field: string; operationType?: OperationType }
Expand Down Expand Up @@ -167,6 +168,8 @@ export function FieldSelect({
return;
}

trackUiEvent('indexpattern_dimension_field_changed');

onChoose((choices[0].value as unknown) as FieldChoice);
}}
renderOption={(option, searchValue) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { FieldSelect } from './field_select';
import { hasField } from '../utils';
import { BucketNestingEditor } from './bucket_nesting_editor';
import { IndexPattern, IndexPatternField } from '../types';
import { trackUiEvent } from '../../lens_ui_telemetry';

const operationPanels = getOperationDisplay();

Expand Down Expand Up @@ -162,10 +163,12 @@ export function PopoverEditor(props: PopoverEditorProps) {
} else {
setInvalidOperationType(operationType);
}
trackUiEvent(`indexpattern_dimension_operation_${operationType}`);
return;
}
if (!compatibleWithCurrentField) {
setInvalidOperationType(operationType);
trackUiEvent(`indexpattern_dimension_operation_${operationType}`);
return;
}
if (incompatibleSelectedOperationType) {
Expand All @@ -182,6 +185,9 @@ export function PopoverEditor(props: PopoverEditorProps) {
indexPattern: currentIndexPattern,
field: hasField(selectedColumn) ? fieldMap[selectedColumn.sourceField] : undefined,
});
trackUiEvent(
`indexpattern_dimension_operation_from_${selectedColumn.operationType}_to_${operationType}`
);
setState(
changeColumn({
state,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { DatasourceDataPanelProps, DataType } from '../types';
import { BucketedAggregation, FieldStatsResponse } from '../../common';
import { IndexPattern, IndexPatternField } from './types';
import { LensFieldIcon, getColorForDataType } from './lens_field_icon';
import { trackUiEvent } from '../lens_ui_telemetry';

export interface FieldItemProps {
core: DatasourceDataPanelProps['core'];
Expand Down Expand Up @@ -141,6 +142,7 @@ export function FieldItem(props: FieldItemProps) {
function togglePopover() {
setOpen(!infoIsOpen);
if (!infoIsOpen) {
trackUiEvent('indexpattern_field_info_click');
fetchData();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { NativeRenderer } from '../native_renderer';
import { MultiColumnEditor } from '../multi_column_editor';
import { generateId } from '../id_generator';
import { isHorizontalChart, isHorizontalSeries } from './state_helpers';
import { trackUiEvent } from '../lens_ui_telemetry';

const isNumericMetric = (op: OperationMetadata) => !op.isBucketed && op.dataType === 'number';
const isBucketed = (op: OperationMetadata) => op.isBucketed;
Expand Down Expand Up @@ -149,6 +150,7 @@ export function XYConfigPanel(props: VisualizationProps<State>) {
setState(updateLayer(state, { ...layer, seriesType }, index))
}
removeLayer={() => {
trackUiEvent('xy_layer_removed');
frame.removeLayers([layer.layerId]);
setState({ ...state, layers: state.layers.filter(l => l !== layer) });
}}
Expand Down Expand Up @@ -258,6 +260,7 @@ export function XYConfigPanel(props: VisualizationProps<State>) {
defaultMessage: 'Add layer',
})}
onClick={() => {
trackUiEvent('xy_layer_added');
const usedSeriesTypes = _.uniq(state.layers.map(layer => layer.seriesType));
setState({
...state,
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/lens/server/usage/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ async function doWork(
daily: {
date_histogram: {
field: 'updated_at',
calendar_interval: '1d',
fixed_interval: '30d',
},
aggs: {
names: {
Expand Down

0 comments on commit bf26faa

Please sign in to comment.