From 3164453655394beadeb93e1fe87b94f63c8ce2e0 Mon Sep 17 00:00:00 2001 From: tglide <26071571+TGlide@users.noreply.github.com> Date: Wed, 9 Aug 2023 13:36:30 +0100 Subject: [PATCH] add command tracking --- src/lib/commandCenter/commands.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/lib/commandCenter/commands.ts b/src/lib/commandCenter/commands.ts index b174bc6ec..56c3d18d2 100644 --- a/src/lib/commandCenter/commands.ts +++ b/src/lib/commandCenter/commands.ts @@ -4,6 +4,7 @@ import { wizard } from '$lib/stores/wizard'; import { onMount } from 'svelte'; import { derived, writable } from 'svelte/store'; import { nanoid } from 'nanoid/non-secure'; +import { trackEvent } from '$lib/actions/analytics'; const groups = [ 'ungrouped', @@ -212,7 +213,18 @@ export const registerCommands = { runner((newCommands: Command[]) => { commandMap.update((curr) => { - curr.set(uuid, newCommands); + const commandsWithTracking = newCommands.map((command) => { + const trackingCallback = () => { + if (command.label) { + trackEvent('command', { label: command.label, group: command.group }); + } + command.callback(); + }; + + return { ...command, callback: trackingCallback }; + }); + + curr.set(uuid, commandsWithTracking); return curr; }); });