Plugins: Track plugin install and uninstall events (#62300)

* chore: track plugin install and uninstall events

* chore: pass the type of the plugin to the tracking as well
This commit is contained in:
Levente Balogh 2023-02-01 10:58:25 +01:00 committed by GitHub
parent 533c8e4b7a
commit f985f02584
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import appEvents from 'app/core/app_events';
import { useQueryParams } from 'app/core/hooks/useQueryParams';
import { useInstallStatus, useUninstallStatus, useInstall, useUninstall } from '../../state/hooks';
import { trackPluginInstalled, trackPluginUninstalled } from '../../tracking';
import { CatalogPlugin, PluginStatus, PluginTabIds, Version } from '../../types';
type InstallControlsButtonProps = {
@ -27,8 +28,14 @@ export function InstallControlsButton({ plugin, pluginStatus, latestCompatibleVe
const showConfirmModal = () => setIsConfirmModalVisible(true);
const hideConfirmModal = () => setIsConfirmModalVisible(false);
const uninstallBtnText = isUninstalling ? 'Uninstalling' : 'Uninstall';
const trackingProps = {
plugin_id: plugin.id,
plugin_type: plugin.type,
path: location.pathname,
};
const onInstall = async () => {
trackPluginInstalled(trackingProps);
await install(plugin.id, latestCompatibleVersion?.version);
if (!errorInstalling) {
appEvents.emit(AppEvents.alertSuccess, [`Installed ${plugin.name}`]);
@ -37,6 +44,7 @@ export function InstallControlsButton({ plugin, pluginStatus, latestCompatibleVe
const onUninstall = async () => {
hideConfirmModal();
trackPluginUninstalled(trackingProps);
await uninstall(plugin.id);
if (!errorUninstalling) {
// If an app plugin is uninstalled we need to reset the active tab when the config / dashboards tabs are removed.

View File

@ -0,0 +1,18 @@
import { reportInteraction } from '@grafana/runtime';
type PluginTrackingProps = {
// The ID of the plugin (e.g. grafana-azure-monitor-datasource)
plugin_id: string;
// The type of the plugin (e.g. 'app' or 'datasource')
plugin_type?: string;
// The path where the plugin details page was rendered (e.g. /plugins/grafana-azure-monitor-datasource )
path: string;
};
export const trackPluginInstalled = (props: PluginTrackingProps) => {
reportInteraction('grafana_plugin_install_clicked', props);
};
export const trackPluginUninstalled = (props: PluginTrackingProps) => {
reportInteraction('grafana_plugin_uninstall_clicked', props);
};