feat: Add browser connection status to credential setup telemetry event (no-changelog) (#36457)

This commit is contained in:
Dimitri Lavrenük
2026-08-18 11:02:32 +00:00
committed by GitHub
parent 9836cf52a3
commit 950ef236bf
2 changed files with 53 additions and 2 deletions
@@ -748,6 +748,7 @@ describe('InstanceAiCredentialSetup', () => {
settingsStore = useInstanceAiSettingsStore();
vi.spyOn(settingsStore, 'fetchBrowserStatus').mockResolvedValue(undefined);
settingsStore.browserConnected = false;
settingsStore.browserStatusLoaded = true;
// The choice only shows with no usable credentials in the store —
// override the suite-level default of one.
@@ -768,7 +769,43 @@ describe('InstanceAiCredentialSetup', () => {
expect(getByTestId('setup-choice-manual')).toBeTruthy();
expect(mockTelemetryTrack).toHaveBeenCalledWith(
'Instance AI Browser Use credential setup choice shown',
expect.objectContaining({ credential_type: 'type1' }),
expect.objectContaining({
credential_type: 'type1',
browser_connection_state: 'disconnected',
}),
);
});
it('reports the connected state on the shown event', () => {
experiment.enabled = true;
settingsStore.browserConnected = true;
renderCard(makeCredentialRequests(1));
expect(mockTelemetryTrack).toHaveBeenCalledWith(
'Instance AI Browser Use credential setup choice shown',
expect.objectContaining({ browser_connection_state: 'connected' }),
);
});
it('holds the shown event back until the browser status has loaded', async () => {
experiment.enabled = true;
settingsStore.browserStatusLoaded = false;
renderCard(makeCredentialRequests(1));
expect(mockTelemetryTrack).not.toHaveBeenCalledWith(
'Instance AI Browser Use credential setup choice shown',
expect.anything(),
);
settingsStore.browserConnected = true;
settingsStore.browserStatusLoaded = true;
await nextTick();
expect(mockTelemetryTrack).toHaveBeenCalledWith(
'Instance AI Browser Use credential setup choice shown',
expect.objectContaining({ browser_connection_state: 'connected' }),
);
});
@@ -847,6 +884,7 @@ describe('InstanceAiCredentialSetup', () => {
credential_type: 'type1',
choice: 'ai',
credential_setup_attempt_id: confirmedAttemptId,
browser_connection_state: 'connected',
}),
);
});
@@ -864,6 +902,10 @@ describe('InstanceAiCredentialSetup', () => {
expect(openModalSpy).toHaveBeenCalledWith(INSTANCE_AI_BROWSER_USE_SETUP_MODAL_KEY);
expect(confirmSpy).not.toHaveBeenCalled();
expect(mockTelemetryTrack).toHaveBeenCalledWith(
'Instance AI Browser Use User clicked credential setup option',
expect.objectContaining({ choice: 'ai', browser_connection_state: 'disconnected' }),
);
// Simulate the browser connecting (push updates the store).
settingsStore.browserConnected = true;
@@ -506,22 +506,31 @@ async function handleLater() {
await deferWholeCard();
}
const browserConnectionState = computed(() =>
settingsStore.browserConnected ? 'connected' : 'disconnected',
);
function trackSetupChoiceClicked(choice: CredentialSetupChoice | 'skip', attemptId?: string) {
telemetry.track('Instance AI Browser Use User clicked credential setup option', {
credential_type: currentRequest.value?.credentialType,
choice,
browser_connection_state: browserConnectionState.value,
...(attemptId ? { credential_setup_attempt_id: attemptId } : {}),
});
}
const shownChoiceTypes = new Set<string>();
watch(
() => (showSetupChoice.value ? currentRequest.value?.credentialType : undefined),
() =>
showSetupChoice.value && settingsStore.browserStatusLoaded
? currentRequest.value?.credentialType
: undefined,
(credentialType) => {
if (!credentialType || shownChoiceTypes.has(credentialType)) return;
shownChoiceTypes.add(credentialType);
telemetry.track('Instance AI Browser Use credential setup choice shown', {
credential_type: credentialType,
browser_connection_state: browserConnectionState.value,
});
},
{ immediate: true },