DashboardScene: Enable scene tracking information (#79963)

* DashboardScene: Enable scene tracking information alt

* tests update

* Review

* Revert "tests update"

This reverts commit 43f894236a.

* nit
This commit is contained in:
Dominik Prokop 2024-01-04 07:34:15 -08:00 committed by GitHub
parent 20096259d3
commit e93c150406
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 2 deletions

View File

@ -29,6 +29,7 @@ import {
UserActionEvent,
} from '@grafana/scenes';
import { DashboardModel, PanelModel } from 'app/features/dashboard/state';
import { trackDashboardLoaded } from 'app/features/dashboard/utils/tracking';
import { DashboardDTO } from 'app/types';
import { AlertStatesDataLayer } from '../scene/AlertStatesDataLayer';
@ -67,7 +68,10 @@ export function transformSaveModelToScene(rsp: DashboardDTO): DashboardScene {
autoMigrateOldPanels: false,
});
return createDashboardSceneFromDashboardModel(oldModel);
const scene = createDashboardSceneFromDashboardModel(oldModel);
scene.state.$behaviors?.push(registerDashboardSceneTracking(oldModel, rsp.dashboard.version));
return scene;
}
export function createSceneObjectsForPanels(oldPanels: PanelModel[]): SceneGridItemLike[] {
@ -480,6 +484,18 @@ const getLimitedDescriptionReporter = () => {
};
};
function registerDashboardSceneTracking(model: DashboardModel, version?: number) {
return () => {
const unsetDashboardInteractionsScenesContext = DashboardInteractions.setScenesContext();
trackDashboardLoaded(model, version);
return () => {
unsetDashboardInteractionsScenesContext();
};
};
}
function registerPanelInteractionsReporter(scene: DashboardScene) {
const descriptionReporter = getLimitedDescriptionReporter();

View File

@ -1,6 +1,8 @@
import { reportInteraction } from '@grafana/runtime';
import { InspectTab } from 'app/features/inspector/types';
let isScenesContextSet = false;
export const DashboardInteractions = {
// Dashboard interactions:
dashboardInitialized: (properties?: Record<string, unknown>) => {
@ -137,11 +139,21 @@ export const DashboardInteractions = {
toolbarAddClick: () => {
reportDashboardInteraction('toolbar_actions_clicked', { item: 'add' });
},
setScenesContext: () => {
isScenesContextSet = true;
return () => {
isScenesContextSet = false;
};
},
};
const reportDashboardInteraction: typeof reportInteraction = (name, properties) => {
const meta = isScenesContextSet ? { scenesView: true } : {};
if (properties) {
reportInteraction(`dashboards_${name}`, properties);
reportInteraction(`dashboards_${name}`, { ...properties, ...meta });
} else {
reportInteraction(`dashboards_${name}`);
}