DashboardScene: Enable scene tracking information alt

This commit is contained in:
Dominik Prokop
2024-01-03 11:34:00 +01:00
parent 6465d87afd
commit 44012b5cd6
3 changed files with 41 additions and 10 deletions
@@ -43,14 +43,17 @@ export const reportPageview = () => {
*
* @public
*/
export const reportInteraction = (interactionName: string, properties?: Record<string, unknown>) => {
getEchoSrv().addEvent<InteractionEchoEvent>({
type: EchoEventType.Interaction,
payload: {
interactionName,
properties,
export const reportInteraction = (interactionName: string, properties?: Record<string, unknown>, meta?: {}) => {
getEchoSrv().addEvent<InteractionEchoEvent>(
{
type: EchoEventType.Interaction,
payload: {
interactionName,
properties,
},
},
});
meta
);
};
/**
@@ -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();
@@ -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,12 +139,22 @@ 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}`);
reportInteraction(`dashboards_${name}`, undefined, meta);
}
};