diff --git a/public/app/features/dashboard-scene/sharing/ShareLinkTab.tsx b/public/app/features/dashboard-scene/sharing/ShareLinkTab.tsx index cf2e28c8299..7f3fc6a5e12 100644 --- a/public/app/features/dashboard-scene/sharing/ShareLinkTab.tsx +++ b/public/app/features/dashboard-scene/sharing/ShareLinkTab.tsx @@ -9,7 +9,7 @@ import { Alert, ClipboardButton, Field, FieldSet, Icon, Input, Switch } from '@g import { t, Trans } from 'app/core/internationalization'; import { createShortLink } from 'app/core/utils/shortLinks'; import { ThemePicker } from 'app/features/dashboard/components/ShareModal/ThemePicker'; -import { shareDashboardType } from 'app/features/dashboard/components/ShareModal/utils'; +import { getTrackingSource, shareDashboardType } from 'app/features/dashboard/components/ShareModal/utils'; import { DashboardInteractions } from '../utils/interactions'; import { getDashboardUrl } from '../utils/urlBuilders'; @@ -131,6 +131,7 @@ export class ShareLinkTab extends SceneObjectBase { currentTimeRange: this.state.useLockedTime, theme: this.state.selectedTheme, shortenURL: this.state.useShortUrl, + shareResource: getTrackingSource(this.state.panelRef), }); }; } diff --git a/public/app/features/dashboard-scene/sharing/ShareModal.tsx b/public/app/features/dashboard-scene/sharing/ShareModal.tsx index 3ada3d1fd72..86d6ab6976d 100644 --- a/public/app/features/dashboard-scene/sharing/ShareModal.tsx +++ b/public/app/features/dashboard-scene/sharing/ShareModal.tsx @@ -7,6 +7,7 @@ import { contextSrv } from 'app/core/core'; import { t } from 'app/core/internationalization'; import { isPublicDashboardsEnabled } from 'app/features/dashboard/components/ShareModal/SharePublicDashboard/SharePublicDashboardUtils'; +import { getTrackingSource } from '../../dashboard/components/ShareModal/utils'; import { DashboardScene } from '../scene/DashboardScene'; import { LibraryVizPanel } from '../scene/LibraryVizPanel'; import { DashboardInteractions } from '../utils/interactions'; @@ -92,7 +93,7 @@ export class ShareModal extends SceneObjectBase implements Moda }; onChangeTab: ComponentProps['onChangeTab'] = (tab) => { - DashboardInteractions.sharingTabChanged({ item: tab.value }); + DashboardInteractions.sharingTabChanged({ item: tab.value, shareResource: getTrackingSource(this.state.panelRef) }); this.setState({ activeTab: tab.value }); }; } diff --git a/public/app/features/dashboard-scene/sharing/ShareSnapshotTab.tsx b/public/app/features/dashboard-scene/sharing/ShareSnapshotTab.tsx index bd733ecbd65..d0de8715791 100644 --- a/public/app/features/dashboard-scene/sharing/ShareSnapshotTab.tsx +++ b/public/app/features/dashboard-scene/sharing/ShareSnapshotTab.tsx @@ -6,7 +6,7 @@ import { getBackendSrv } from '@grafana/runtime'; import { SceneComponentProps, sceneGraph, SceneObjectBase, SceneObjectRef, VizPanel } from '@grafana/scenes'; import { Button, ClipboardButton, Field, Input, Modal, RadioButtonGroup } from '@grafana/ui'; import { t, Trans } from 'app/core/internationalization'; -import { shareDashboardType } from 'app/features/dashboard/components/ShareModal/utils'; +import { getTrackingSource, shareDashboardType } from 'app/features/dashboard/components/ShareModal/utils'; import { getDashboardSnapshotSrv, SnapshotSharingOptions } from 'app/features/dashboard/services/SnapshotSrv'; import { transformSceneToSaveModel, trimDashboardForSnapshot } from '../serialization/transformSceneToSaveModel'; @@ -124,9 +124,15 @@ export class ShareSnapshotTab extends SceneObjectBase { return await getDashboardSnapshotSrv().create(cmdData); } finally { if (external) { - DashboardInteractions.publishSnapshotClicked({ expires: cmdData.expires }); + DashboardInteractions.publishSnapshotClicked({ + expires: cmdData.expires, + shareResource: getTrackingSource(this.state.panelRef), + }); } else { - DashboardInteractions.publishSnapshotLocalClicked({ expires: cmdData.expires }); + DashboardInteractions.publishSnapshotLocalClicked({ + expires: cmdData.expires, + shareResource: getTrackingSource(this.state.panelRef), + }); } } }; diff --git a/public/app/features/dashboard/components/ShareModal/ShareEmbed.tsx b/public/app/features/dashboard/components/ShareModal/ShareEmbed.tsx index 8d60b1e4e3a..4ff8be1eaab 100644 --- a/public/app/features/dashboard/components/ShareModal/ShareEmbed.tsx +++ b/public/app/features/dashboard/components/ShareModal/ShareEmbed.tsx @@ -9,7 +9,7 @@ import { DashboardInteractions } from 'app/features/dashboard-scene/utils/intera import { ThemePicker } from './ThemePicker'; import { ShareModalTabProps } from './types'; -import { buildIframeHtml } from './utils'; +import { buildIframeHtml, getTrackingSource } from './utils'; interface Props extends Omit { panel?: { timeFrom?: string; id: number }; @@ -24,7 +24,7 @@ export function ShareEmbed({ panel, dashboard, range, buildIframe = buildIframeH const [iframeHtml, setIframeHtml] = useState(''); useEffectOnce(() => { - reportInteraction('grafana_dashboards_embed_share_viewed'); + reportInteraction('grafana_dashboards_embed_share_viewed', { shareResource: getTrackingSource(panel) }); }); useEffect(() => { @@ -85,6 +85,7 @@ export function ShareEmbed({ panel, dashboard, range, buildIframe = buildIframeH DashboardInteractions.embedSnippetCopy({ currentTimeRange: useCurrentTimeRange, theme: selectedTheme, + shareResource: getTrackingSource(panel), }); }} > diff --git a/public/app/features/dashboard/components/ShareModal/ShareExport.tsx b/public/app/features/dashboard/components/ShareModal/ShareExport.tsx index 6bf1bad1b84..6ba26550ce3 100644 --- a/public/app/features/dashboard/components/ShareModal/ShareExport.tsx +++ b/public/app/features/dashboard/components/ShareModal/ShareExport.tsx @@ -10,6 +10,7 @@ import { ShowModalReactEvent } from 'app/types/events'; import { ViewJsonModal } from './ViewJsonModal'; import { ShareModalTabProps } from './types'; +import { getTrackingSource } from './utils'; interface Props extends ShareModalTabProps {} @@ -39,7 +40,10 @@ export class ShareExport extends PureComponent { const { dashboard } = this.props; const { shareExternally } = this.state; - DashboardInteractions.exportSaveJsonClicked({ externally: shareExternally }); + DashboardInteractions.exportSaveJsonClicked({ + externally: shareExternally, + shareResource: getTrackingSource(this.props.panel), + }); if (shareExternally) { this.exporter.makeExportable(dashboard).then((dashboardJson) => { @@ -53,7 +57,10 @@ export class ShareExport extends PureComponent { onViewJson = () => { const { dashboard } = this.props; const { shareExternally } = this.state; - DashboardInteractions.exportViewJsonClicked({ externally: shareExternally }); + DashboardInteractions.exportViewJsonClicked({ + externally: shareExternally, + shareResource: getTrackingSource(this.props.panel), + }); if (shareExternally) { this.exporter.makeExportable(dashboard).then((dashboardJson) => { diff --git a/public/app/features/dashboard/components/ShareModal/ShareLibraryPanel.tsx b/public/app/features/dashboard/components/ShareModal/ShareLibraryPanel.tsx index b40dce681db..9b76f04af65 100644 --- a/public/app/features/dashboard/components/ShareModal/ShareLibraryPanel.tsx +++ b/public/app/features/dashboard/components/ShareModal/ShareLibraryPanel.tsx @@ -5,6 +5,7 @@ import { Trans } from 'app/core/internationalization'; import { AddLibraryPanelContents } from 'app/features/library-panels/components/AddLibraryPanelModal/AddLibraryPanelModal'; import { ShareModalTabProps } from './types'; +import { getTrackingSource } from './utils'; interface Props extends ShareModalTabProps { initialFolderUid?: string; @@ -12,8 +13,8 @@ interface Props extends ShareModalTabProps { export const ShareLibraryPanel = ({ panel, initialFolderUid, onDismiss }: Props) => { useEffect(() => { - reportInteraction('grafana_dashboards_library_panel_share_viewed'); - }, []); + reportInteraction('grafana_dashboards_library_panel_share_viewed', { shareResource: getTrackingSource(panel) }); + }, [panel]); if (!panel) { return null; diff --git a/public/app/features/dashboard/components/ShareModal/ShareLink.tsx b/public/app/features/dashboard/components/ShareModal/ShareLink.tsx index b7bc752eab9..595f0d5a6dd 100644 --- a/public/app/features/dashboard/components/ShareModal/ShareLink.tsx +++ b/public/app/features/dashboard/components/ShareModal/ShareLink.tsx @@ -8,7 +8,7 @@ import { DashboardInteractions } from 'app/features/dashboard-scene/utils/intera import { ThemePicker } from './ThemePicker'; import { ShareModalTabProps } from './types'; -import { buildImageUrl, buildShareUrl } from './utils'; +import { buildImageUrl, buildShareUrl, getTrackingSource } from './utils'; export interface Props extends ShareModalTabProps {} @@ -30,7 +30,6 @@ export class ShareLink extends PureComponent { shareUrl: '', imageUrl: '', }; - this.onCopy = this.onCopy.bind(this); } componentDidMount() { @@ -74,13 +73,14 @@ export class ShareLink extends PureComponent { return this.state.shareUrl; }; - onCopy() { + onCopy = () => { DashboardInteractions.shareLinkCopied({ currentTimeRange: this.state.useCurrentTimeRange, theme: this.state.selectedTheme, shortenURL: this.state.useShortUrl, + shareResource: getTrackingSource(this.props.panel), }); - } + }; render() { const { panel, dashboard } = this.props; diff --git a/public/app/features/dashboard/components/ShareModal/ShareModal.tsx b/public/app/features/dashboard/components/ShareModal/ShareModal.tsx index ddbe9cfaa03..b50c79a1735 100644 --- a/public/app/features/dashboard/components/ShareModal/ShareModal.tsx +++ b/public/app/features/dashboard/components/ShareModal/ShareModal.tsx @@ -16,7 +16,7 @@ import { ShareLibraryPanel } from './ShareLibraryPanel'; import { ShareLink } from './ShareLink'; import { ShareSnapshot } from './ShareSnapshot'; import { ShareModalTabModel } from './types'; -import { shareDashboardType } from './utils'; +import { getTrackingSource, shareDashboardType } from './utils'; const customDashboardTabs: ShareModalTabModel[] = []; const customPanelTabs: ShareModalTabModel[] = []; @@ -104,6 +104,7 @@ class UnthemedShareModal extends React.Component { this.setState((prevState) => ({ ...prevState, activeTab: t.value })); DashboardInteractions.sharingTabChanged({ item: t.value, + shareResource: getTrackingSource(this.props.panel), }); }; diff --git a/public/app/features/dashboard/components/ShareModal/SharePublicDashboard/SharePublicDashboard.test.tsx b/public/app/features/dashboard/components/ShareModal/SharePublicDashboard/SharePublicDashboard.test.tsx index 8673036f63c..faff169478a 100644 --- a/public/app/features/dashboard/components/ShareModal/SharePublicDashboard/SharePublicDashboard.test.tsx +++ b/public/app/features/dashboard/components/ShareModal/SharePublicDashboard/SharePublicDashboard.test.tsx @@ -357,7 +357,10 @@ describe('SharePublic - Report interactions', () => { await waitFor(() => { expect(DashboardInteractions.sharingTabChanged).toHaveBeenCalledTimes(1); - expect(DashboardInteractions.sharingTabChanged).lastCalledWith({ item: shareDashboardType.publicDashboard }); + expect(DashboardInteractions.sharingTabChanged).lastCalledWith({ + item: shareDashboardType.publicDashboard, + shareResource: 'dashboard', + }); }); }); diff --git a/public/app/features/dashboard/components/ShareModal/ShareSnapshot.tsx b/public/app/features/dashboard/components/ShareModal/ShareSnapshot.tsx index aa449768aa7..300cdbc29bf 100644 --- a/public/app/features/dashboard/components/ShareModal/ShareSnapshot.tsx +++ b/public/app/features/dashboard/components/ShareModal/ShareSnapshot.tsx @@ -12,6 +12,7 @@ import { VariableRefresh } from '../../../variables/types'; import { getDashboardSnapshotSrv } from '../../services/SnapshotSrv'; import { ShareModalTabProps } from './types'; +import { getTrackingSource } from './utils'; interface Props extends ShareModalTabProps {} @@ -118,11 +119,13 @@ export class ShareSnapshot extends PureComponent { DashboardInteractions.publishSnapshotClicked({ expires: snapshotExpires, timeout: timeoutSeconds, + shareResource: getTrackingSource(this.props.panel), }); } else { DashboardInteractions.publishSnapshotLocalClicked({ expires: snapshotExpires, timeout: timeoutSeconds, + shareResource: getTrackingSource(this.props.panel), }); } this.setState({ isLoading: false }); diff --git a/public/app/features/dashboard/components/ShareModal/utils.ts b/public/app/features/dashboard/components/ShareModal/utils.ts index 90b1664c492..12518e52eeb 100644 --- a/public/app/features/dashboard/components/ShareModal/utils.ts +++ b/public/app/features/dashboard/components/ShareModal/utils.ts @@ -1,5 +1,6 @@ import { dateTime, locationUtil, TimeRange, urlUtil, rangeUtil } from '@grafana/data'; import { config } from '@grafana/runtime'; +import { SceneObjectRef, VizPanel } from '@grafana/scenes'; import { createShortLink } from 'app/core/utils/shortLinks'; import { getTimeSrv } from 'app/features/dashboard/services/TimeSrv'; @@ -162,6 +163,12 @@ export function getLocalTimeZone() { return '&tz=' + encodeURIComponent(options.timeZone); } +export const getTrackingSource = ( + panel?: PanelModel | SceneObjectRef | { timeFrom?: string; id: number } +) => { + return panel ? 'panel' : 'dashboard'; +}; + export const shareDashboardType: { [key: string]: string; } = { diff --git a/public/app/features/library-panels/components/AddLibraryPanelModal/AddLibraryPanelModal.tsx b/public/app/features/library-panels/components/AddLibraryPanelModal/AddLibraryPanelModal.tsx index 73b086913c5..697b9197b6a 100644 --- a/public/app/features/library-panels/components/AddLibraryPanelModal/AddLibraryPanelModal.tsx +++ b/public/app/features/library-panels/components/AddLibraryPanelModal/AddLibraryPanelModal.tsx @@ -23,7 +23,6 @@ export const AddLibraryPanelContents = ({ panel, initialFolderUid, onDismiss }: const [debouncedPanelName, setDebouncedPanelName] = useState(panel.title); const [waiting, setWaiting] = useState(false); - console.log('folderUid', folderUid); useEffect(() => setWaiting(true), [panelName]); useDebounce(() => setDebouncedPanelName(panelName), 350, [panelName]);