Explore: Add feature tracking events (#54514) (#55469)

* Explore: Add feature tracking events (#54514)

* refactor: repair tests

* refactor: clean up

* feat: add details to change of data source

* refactor: remove duplicate tracking

* refactor: make tracking reusable in an easier way

* refactor: add property

* refactor: change data for time picker

* refactor: change tracking label for time picker

Co-authored-by: Ivan Ortega Alba <ivanortegaalba@gmail.com>

* refactor: store tracking in explore component

* refactor: add index signature

* refactor: remove ?

* refactor: split into 3 callbacks

* refactor: apply suggestions from code review

Co-authored-by: Piotr Jamróz <pm.jamroz@gmail.com>

Co-authored-by: Ivan Ortega Alba <ivanortegaalba@gmail.com>
Co-authored-by: Piotr Jamróz <pm.jamroz@gmail.com>
(cherry picked from commit dbbab6e95c)

* refactor: remove unrelated changes
This commit is contained in:
Laura Benz
2022-09-20 18:03:10 +02:00
committed by GitHub
parent e61cc31378
commit c8f4918e48
8 changed files with 102 additions and 15 deletions
@@ -29,6 +29,11 @@ jest.mock('app/core/services/context_srv', () => ({
},
}));
jest.mock('@grafana/runtime', () => ({
...jest.requireActual('@grafana/runtime'),
reportInteraction: () => null,
}));
const setup = (propOverrides = {}) => {
const props: ExploreQueryInspectorProps = {
loading: false,
@@ -1,7 +1,8 @@
import React from 'react';
import React, { useEffect } from 'react';
import { connect, ConnectedProps } from 'react-redux';
import { CoreApp, TimeZone } from '@grafana/data';
import { reportInteraction } from '@grafana/runtime/src';
import { TabbedContainer, TabConfig } from '@grafana/ui';
import { ExploreDrawer } from 'app/features/explore/ExploreDrawer';
import { InspectDataTab } from 'app/features/inspector/InspectDataTab';
@@ -27,6 +28,10 @@ export function ExploreQueryInspector(props: Props) {
const dataFrames = queryResponse?.series || [];
const error = queryResponse?.error;
useEffect(() => {
reportInteraction('grafana_explore_query_inspector_opened');
}, []);
const statsTab: TabConfig = {
label: 'Stats',
value: 'stats',
@@ -1,6 +1,7 @@
import React, { Component } from 'react';
import { TimeRange, TimeZone, RawTimeRange, dateTimeForTimeZone, dateMath } from '@grafana/data';
import { reportInteraction } from '@grafana/runtime';
import { TimePickerWithHistory } from 'app/core/components/TimePicker/TimePickerWithHistory';
import { getShiftedTimeRange, getZoomedTimeRange } from 'app/core/utils/timePicker';
import { ExploreId } from 'app/types';
@@ -44,6 +45,11 @@ export class ExploreTimeControls extends Component<Props> {
from: adjustedFrom,
to: adjustedTo,
});
reportInteraction('grafana_explore_time_picker_time_range_changed', {
timeRangeFrom: adjustedFrom,
timeRangeTo: adjustedTo,
});
};
onZoom = () => {
+20 -5
View File
@@ -67,6 +67,23 @@ class UnConnectedExploreToolbar extends PureComponent<Props> {
syncTimes(exploreId);
};
onCopyShortLink = async () => {
await createAndCopyShortLink(window.location.href);
reportInteraction('grafana_explore_shortened_link_clicked');
};
onOpenSplitView = () => {
const { split } = this.props;
split();
reportInteraction('grafana_explore_splitView_opened');
};
onCloseSplitView = () => {
const { closeSplit, exploreId } = this.props;
closeSplit(exploreId);
reportInteraction('grafana_explore_splitView_closed');
};
renderRefreshPicker = (showSmallTimePicker: boolean) => {
const { loading, refreshInterval, isLive } = this.props;
@@ -99,7 +116,6 @@ class UnConnectedExploreToolbar extends PureComponent<Props> {
render() {
const {
datasourceMissing,
closeSplit,
exploreId,
loading,
range,
@@ -109,7 +125,6 @@ class UnConnectedExploreToolbar extends PureComponent<Props> {
syncedTimes,
refreshInterval,
onChangeTime,
split,
hasLiveOption,
isLive,
isPaused,
@@ -138,7 +153,7 @@ class UnConnectedExploreToolbar extends PureComponent<Props> {
key="share"
tooltip="Copy shortened link"
icon="share-alt"
onClick={() => createAndCopyShortLink(window.location.href)}
onClick={this.onCopyShortLink}
aria-label="Copy shortened link"
/>
),
@@ -155,11 +170,11 @@ class UnConnectedExploreToolbar extends PureComponent<Props> {
>
<ToolbarButtonRow>
{!splitted ? (
<ToolbarButton title="Split" onClick={() => split()} icon="columns" disabled={isLive}>
<ToolbarButton title="Split" onClick={this.onOpenSplitView} icon="columns" disabled={isLive}>
Split
</ToolbarButton>
) : (
<ToolbarButton title="Close split pane" onClick={() => closeSplit(exploreId)} icon="times">
<ToolbarButton title="Close split pane" onClick={this.onCloseSplitView} icon="times">
Close
</ToolbarButton>
)}
@@ -12,6 +12,11 @@ import { UserState } from '../profile/state/reducers';
import { QueryRows } from './QueryRows';
import { makeExplorePaneState } from './state/utils';
jest.mock('@grafana/runtime', () => ({
...jest.requireActual('@grafana/runtime'),
reportInteraction: () => null,
}));
function setup(queries: DataQuery[]) {
const defaultDs = {
name: 'newDs',
+16
View File
@@ -3,6 +3,7 @@ import React, { useCallback, useMemo } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { CoreApp, DataQuery } from '@grafana/data';
import { reportInteraction } from '@grafana/runtime';
import { getNextRefIdChar } from 'app/core/utils/query';
import { ExploreId } from 'app/types/explore';
@@ -66,6 +67,18 @@ export const QueryRows = ({ exploreId }: Props) => {
[onChange, queries]
);
const onQueryCopied = () => {
reportInteraction('grafana_explore_query_row_copy');
};
const onQueryRemoved = () => {
reportInteraction('grafana_explore_query_row_remove');
};
const onQueryToggled = (queryStatus?: boolean) => {
reportInteraction('grafana_query_row_toggle', queryStatus === undefined ? {} : { queryEnabled: queryStatus });
};
return (
<QueryEditorRows
dsSettings={dsSettings}
@@ -73,6 +86,9 @@ export const QueryRows = ({ exploreId }: Props) => {
onQueriesChange={onChange}
onAddQuery={onAddQuery}
onRunQueries={onRunQueries}
onQueryCopied={onQueryCopied}
onQueryRemoved={onQueryRemoved}
onQueryToggled={onQueryToggled}
data={queryResponse}
app={CoreApp.Explore}
history={history}
@@ -57,6 +57,9 @@ interface Props<TQuery extends DataQuery> {
history?: Array<HistoryItem<TQuery>>;
eventBus?: EventBusExtended;
alerting?: boolean;
onQueryCopied?: () => void;
onQueryRemoved?: () => void;
onQueryToggled?: (queryStatus?: boolean | undefined) => void;
}
interface State<TQuery extends DataQuery> {
@@ -273,18 +276,32 @@ export class QueryEditorRow<TQuery extends DataQuery> extends PureComponent<Prop
};
onRemoveQuery = () => {
this.props.onRemoveQuery(this.props.query);
const { onRemoveQuery, query, onQueryRemoved } = this.props;
onRemoveQuery(query);
if (onQueryRemoved) {
onQueryRemoved();
}
};
onCopyQuery = () => {
const copy = cloneDeep(this.props.query);
this.props.onAddQuery(copy);
const { query, onAddQuery, onQueryCopied } = this.props;
const copy = cloneDeep(query);
onAddQuery(copy);
if (onQueryCopied) {
onQueryCopied();
}
};
onDisableQuery = () => {
const { query } = this.props;
this.props.onChange({ ...query, hide: !query.hide });
this.props.onRunQuery();
const { query, onChange, onRunQuery, onQueryToggled } = this.props;
onChange({ ...query, hide: !query.hide });
onRunQuery();
if (onQueryToggled) {
onQueryToggled(query.hide);
}
};
onToggleHelp = () => {
@@ -31,6 +31,9 @@ interface Props {
app?: CoreApp;
history?: Array<HistoryItem<DataQuery>>;
eventBus?: EventBusExtended;
onQueryCopied?: () => void;
onQueryRemoved?: () => void;
onQueryToggled?: (queryStatus?: boolean | undefined) => void;
}
export class QueryEditorRows extends PureComponent<Props> {
@@ -129,7 +132,19 @@ export class QueryEditorRows extends PureComponent<Props> {
};
render() {
const { dsSettings, data, queries, app, history, eventBus } = this.props;
const {
dsSettings,
data,
queries,
app,
history,
eventBus,
onAddQuery,
onRunQueries,
onQueryCopied,
onQueryRemoved,
onQueryToggled,
} = this.props;
return (
<DragDropContext onDragStart={this.onDragStart} onDragEnd={this.onDragEnd}>
@@ -154,8 +169,11 @@ export class QueryEditorRows extends PureComponent<Props> {
onChangeDataSource={onChangeDataSourceSettings}
onChange={(query) => this.onChangeQuery(query, index)}
onRemoveQuery={this.onRemoveQuery}
onAddQuery={this.props.onAddQuery}
onRunQuery={this.props.onRunQueries}
onAddQuery={onAddQuery}
onRunQuery={onRunQueries}
onQueryCopied={onQueryCopied}
onQueryRemoved={onQueryRemoved}
onQueryToggled={onQueryToggled}
queries={queries}
app={app}
history={history}