Skip to content

Commit dfbb3a6

Browse files
authored
fix(Tracking): Use custom reporter (#277)
1 parent 39e550a commit dfbb3a6

File tree

5 files changed

+35
-32
lines changed

5 files changed

+35
-32
lines changed

docs/sources/choose-a-view/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ Similar to a `git diff`, it takes the selected flame graphs and highlights the d
180180

181181
### Favorites
182182

183-
The **Favorites** view shows all your favorited visualizations.
183+
The **Favorites** view shows all your favorited visualizations.
184184
Clicking on the star (⭐️) at the top-right corner of a visualization saves it as a favorite.
185185

186186
Using favories, you can create an overview of what's important, as well as jump to the **Flame graph** view or the **Labels** view.

src/pages/ProfilesExplorerView/components/SceneExploreServiceFlameGraph/components/SceneExportMenu/SceneExportMenu.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { TimeRange } from '@grafana/data';
2-
import { reportInteraction } from '@grafana/runtime';
32
import { SceneComponentProps, sceneGraph, SceneObjectBase, SceneObjectState } from '@grafana/scenes';
43
import { Button, Dropdown, Menu } from '@grafana/ui';
54
import { displayError } from '@shared/domain/displayStatus';
5+
import { reportInteraction } from '@shared/domain/reportInteraction';
66
import { useMaxNodesFromUrl } from '@shared/domain/url-params/useMaxNodesFromUrl';
77
import { DEFAULT_SETTINGS } from '@shared/infrastructure/settings/PluginSettings';
88
import { useFetchPluginSettings } from '@shared/infrastructure/settings/useFetchPluginSettings';
@@ -89,7 +89,7 @@ export class SceneExportMenu extends SceneObjectBase<SceneExportMenuState> {
8989
const { settings } = useFetchPluginSettings();
9090

9191
const downloadPng = () => {
92-
reportInteraction('g_pyroscope_export_profile', { format: 'png' });
92+
reportInteraction('g_pyroscope_app_export_profile', { format: 'png' });
9393

9494
const filename = `${getExportFilename(query, timeRange)}.png`;
9595

@@ -105,7 +105,7 @@ export class SceneExportMenu extends SceneObjectBase<SceneExportMenuState> {
105105
};
106106

107107
const downloadJson = async () => {
108-
reportInteraction('g_pyroscope_export_profile', { format: 'json' });
108+
reportInteraction('g_pyroscope_app_export_profile', { format: 'json' });
109109

110110
const profile = await this.fetchFlamebearerProfile({ dataSourceUid, query, timeRange, maxNodes });
111111
if (!profile) {
@@ -119,7 +119,7 @@ export class SceneExportMenu extends SceneObjectBase<SceneExportMenuState> {
119119
};
120120

121121
const downloadPprof = async () => {
122-
reportInteraction('g_pyroscope_export_profile', { format: 'pprof' });
122+
reportInteraction('g_pyroscope_app_export_profile', { format: 'pprof' });
123123

124124
const profile = await this.fetchPprofProfile({ dataSourceUid, query, timeRange, maxNodes });
125125
if (!profile) {
@@ -132,7 +132,7 @@ export class SceneExportMenu extends SceneObjectBase<SceneExportMenuState> {
132132
};
133133

134134
const uploadToFlamegraphDotCom = async () => {
135-
reportInteraction('g_pyroscope_export_profile', { format: 'flamegraph.com' });
135+
reportInteraction('g_pyroscope_app_export_profile', { format: 'flamegraph.com' });
136136

137137
const profile = await this.fetchFlamebearerProfile({ dataSourceUid, query, timeRange, maxNodes });
138138
if (!profile) {

src/pages/ProfilesExplorerView/components/SceneProfilesExplorer/components/domain/useHeader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { reportInteraction } from '@grafana/runtime';
21
import { SceneObject, SceneVariable } from '@grafana/scenes';
32
import { displaySuccess } from '@shared/domain/displayStatus';
3+
import { reportInteraction } from '@shared/domain/reportInteraction';
44
import { logger } from '@shared/infrastructure/tracking/logger';
55
import { useCallback } from 'react';
66
import { useHistory } from 'react-router-dom';

src/pages/ProfilesExplorerView/domain/variables/FiltersVariable/FiltersVariable.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { reportInteraction } from '@grafana/runtime';
21
import { AdHocFiltersVariable, SceneComponentProps, sceneGraph } from '@grafana/scenes';
32
import { CompleteFilters, OperatorKind } from '@shared/components/QueryBuilder/domain/types';
43
import { QueryBuilder } from '@shared/components/QueryBuilder/QueryBuilder';
4+
import { reportInteraction } from '@shared/domain/reportInteraction';
55
import { uniq } from 'lodash';
66
import React from 'react';
77

@@ -43,7 +43,7 @@ export class FiltersVariable extends AdHocFiltersVariable {
4343
}
4444

4545
onChangeQuery = (query: string, filters: CompleteFilters) => {
46-
reportInteraction('g_pyroscope_filters_changed', {
46+
reportInteraction('g_pyroscope_app_filters_changed', {
4747
name: this.state.name,
4848
count: filters.length,
4949
operators: uniq(filters.map((f) => f.operator.label)),

src/shared/domain/reportInteraction.ts

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,24 @@ import { PYROSCOPE_APP_ID, ROUTES } from '../../constants';
44
import { LayoutType } from '../../pages/ProfilesExplorerView/components/SceneByVariableRepeaterGrid/components/SceneLayoutSwitcher';
55
import { PanelType } from '../../pages/ProfilesExplorerView/components/SceneByVariableRepeaterGrid/components/ScenePanelTypeSwitcher';
66

7-
const PROFILES_EXPLORER_PAGE_NAME = ROUTES.PROFILES_EXPLORER_VIEW.slice(1);
8-
9-
function getCurrentPage(): string {
10-
const { pathname } = new URL(window.location.toString());
11-
return pathname.split('/').pop() || '';
12-
}
13-
14-
function getExtraProperties() {
15-
const page = getCurrentPage();
16-
const version = config.apps[PYROSCOPE_APP_ID].version;
17-
const extraProperties: Record<string, any> = { page, version };
18-
19-
if (page === PROFILES_EXPLORER_PAGE_NAME) {
20-
extraProperties.explorationType = new URLSearchParams(window.location.search).get('explorationType');
21-
}
22-
23-
return extraProperties;
24-
}
25-
267
// hey future dev: don't forget to add any new value to our features tracking dashboard!
278
export type InteractionName =
289
| 'g_pyroscope_app_compare_link_clicked'
29-
| 'g_pyroscope_app_diff_preset_selected'
30-
| 'g_pyroscope_app_diff_preset_save_clicked'
3110
| 'g_pyroscope_app_diff_auto_select_clicked'
3211
| 'g_pyroscope_app_diff_choose_preset_clicked'
3312
| 'g_pyroscope_app_diff_learn_how_clicked'
34-
| 'g_pyroscope_app_include_action_clicked'
13+
| 'g_pyroscope_app_diff_preset_save_clicked'
14+
| 'g_pyroscope_app_diff_preset_selected'
3515
| 'g_pyroscope_app_exclude_action_clicked'
3616
| 'g_pyroscope_app_explain_flamegraph_clicked'
3717
| 'g_pyroscope_app_exploration_type_clicked'
3818
| 'g_pyroscope_app_export_profile'
3919
| 'g_pyroscope_app_fav_action_clicked'
20+
| 'g_pyroscope_app_filters_changed'
4021
| 'g_pyroscope_app_function_details_clicked'
4122
| 'g_pyroscope_app_group_by_label_clicked'
4223
| 'g_pyroscope_app_hide_no_data_changed'
24+
| 'g_pyroscope_app_include_action_clicked'
4325
| 'g_pyroscope_app_layout_changed'
4426
| 'g_pyroscope_app_optimize_code_clicked'
4527
| 'g_pyroscope_app_panel_type_changed'
@@ -56,9 +38,11 @@ type InteractionProperties =
5638
// g_pyroscope_app_exploration_type_clicked
5739
| { explorationType: string }
5840
// g_pyroscope_app_export_profile
59-
| { format: 'png' | 'json' | 'flamegraph.com' }
41+
| { format: 'png' | 'json' | 'pprof' | 'flamegraph.com' }
6042
// g_pyroscope_app_fav_action_clicked
6143
| { favAfterClick: boolean }
44+
// g_pyroscope_app_filters_changed
45+
| { name: string; count: number; operators: string[] }
6246
// g_pyroscope_app_group_by_label_clicked
6347
| { label: string }
6448
// g_pyroscope_app_hide_no_data_changed
@@ -70,6 +54,25 @@ type InteractionProperties =
7054
// g_pyroscope_app_select_action_clicked
7155
| { type: string };
7256

57+
const PROFILES_EXPLORER_PAGE_NAME = ROUTES.PROFILES_EXPLORER_VIEW.slice(1);
58+
59+
function getCurrentPage(): string {
60+
const { pathname } = new URL(window.location.toString());
61+
return pathname.split('/').pop() || '';
62+
}
63+
64+
function getExtraProperties() {
65+
const page = getCurrentPage();
66+
const version = config.apps[PYROSCOPE_APP_ID].version;
67+
const extraProperties: Record<string, any> = { page, version };
68+
69+
if (page === PROFILES_EXPLORER_PAGE_NAME) {
70+
extraProperties.explorationType = new URLSearchParams(window.location.search).get('explorationType');
71+
}
72+
73+
return extraProperties;
74+
}
75+
7376
export function reportInteraction(interactionName: InteractionName, properties?: InteractionProperties) {
7477
grafanaReportInteraction(interactionName, {
7578
...properties,

0 commit comments

Comments
 (0)