Skip to content

Commit 64f5a68

Browse files
committed
Add analytics for F key usage
Includes activations and "clicks".
1 parent 3c1b29c commit 64f5a68

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

apps/desktop/src/lib/bootstrap/deps.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ import {
8181
USER_SERVICE as CLOUD_USER_SERVICE
8282
} from '@gitbutler/shared/users/userService';
8383
import { DragStateService, DRAG_STATE_SERVICE } from '@gitbutler/ui/drag/dragStateService.svelte';
84+
import { FModeManager } from '@gitbutler/ui/focus/fModeManager';
8485
import { FOCUS_MANAGER, FocusManager } from '@gitbutler/ui/focus/focusManager';
8586
import {
8687
EXTERNAL_LINK_SERVICE,
@@ -212,9 +213,17 @@ export function initDependencies(args: {
212213
// HISTORY & OPERATIONS
213214
// ============================================================================
214215

216+
const fModeManager = new FModeManager();
217+
const focusManager = new FocusManager(fModeManager);
215218
const historyService = new HistoryService(backend, clientState['backendApi']);
216219
const oplogService = new OplogService(clientState['backendApi']);
217-
const commitAnalytics = new CommitAnalytics(stackService, uiState, worktreeService, rulesService);
220+
const commitAnalytics = new CommitAnalytics(
221+
stackService,
222+
uiState,
223+
worktreeService,
224+
rulesService,
225+
fModeManager
226+
);
218227
const codegenAnalytics = new CodegenAnalytics(claudeCodeService, settingsService);
219228

220229
// ============================================================================
@@ -266,7 +275,6 @@ export function initDependencies(args: {
266275
// UI & INTERACTION
267276
// ============================================================================
268277

269-
const focusManager = new FocusManager();
270278
const imeHandler = new IMECompositionHandler();
271279
const reorderDropzoneFactory = new ReorderDropzoneFactory(stackService);
272280
const shortcutService = new ShortcutService(backend);

apps/desktop/src/lib/soup/commitAnalytics.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type { HunkAssignment } from '$lib/hunks/hunk';
1010
import type RulesService from '$lib/rules/rulesService.svelte';
1111
import type { Stack, BranchDetails } from '$lib/stacks/stack';
1212
import type { EventProperties } from '$lib/state/customHooks.svelte';
13+
import type { FModeManager } from '@gitbutler/ui/focus/fModeManager';
1314

1415
export const COMMIT_ANALYTICS = new InjectionToken<CommitAnalytics>('CommitAnalytics');
1516

@@ -18,7 +19,8 @@ export class CommitAnalytics {
1819
private stackService: StackService,
1920
private uiState: UiState,
2021
private worktreeService: WorktreeService,
21-
private readonly rulesService: RulesService
22+
private rulesService: RulesService,
23+
private fModeManager: FModeManager
2224
) {}
2325

2426
async getCommitProperties(args: {
@@ -86,6 +88,8 @@ export class CommitAnalytics {
8688
totalAssignedFiles: this.getAssignedFiles(assignments).length,
8789
// Total number of files that have not been assigned
8890
totalUnassignedFiles: this.getUnassignedFiles(assignments).length,
91+
// Number of times F key shortcuts have been "clicked"
92+
fKeyActivations: this.fModeManager.activations,
8993
// Rule metrics
9094
...this.getRuleMetrics(rules),
9195
// Behavior metrics

packages/ui/src/lib/focus/fModeManager.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ import {
44
createShortcutOverlay,
55
removeShortcutOverlay
66
} from '$lib/focus/shortcutUtils';
7+
import { InjectionToken } from '@gitbutler/core/context';
78
import type { FocusableNode } from '$lib/focus/focusTypes';
89

10+
export const FMODE_MANAGER: InjectionToken<FModeManager> = new InjectionToken('FModeManager');
11+
912
/**
1013
* F-mode allows users to quickly navigate to buttons and containers using
1114
* two-letter keyboard shortcuts (e.g., 'AA', 'AB', etc.).
@@ -19,9 +22,8 @@ export class FModeManager {
1922
private activeOverlays = new Map<HTMLElement, HTMLElement>();
2023
private elementToShortcut = new Map<HTMLElement, string>();
2124

22-
get active(): boolean {
23-
return this._active;
24-
}
25+
// Count of how many shortcuts have been activated.
26+
private _activations = 0;
2527

2628
setFeatureEnabled(enabled: boolean): void {
2729
this.featureEnabled = enabled;
@@ -183,6 +185,7 @@ export class FModeManager {
183185
} else {
184186
element.click();
185187
}
188+
this._activations++;
186189
this.deactivate(); // Auto-exit after activation
187190
}
188191

@@ -240,4 +243,12 @@ export class FModeManager {
240243
}
241244
});
242245
}
246+
247+
get active(): boolean {
248+
return this._active;
249+
}
250+
251+
get activations(): number {
252+
return this._activations;
253+
}
243254
}

packages/ui/src/lib/focus/focusManager.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export class FocusManager {
3232

3333
private previousElements: HTMLElement[] = [];
3434
private indexCache = new Map<HTMLElement, number>();
35-
private fModeManager: FModeManager;
3635

3736
readonly cursor = writable<HTMLElement | undefined>();
3837
readonly outline = writable(false); // external use
@@ -41,9 +40,7 @@ export class FocusManager {
4140
private handleMouse = this.handleClick.bind(this);
4241
private handleKeys = this.handleKeydown.bind(this);
4342

44-
constructor() {
45-
this.fModeManager = new FModeManager();
46-
}
43+
constructor(private fModeManager: FModeManager) {}
4744

4845
setFModeEnabled(enabled: boolean): void {
4946
this.fModeManager.setFeatureEnabled(enabled);

0 commit comments

Comments
 (0)