From 029253d5f6f1761f1a9d9e742c0c750ebc3d7392 Mon Sep 17 00:00:00 2001 From: Ashley Harrison Date: Tue, 31 Jan 2023 13:54:24 +0000 Subject: [PATCH] Navigation: add event tracking for dashboard save as events (#62568) * add event tracking for dashboard save as events * emit a grafana_dashboard_copied event instead --- .../SaveDashboard/SaveDashboardButton.tsx | 2 ++ .../SaveDashboard/SaveDashboardDrawer.tsx | 2 +- .../SaveDashboard/useDashboardSave.tsx | 19 +++++++++++++------ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/public/app/features/dashboard/components/SaveDashboard/SaveDashboardButton.tsx b/public/app/features/dashboard/components/SaveDashboard/SaveDashboardButton.tsx index ef02f73e24d..1bb4654cae2 100644 --- a/public/app/features/dashboard/components/SaveDashboard/SaveDashboardButton.tsx +++ b/public/app/features/dashboard/components/SaveDashboard/SaveDashboardButton.tsx @@ -1,6 +1,7 @@ import React from 'react'; import { selectors } from '@grafana/e2e-selectors'; +import { reportInteraction } from '@grafana/runtime'; import { Button, ButtonVariant, ComponentSize, ModalsController } from '@grafana/ui'; import { DashboardModel } from 'app/features/dashboard/state'; @@ -49,6 +50,7 @@ export const SaveDashboardAsButton: React.FC { + reportInteraction('grafana_dashboard_save_as_clicked'); showModal(SaveDashboardDrawer, { dashboard, onSaveSuccess, diff --git a/public/app/features/dashboard/components/SaveDashboard/SaveDashboardDrawer.tsx b/public/app/features/dashboard/components/SaveDashboard/SaveDashboardDrawer.tsx index 98f2cabe06b..da46a82f6d6 100644 --- a/public/app/features/dashboard/components/SaveDashboard/SaveDashboardDrawer.tsx +++ b/public/app/features/dashboard/components/SaveDashboard/SaveDashboardDrawer.tsx @@ -61,7 +61,7 @@ export const SaveDashboardDrawer = ({ dashboard, onDismiss, onSaveSuccess, isCop }, [dashboard, previous.value, options, isNew]); const [showDiff, setShowDiff] = useState(false); - const { state, onDashboardSave } = useDashboardSave(dashboard); + const { state, onDashboardSave } = useDashboardSave(dashboard, isCopy); const onSuccess = onSaveSuccess ? () => { onDismiss(); diff --git a/public/app/features/dashboard/components/SaveDashboard/useDashboardSave.tsx b/public/app/features/dashboard/components/SaveDashboard/useDashboardSave.tsx index 42306bcd8c8..b636f8b50e5 100644 --- a/public/app/features/dashboard/components/SaveDashboard/useDashboardSave.tsx +++ b/public/app/features/dashboard/components/SaveDashboard/useDashboardSave.tsx @@ -26,7 +26,7 @@ const saveDashboard = async (saveModel: any, options: SaveDashboardOptions, dash return result; }; -export const useDashboardSave = (dashboard: DashboardModel) => { +export const useDashboardSave = (dashboard: DashboardModel, isCopy = false) => { const [state, onDashboardSave] = useAsyncFn( async (clone: any, options: SaveDashboardOptions, dashboard: DashboardModel) => await saveDashboard(clone, options, dashboard), @@ -46,10 +46,17 @@ export const useDashboardSave = (dashboard: DashboardModel) => { // important that these happen before location redirect below appEvents.publish(new DashboardSavedEvent()); notifyApp.success('Dashboard saved'); - reportInteraction(`grafana_dashboard_${dashboard.id ? 'saved' : 'created'}`, { - name: dashboard.title, - url: state.value.url, - }); + if (isCopy) { + reportInteraction('grafana_dashboard_copied', { + name: dashboard.title, + url: state.value.url, + }); + } else { + reportInteraction(`grafana_dashboard_${dashboard.id ? 'saved' : 'created'}`, { + name: dashboard.title, + url: state.value.url, + }); + } const currentPath = locationService.getLocation().pathname; const newUrl = locationUtil.stripBaseFromUrl(state.value.url); @@ -67,7 +74,7 @@ export const useDashboardSave = (dashboard: DashboardModel) => { ); } } - }, [dashboard, state, notifyApp, dispatch]); + }, [dashboard, isCopy, state, notifyApp, dispatch]); return { state, onDashboardSave }; };