mirror of https://github.com/grafana/grafana
Chore: Add tracking for dashboard load (#70057)
* Chore: Add tracking for dashboard load * Address review commentspull/70599/head
parent
15e134215a
commit
6fbc0b9b9c
@ -0,0 +1,40 @@ |
||||
import { getDashboardModel } from 'test/helpers/getDashboardModel'; |
||||
|
||||
import * as runtime from '@grafana/runtime'; |
||||
|
||||
import { trackDashboardLoaded } from './tracking'; |
||||
|
||||
describe('trackDashboardLoaded', () => { |
||||
it('should report dashboard_loaded interaction with correct parameters', () => { |
||||
const dashboardJSON = { |
||||
uid: 'dashboard-123', |
||||
title: 'Test Dashboard', |
||||
panels: [ |
||||
{ id: 1, type: 'row', repeat: 'dc', gridPos: { x: 0, y: 0, h: 1, w: 24 } }, |
||||
{ id: 2, repeat: 'app', repeatDirection: 'h', gridPos: { x: 0, y: 1, h: 2, w: 8 } }, |
||||
], |
||||
templating: { |
||||
list: [ |
||||
{ type: 'query', name: 'Query 1' }, |
||||
{ type: 'interval', name: 'Interval 1' }, |
||||
{ type: 'query', name: 'Query 2' }, |
||||
], |
||||
}, |
||||
}; |
||||
const model = getDashboardModel(dashboardJSON); |
||||
const reportInteractionSpy = jest.spyOn(runtime, 'reportInteraction'); |
||||
|
||||
trackDashboardLoaded(model, 16); |
||||
|
||||
expect(reportInteractionSpy).toHaveBeenCalledWith('dashboards_init_dashboard_completed', { |
||||
uid: 'dashboard-123', |
||||
title: 'Test Dashboard', |
||||
theme: 'dark', |
||||
schemaVersion: model.schemaVersion, // This value is based on public/app/features/dashboard/state/DashboardMigrator.ts#L81
|
||||
panels_count: 2, |
||||
variable_type_query_count: 2, |
||||
variable_type_interval_count: 1, |
||||
version_before_migration: 16, |
||||
}); |
||||
}); |
||||
}); |
@ -0,0 +1,25 @@ |
||||
import { reportInteraction } from '@grafana/runtime'; |
||||
|
||||
import { DashboardModel } from '../state'; |
||||
|
||||
export function trackDashboardLoaded(dashboard: DashboardModel, versionBeforeMigration?: number) { |
||||
// Count the different types of variables
|
||||
const variables = dashboard.templating.list |
||||
.map((v) => v.type) |
||||
.reduce((r, k) => { |
||||
r[variableName(k)] = 1 + r[variableName(k)] || 1; |
||||
return r; |
||||
}, {}); |
||||
|
||||
reportInteraction('dashboards_init_dashboard_completed', { |
||||
uid: dashboard.uid, |
||||
title: dashboard.title, |
||||
theme: dashboard.style, |
||||
schemaVersion: dashboard.schemaVersion, |
||||
version_before_migration: versionBeforeMigration, |
||||
panels_count: dashboard.panels.length, |
||||
...variables, |
||||
}); |
||||
} |
||||
|
||||
const variableName = (type: string) => `variable_type_${type}_count`; |
Loading…
Reference in new issue