Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

feat(mobile): count the phone onboarding steps and which sign-in button was used

Dev jacob248e5b1fcd90
diff --git a/backend/src/analytics/dailyProductReview.ts b/backend/src/analytics/dailyProductReview.ts
index 155a7d914..7678bc087 100644
--- a/backend/src/analytics/dailyProductReview.ts
+++ b/backend/src/analytics/dailyProductReview.ts
@@ -1,4 +1,4 @@
-import { PRODUCT_FEEDBACK, PRODUCT_FEEDBACK_REASONS, PRODUCT_FEEDBACK_OUTCOMES, PRODUCT_USAGE_ACTIONS, PRODUCT_USAGE_AUTOMATIC_ACTIONS, PRODUCT_USAGE_FLOWS, PRODUCT_USAGE_SURFACES } from '../types/productUsage.js'
+import { PRODUCT_FEEDBACK, PRODUCT_FEEDBACK_REASONS, PRODUCT_FEEDBACK_OUTCOMES, PRODUCT_USAGE_ACTIONS, PRODUCT_USAGE_AUTOMATIC_ACTIONS, PRODUCT_USAGE_FLOWS, PRODUCT_USAGE_SETUP_FLOWS, PRODUCT_USAGE_SURFACES } from '../types/productUsage.js'
import { DAILY_PRODUCT_METRICS } from './dailyProductUsage.js'
type Row = { dayUtc: Date; metric: string; value: number }
@@ -90,7 +90,7 @@ export function dailyProductReview(rows: Row[], now: Date) {
definition: 'Participating installations with work in two consecutive complete UTC calendar months; late uploads and measurement rollout affect coverage.',
},
flows: ['setup', 'ui'].flatMap(channel => PRODUCT_USAGE_SURFACES.flatMap(surface => PRODUCT_USAGE_FLOWS
- .filter(flow => channel !== 'setup' || ['setup', 'setup_harness', 'setup_tmux', 'setup_clipboard', 'sign_in'].includes(flow))
+ .filter(flow => channel !== 'setup' || (PRODUCT_USAGE_SETUP_FLOWS as readonly string[]).includes(flow))
.map(flow => {
const prefix = `${channel}_${surface}_${flow}_`
const started = c[`${prefix}started`] ?? null
diff --git a/backend/src/types/productUsage.ts b/backend/src/types/productUsage.ts
index 0fb3daa26..e0a276bb0 100644
--- a/backend/src/types/productUsage.ts
+++ b/backend/src/types/productUsage.ts
@@ -13,15 +13,23 @@ export const PRODUCT_USAGE_ACTIONS = ['create', 'resume', 'restart', 'model_chan
export const PRODUCT_USAGE_AUTOMATIC_ACTIONS: readonly typeof PRODUCT_USAGE_ACTIONS[number][] = ['history', 'history_page', 'store_list', 'model_list']
export const PRODUCT_USAGE_FEATURE_MEASURES = ['installation_days', 'first_installations', 'repeat_installation_days'] as const
export const PRODUCT_USAGE_SURFACES = ['desktop', 'phone', 'web'] as const
-export const PRODUCT_USAGE_FLOWS = ['setup', 'setup_harness', 'setup_tmux', 'setup_clipboard', 'sign_in',
- 'workspace_connect', 'computer_link', 'remote_connect', 'viewer_open', 'update_check', 'update_stage'] as const
+/** Flows that can finish before an account exists, so a signed-out report may carry them. The
+ * sign_in_<method> flows split the phone's welcome screen by the button used; sign_in stays the total. */
+export const PRODUCT_USAGE_SETUP_FLOWS = ['setup', 'setup_harness', 'setup_tmux', 'setup_clipboard', 'sign_in',
+ 'sign_in_scan', 'sign_in_google', 'sign_in_apple', 'sign_in_email'] as const
+/** Phone onboarding after sign-in: waiting for a computer, opening its session, the first message
+ * sent there and the notification prompt that follows. Counts and duration buckets only. */
+export const PRODUCT_USAGE_ONBOARDING_FLOWS = ['computer_wait', 'session_open', 'first_message', 'notify_permission'] as const
+export const PRODUCT_USAGE_FLOWS = [...PRODUCT_USAGE_SETUP_FLOWS,
+ 'workspace_connect', 'computer_link', 'remote_connect', 'viewer_open', 'update_check', 'update_stage',
+ ...PRODUCT_USAGE_ONBOARDING_FLOWS] as const
export const PRODUCT_USAGE_FLOW_MEASURES = ['started', 'ok', 'failed', 'cancelled', 'unknown',
'under_1s', '1s_to_10s', '10s_to_1m', 'over_1m'] as const
export const PRODUCT_USAGE_UI_METRICS = PRODUCT_USAGE_SURFACES.flatMap(surface =>
PRODUCT_USAGE_FLOWS.flatMap(flow => PRODUCT_USAGE_FLOW_MEASURES.map(measure => `ui_${surface}_${flow}_${measure}` as const)))
// A signed-out report is explicitly enabled on this app. It cannot carry account/work metrics.
export const PRODUCT_USAGE_SETUP_METRICS = PRODUCT_USAGE_SURFACES.flatMap(surface =>
- (['setup', 'setup_harness', 'setup_tmux', 'setup_clipboard', 'sign_in'] as const).flatMap(flow =>
+ PRODUCT_USAGE_SETUP_FLOWS.flatMap(flow =>
PRODUCT_USAGE_FLOW_MEASURES.map(measure => `setup_${surface}_${flow}_${measure}` as const)))
export const PRODUCT_USAGE_ACTION_MEASURES = ['requests', 'ok', 'failed', 'pending', 'unknown',
'error_setup', 'error_auth', 'error_unavailable', 'error_invalid', 'error_other',
diff --git a/cli/src/lib/productUsageContract.ts b/cli/src/lib/productUsageContract.ts
index 0fb3daa26..e0a276bb0 100644
--- a/cli/src/lib/productUsageContract.ts
+++ b/cli/src/lib/productUsageContract.ts
@@ -13,15 +13,23 @@ export const PRODUCT_USAGE_ACTIONS = ['create', 'resume', 'restart', 'model_chan
export const PRODUCT_USAGE_AUTOMATIC_ACTIONS: readonly typeof PRODUCT_USAGE_ACTIONS[number][] = ['history', 'history_page', 'store_list', 'model_list']
export const PRODUCT_USAGE_FEATURE_MEASURES = ['installation_days', 'first_installations', 'repeat_installation_days'] as const
export const PRODUCT_USAGE_SURFACES = ['desktop', 'phone', 'web'] as const
-export const PRODUCT_USAGE_FLOWS = ['setup', 'setup_harness', 'setup_tmux', 'setup_clipboard', 'sign_in',
- 'workspace_connect', 'computer_link', 'remote_connect', 'viewer_open', 'update_check', 'update_stage'] as const
+/** Flows that can finish before an account exists, so a signed-out report may carry them. The
+ * sign_in_<method> flows split the phone's welcome screen by the button used; sign_in stays the total. */
+export const PRODUCT_USAGE_SETUP_FLOWS = ['setup', 'setup_harness', 'setup_tmux', 'setup_clipboard', 'sign_in',
+ 'sign_in_scan', 'sign_in_google', 'sign_in_apple', 'sign_in_email'] as const
+/** Phone onboarding after sign-in: waiting for a computer, opening its session, the first message
+ * sent there and the notification prompt that follows. Counts and duration buckets only. */
+export const PRODUCT_USAGE_ONBOARDING_FLOWS = ['computer_wait', 'session_open', 'first_message', 'notify_permission'] as const
+export const PRODUCT_USAGE_FLOWS = [...PRODUCT_USAGE_SETUP_FLOWS,
+ 'workspace_connect', 'computer_link', 'remote_connect', 'viewer_open', 'update_check', 'update_stage',
+ ...PRODUCT_USAGE_ONBOARDING_FLOWS] as const
export const PRODUCT_USAGE_FLOW_MEASURES = ['started', 'ok', 'failed', 'cancelled', 'unknown',
'under_1s', '1s_to_10s', '10s_to_1m', 'over_1m'] as const
export const PRODUCT_USAGE_UI_METRICS = PRODUCT_USAGE_SURFACES.flatMap(surface =>
PRODUCT_USAGE_FLOWS.flatMap(flow => PRODUCT_USAGE_FLOW_MEASURES.map(measure => `ui_${surface}_${flow}_${measure}` as const)))
// A signed-out report is explicitly enabled on this app. It cannot carry account/work metrics.
export const PRODUCT_USAGE_SETUP_METRICS = PRODUCT_USAGE_SURFACES.flatMap(surface =>
- (['setup', 'setup_harness', 'setup_tmux', 'setup_clipboard', 'sign_in'] as const).flatMap(flow =>
+ PRODUCT_USAGE_SETUP_FLOWS.flatMap(flow =>
PRODUCT_USAGE_FLOW_MEASURES.map(measure => `setup_${surface}_${flow}_${measure}` as const)))
export const PRODUCT_USAGE_ACTION_MEASURES = ['requests', 'ok', 'failed', 'pending', 'unknown',
'error_setup', 'error_auth', 'error_unavailable', 'error_invalid', 'error_other',
diff --git a/desktop/lib/measurement/product_measurement.dart b/desktop/lib/measurement/product_measurement.dart
index 8eb19d2dc..fe6eb580f 100644
--- a/desktop/lib/measurement/product_measurement.dart
+++ b/desktop/lib/measurement/product_measurement.dart
@@ -3,22 +3,34 @@ import 'dart:math';
import 'package:flutter/foundation.dart';
+/// Mirrors `PRODUCT_USAGE_FLOWS` in backend/src/types/productUsage.ts; a wire name the backend
+/// does not list rejects the whole report.
enum ProductFlow {
- setup('setup'),
- setupHarness('setup_harness'),
- setupTmux('setup_tmux'),
- setupClipboard('setup_clipboard'),
- signIn('sign_in'),
+ setup('setup', beforeSignIn: true),
+ setupHarness('setup_harness', beforeSignIn: true),
+ setupTmux('setup_tmux', beforeSignIn: true),
+ setupClipboard('setup_clipboard', beforeSignIn: true),
+ signIn('sign_in', beforeSignIn: true),
+ signInScan('sign_in_scan', beforeSignIn: true),
+ signInGoogle('sign_in_google', beforeSignIn: true),
+ signInApple('sign_in_apple', beforeSignIn: true),
+ signInEmail('sign_in_email', beforeSignIn: true),
workspaceConnect('workspace_connect'),
computerLink('computer_link'),
remoteConnect('remote_connect'),
viewerOpen('viewer_open'),
updateCheck('update_check'),
- updateStage('update_stage');
+ updateStage('update_stage'),
+ computerWait('computer_wait'),
+ sessionOpen('session_open'),
+ firstMessage('first_message'),
+ notifyPermission('notify_permission');
- const ProductFlow(this.wire);
+ const ProductFlow(this.wire, {this.beforeSignIn = false});
final String wire;
- bool get beforeSignIn => index <= ProductFlow.signIn.index;
+
+ /// Whether a signed-out session that opted in may count it.
+ final bool beforeSignIn;
}
enum ProductOutcome { ok, failed, cancelled, unknown }
@@ -127,7 +139,11 @@ class ProductMeasurement extends ChangeNotifier {
_active.removeWhere((_, value) => value == channel);
}
- void Function(ProductOutcome) begin(ProductFlow flow) {
+ /// [elapsed] is time the flow already ran before it could be counted; it lands in the duration.
+ void Function(ProductOutcome) begin(
+ ProductFlow flow, {
+ Duration elapsed = Duration.zero,
+ }) {
final channel = sharing
? 'ui'
: flow.beforeSignIn && _setupAllowed
@@ -155,7 +171,7 @@ class ProductMeasurement extends ChangeNotifier {
return;
}
_count(channel, day, '$prefix${outcome.name}');
- final ms = watch.elapsedMilliseconds;
+ final ms = watch.elapsedMilliseconds + elapsed.inMilliseconds;
_count(
channel,
day,
@@ -170,6 +186,16 @@ class ProductMeasurement extends ChangeNotifier {
};
}
+ /// One attempt counted under several flows at once — `sign_in` and the button that started it.
+ void Function(ProductOutcome) beginEach(List<ProductFlow> flows) {
+ final finishers = [for (final flow in flows) begin(flow)];
+ return (outcome) {
+ for (final finish in finishers) {
+ finish(outcome);
+ }
+ };
+ }
+
/// The adapter hands over only enum-derived status names, never setup logs or commands.
void setupFacts(Map<ProductFlow, String> facts) {
_setupFacts
diff --git a/desktop/test/remote_connect_measurement_test.dart b/desktop/test/remote_connect_measurement_test.dart
index 271814946..4299f5c99 100644
--- a/desktop/test/remote_connect_measurement_test.dart
+++ b/desktop/test/remote_connect_measurement_test.dart
@@ -13,7 +13,7 @@ class _Recorder extends ProductMeasurement {
final ended = <String>[];
@override
- void Function(ProductOutcome) begin(ProductFlow flow) =>
+ void Function(ProductOutcome) begin(ProductFlow flow, {Duration elapsed = Duration.zero}) =>
(outcome) => ended.add('${flow.name}:${outcome.name}');
}
diff --git a/mobile/lib/measurement/onboarding_measurement.dart b/mobile/lib/measurement/onboarding_measurement.dart
new file mode 100644
index 000000000..db7c8f0de
--- /dev/null
+++ b/mobile/lib/measurement/onboarding_measurement.dart
@@ -0,0 +1,70 @@
+import 'product_measurement.dart';
+
+/// The phone's onboarding after sign-in, as fixed flows that hand over to each other: waiting for a
+/// computer → opening its session → the first message sent there → the notification prompt.
+///
+/// Counts and duration buckets only, through [ProductMeasurement]: no account, computer, session,
+/// message or answer text, and nothing at all unless the account shares product usage.
+///
+/// Each flow runs once per sign-in ([reset] on sign-out). A step that starts before the account's
+/// sharing choice has loaded — right after sign-in — waits here, and is counted from when it really
+/// started once sharing is confirmed; a step that ends before then is never counted.
+class OnboardingMeasurement {
+ OnboardingMeasurement(this._usage) {
+ _usage.addListener(_admit);
+ }
+
+ final ProductMeasurement _usage;
+ final _waiting = <ProductFlow, Stopwatch>{};
+ final _running = <ProductFlow, void Function(ProductOutcome)>{};
+ final _seen = <ProductFlow>{};
+
+ /// Starts [flow] the first time it is asked for in this sign-in; build methods may call it on
+ /// every frame.
+ void start(ProductFlow flow) {
+ if (!_seen.add(flow)) return;
+ _waiting[flow] = Stopwatch()..start();
+ _admit();
+ }
+
+ /// Ends [flow] with [outcome] if it is running; otherwise nothing.
+ void end(ProductFlow flow, ProductOutcome outcome) {
+ _waiting.remove(flow);
+ _running.remove(flow)?.call(outcome);
+ }
+
+ /// Asks the OS for notifications through [ask], counting the answer: allowed is `ok`, refused is
+ /// `cancelled`, no answer is `unknown`.
+ Future<void> askNotifications(Future<bool?> Function() ask) async {
+ start(ProductFlow.notifyPermission);
+ final allowed = await ask();
+ end(ProductFlow.notifyPermission, switch (allowed) {
+ true => ProductOutcome.ok,
+ false => ProductOutcome.cancelled,
+ null => ProductOutcome.unknown,
+ });
+ }
+
+ /// Signed out: whatever was still running was abandoned, and the next sign-in starts afresh.
+ void reset() {
+ for (final flow in [..._running.keys]) {
+ end(flow, ProductOutcome.cancelled);
+ }
+ _waiting.clear();
+ _seen.clear();
+ }
+
+ void _admit() {
+ if (!_usage.sharing || _waiting.isEmpty) return;
+ for (final MapEntry(key: flow, value: watch) in [..._waiting.entries]) {
+ _waiting.remove(flow);
+ _running[flow] = _usage.begin(flow, elapsed: watch.elapsed);
+ }
+ }
+
+ void dispose() {
+ _usage.removeListener(_admit);
+ _waiting.clear();
+ _running.clear();
+ }
+}
diff --git a/mobile/lib/measurement/product_measurement.dart b/mobile/lib/measurement/product_measurement.dart
index 8eb19d2dc..fe6eb580f 100644
--- a/mobile/lib/measurement/product_measurement.dart
+++ b/mobile/lib/measurement/product_measurement.dart
@@ -3,22 +3,34 @@ import 'dart:math';
import 'package:flutter/foundation.dart';
+/// Mirrors `PRODUCT_USAGE_FLOWS` in backend/src/types/productUsage.ts; a wire name the backend
+/// does not list rejects the whole report.
enum ProductFlow {
- setup('setup'),
- setupHarness('setup_harness'),
- setupTmux('setup_tmux'),
- setupClipboard('setup_clipboard'),
- signIn('sign_in'),
+ setup('setup', beforeSignIn: true),
+ setupHarness('setup_harness', beforeSignIn: true),
+ setupTmux('setup_tmux', beforeSignIn: true),
+ setupClipboard('setup_clipboard', beforeSignIn: true),
+ signIn('sign_in', beforeSignIn: true),
+ signInScan('sign_in_scan', beforeSignIn: true),
+ signInGoogle('sign_in_google', beforeSignIn: true),
+ signInApple('sign_in_apple', beforeSignIn: true),
+ signInEmail('sign_in_email', beforeSignIn: true),
workspaceConnect('workspace_connect'),
computerLink('computer_link'),
remoteConnect('remote_connect'),
viewerOpen('viewer_open'),
updateCheck('update_check'),
- updateStage('update_stage');
+ updateStage('update_stage'),
+ computerWait('computer_wait'),
+ sessionOpen('session_open'),
+ firstMessage('first_message'),
+ notifyPermission('notify_permission');
- const ProductFlow(this.wire);
+ const ProductFlow(this.wire, {this.beforeSignIn = false});
final String wire;
- bool get beforeSignIn => index <= ProductFlow.signIn.index;
+
+ /// Whether a signed-out session that opted in may count it.
+ final bool beforeSignIn;
}
enum ProductOutcome { ok, failed, cancelled, unknown }
@@ -127,7 +139,11 @@ class ProductMeasurement extends ChangeNotifier {
_active.removeWhere((_, value) => value == channel);
}
- void Function(ProductOutcome) begin(ProductFlow flow) {
+ /// [elapsed] is time the flow already ran before it could be counted; it lands in the duration.
+ void Function(ProductOutcome) begin(
+ ProductFlow flow, {
+ Duration elapsed = Duration.zero,
+ }) {
final channel = sharing
? 'ui'
: flow.beforeSignIn && _setupAllowed
@@ -155,7 +171,7 @@ class ProductMeasurement extends ChangeNotifier {
return;
}
_count(channel, day, '$prefix${outcome.name}');
- final ms = watch.elapsedMilliseconds;
+ final ms = watch.elapsedMilliseconds + elapsed.inMilliseconds;
_count(
channel,
day,
@@ -170,6 +186,16 @@ class ProductMeasurement extends ChangeNotifier {
};
}
+ /// One attempt counted under several flows at once — `sign_in` and the button that started it.
+ void Function(ProductOutcome) beginEach(List<ProductFlow> flows) {
+ final finishers = [for (final flow in flows) begin(flow)];
+ return (outcome) {
+ for (final finish in finishers) {
+ finish(outcome);
+ }
+ };
+ }
+
/// The adapter hands over only enum-derived status names, never setup logs or commands.
void setupFacts(Map<ProductFlow, String> facts) {
_setupFacts
diff --git a/mobile/lib/notify/system_notices.dart b/mobile/lib/notify/system_notices.dart
index a88c26f2d..551192eb2 100644
--- a/mobile/lib/notify/system_notices.dart
+++ b/mobile/lib/notify/system_notices.dart
@@ -23,8 +23,9 @@ typedef AgentNoticeMessage = ({
/// [SilentSystemNotices].
abstract interface class SystemNotices {
/// Asks the person, once, whether the phone may notify them. The OS
- /// remembers the answer; asking again is a no-op.
- Future<void> requestPermission();
+ /// remembers the answer; asking again is a no-op. True when allowed, false
+ /// when refused, null when nothing could say.
+ Future<bool?> requestPermission();
Future<void> show(AgentNoticeMessage message);
@@ -54,7 +55,7 @@ class SilentSystemNotices implements SystemNotices {
final openedDevice = ValueNotifier<String?>(null);
@override
- Future<void> requestPermission() async {}
+ Future<bool?> requestPermission() async => null;
@override
Future<void> show(AgentNoticeMessage message) async {}
@@ -165,21 +166,23 @@ class LocalSystemNotices implements SystemNotices {
}
@override
- Future<void> requestPermission() async {
+ Future<bool?> requestPermission() async {
try {
await _init();
- await _plugin
+ final ios = await _plugin
.resolvePlatformSpecificImplementation<
IOSFlutterLocalNotificationsPlugin
>()
?.requestPermissions(alert: true, sound: true);
- await _plugin
+ final android = await _plugin
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin
>()
?.requestNotificationsPermission();
+ return ios ?? android;
} catch (error) {
appLog.warn('notify', 'permission request failed', error: error);
+ return null;
}
}
diff --git a/mobile/lib/phone/agent_home.dart b/mobile/lib/phone/agent_home.dart
index 6488d3ca0..44bdffa5f 100644
--- a/mobile/lib/phone/agent_home.dart
+++ b/mobile/lib/phone/agent_home.dart
@@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
import 'package:harness_mobile/demo/sample_mode.dart';
import 'package:harness_mobile/logging/startup_trace.dart';
import 'package:harness_mobile/logging/typing_trace.dart';
+import 'package:harness_mobile/measurement/product_measurement.dart';
import 'package:harness_mobile/shared/theme/app_theme.dart';
import 'package:harness_mobile/core/models.dart';
import 'package:harness_mobile/state/app_state.dart';
@@ -944,6 +945,7 @@ class _AgentHomeState extends State<AgentHome>
_endLaunchWait();
// The onboarding handing over to the session it was waiting for: it grows in, once.
final handOver = _onboarding && _joining != null;
+ if (_onboarding) _measureHandOver(handOver);
// Nothing remembered, nothing picked: the sessions, each a tap from its terminal — but not at
// the end of the onboarding, which opens the computer's own session ([_target]).
if (!handOver &&
@@ -1120,7 +1122,10 @@ class _AgentHomeState extends State<AgentHome>
/// and this screen moves on; with one of the person's other Google accounts, and it never does.
Widget _goToYourComputer() {
final notifier = widget.notifier;
- if (_onboarding) _awaitedComputer = true;
+ if (_onboarding) {
+ _awaitedComputer = true;
+ notifier.onboardingMeasurement.start(ProductFlow.computerWait);
+ }
return OnboardingStage(
headline: OnboardingCopy.goToHeadline,
headlineKey: const ValueKey('home-go-to'),
@@ -1157,6 +1162,10 @@ class _AgentHomeState extends State<AgentHome>
final machine = notifier.machines.firstOrNull;
if (machine == null) return;
_joining = (machineId: machine.machineId, name: machine.displayName);
+ notifier.onboardingMeasurement.end(
+ ProductFlow.computerWait,
+ ProductOutcome.ok,
+ );
// After the frame: it may take a "New device" down, which notifies — not during a build.
final welcomed = machine.machineId;
WidgetsBinding.instance.addPostFrameCallback((_) {
@@ -1175,6 +1184,7 @@ class _AgentHomeState extends State<AgentHome>
name: ready.machine.displayName,
);
}
+ notifier.onboardingMeasurement.start(ProductFlow.sessionOpen);
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) _moment.start();
});
@@ -1206,10 +1216,25 @@ class _AgentHomeState extends State<AgentHome>
};
}
+ /// The onboarding ends: its session opened by itself, and the first message there is next — or
+ /// the person went on to another session without it.
+ void _measureHandOver(bool handOver) {
+ final onboarding = widget.notifier.onboardingMeasurement;
+ onboarding.end(
+ ProductFlow.sessionOpen,
+ handOver ? ProductOutcome.ok : ProductOutcome.cancelled,
+ );
+ if (handOver) onboarding.start(ProductFlow.firstMessage);
+ }
+
/// Arms [_firstSessionPatience] on the first frame that waits for it. Called from build: a timer,
/// not a rebuild.
bool _waitForFirstSession() {
_firstSessionWait ??= Timer(_firstSessionPatience, () {
+ widget.notifier.onboardingMeasurement.end(
+ ProductFlow.sessionOpen,
+ ProductOutcome.failed,
+ );
if (!mounted) return;
setState(() => _firstSessionGaveUp = true);
});
diff --git a/mobile/lib/phone/terminal_page.dart b/mobile/lib/phone/terminal_page.dart
index 8849132b0..f46ee7c96 100644
--- a/mobile/lib/phone/terminal_page.dart
+++ b/mobile/lib/phone/terminal_page.dart
@@ -1,3 +1,4 @@
+import '../measurement/product_measurement.dart';
import '../measurement/task_feedback.dart';
import 'dart:async';
import 'dart:ui' as ui;
@@ -830,7 +831,12 @@ class _TerminalPageState extends State<TerminalPage>
if (session?.voiceDeliver == _deliverVoice) session?.voiceDeliver = null;
if (session?.onLineSent == _onLineSent) session?.onLineSent = null;
// Said once: leaving the session spends the onboarding's line too.
- _spendFirstSessionLine();
+ if (_spendFirstSessionLine()) {
+ widget.notifier.onboardingMeasurement.end(
+ ProductFlow.firstMessage,
+ ProductOutcome.cancelled,
+ );
+ }
_barMessageTimer?.cancel();
_barMessage.dispose();
_scrollback.dispose();
@@ -1065,12 +1071,17 @@ class _TerminalPageState extends State<TerminalPage>
/// Not in the sample: nothing there reaches a harness, and its notices would be for nothing.
void _onLineSent() {
if (!mounted || SampleMode.maybeOf(context) != null) return;
+ final onboarding = widget.notifier.onboardingMeasurement;
unawaited(
NotificationsAsk.shared.afterSend(
- widget.notifier.agentNotices.system.requestPermission,
+ () => onboarding.askNotifications(
+ widget.notifier.agentNotices.system.requestPermission,
+ ),
),
);
- if (_spendFirstSessionLine()) setState(() {});
+ if (!_spendFirstSessionLine()) return;
+ onboarding.end(ProductFlow.firstMessage, ProductOutcome.ok);
+ setState(() {});
}
/// Whether [session] is a kept screen standing in while its stream attaches — drawn like the live
diff --git a/mobile/lib/state/app_state.dart b/mobile/lib/state/app_state.dart
index f88ddeab2..b779917c6 100644
--- a/mobile/lib/state/app_state.dart
+++ b/mobile/lib/state/app_state.dart
@@ -1,4 +1,5 @@
import '../core/test_run.dart';
+import '../measurement/onboarding_measurement.dart';
import '../measurement/product_measurement.dart';
import '../measurement/setup_transport.dart';
@@ -274,6 +275,9 @@ class AppNotifier extends ChangeNotifier {
AppConfig config;
late ApiClient api;
late final ProductMeasurement productMeasurement;
+
+ /// The phone's onboarding steps after sign-in, counted through [productMeasurement].
+ late final onboardingMeasurement = OnboardingMeasurement(productMeasurement);
final _measurementConnections = <String, void Function(ProductOutcome)>{};
/// Says whether this device is signed in, and signs it out: [ViewerServices.login], the app's own
@@ -1712,6 +1716,7 @@ class AppNotifier extends ChangeNotifier {
_lastErrorRetryable = true;
signedOutReason = _signedOutEnded;
signedInThisRun = false;
+ onboardingMeasurement.reset();
welcomedMachines.clear();
firstSessionLine = null;
status = AppStatus.unauthenticated;
@@ -1729,6 +1734,10 @@ class AppNotifier extends ChangeNotifier {
/// `viewer/email_code_api.dart`.
Future<void> sendLoginCode(String email) => viewer.emailLogin.sendCode(email);
+ /// A sign-in attempt, counted as `sign_in` and under the welcome-screen button that started it.
+ void Function(ProductOutcome) _measureSignIn(ProductFlow method) =>
+ productMeasurement.beginEach([ProductFlow.signIn, method]);
+
/// The phone's sign-in, second step: trade the emailed [code] for a session
/// and go in.
///
@@ -1743,7 +1752,7 @@ class AppNotifier extends ChangeNotifier {
}) async {
final login = viewer.emailLogin;
if (_disposed || signingIn) return;
- final measureSignIn = productMeasurement.begin(ProductFlow.signIn);
+ final measureSignIn = _measureSignIn(ProductFlow.signInEmail);
final revision = _invalidateAuthWork();
_closedHistory.clear();
_lastError = null;
@@ -1783,7 +1792,7 @@ class AppNotifier extends ChangeNotifier {
Future<void> signInWithScan(String code) async {
final login = viewer.emailLogin;
if (_disposed || signingIn) return;
- final measureSignIn = productMeasurement.begin(ProductFlow.signIn);
+ final measureSignIn = _measureSignIn(ProductFlow.signInScan);
final revision = _invalidateAuthWork();
_closedHistory.clear();
_lastError = null;
@@ -1826,6 +1835,10 @@ class AppNotifier extends ChangeNotifier {
Future<void> signInWithProvider(SignInProvider provider) async {
final login = viewer.login;
if (_disposed || signingIn) return;
+ final measureSignIn = _measureSignIn(switch (provider) {
+ SignInProvider.google => ProductFlow.signInGoogle,
+ SignInProvider.apple => ProductFlow.signInApple,
+ });
final revision = _invalidateAuthWork();
_closedHistory.clear();
_lastError = null;
@@ -1843,17 +1856,25 @@ class AppNotifier extends ChangeNotifier {
unawaited(closeSignInPage());
if (!_authWorkCurrent(revision)) return;
signedInThisRun = true;
+ measureSignIn(ProductOutcome.ok);
status = AppStatus.bootstrapping;
notifyListeners();
await _enterSignedIn(revision);
} on SignInCancelled {
+ measureSignIn(ProductOutcome.cancelled);
unawaited(closeSignInPage());
if (_authWorkCurrent(revision)) status = AppStatus.unauthenticated;
} catch (_) {
+ measureSignIn(ProductOutcome.failed);
unawaited(closeSignInPage());
if (_authWorkCurrent(revision)) status = AppStatus.unauthenticated;
rethrow;
} finally {
+ measureSignIn(
+ _authWorkCurrent(revision)
+ ? ProductOutcome.unknown
+ : ProductOutcome.cancelled,
+ );
if (_authWorkCurrent(revision)) {
signingIn = false;
signInProvider = null;
@@ -2002,6 +2023,7 @@ class AppNotifier extends ChangeNotifier {
selectedMachineId = null;
signedOutReason = reason;
signedInThisRun = false;
+ onboardingMeasurement.reset();
welcomedMachines.clear();
firstSessionLine = null;
status = AppStatus.unauthenticated;
@@ -8861,6 +8883,7 @@ class AppNotifier extends ChangeNotifier {
@override
void dispose() {
+ onboardingMeasurement.dispose();
productMeasurement.dispose();
_measurementConnections.clear();
_disposed = true;
diff --git a/mobile/test/notify/agent_announcer_test.dart b/mobile/test/notify/agent_announcer_test.dart
index 7feb5debb..7e2a01669 100644
--- a/mobile/test/notify/agent_announcer_test.dart
+++ b/mobile/test/notify/agent_announcer_test.dart
@@ -17,7 +17,7 @@ class _RecordingNotices implements SystemNotices {
final openedDevice = ValueNotifier<String?>(null);
@override
- Future<void> requestPermission() async {}
+ Future<bool?> requestPermission() async => null;
@override
Future<void> show(AgentNoticeMessage message) async => shown.add(message);
diff --git a/mobile/test/onboarding_measurement_test.dart b/mobile/test/onboarding_measurement_test.dart
new file mode 100644
index 000000000..3ff624879
--- /dev/null
+++ b/mobile/test/onboarding_measurement_test.dart
@@ -0,0 +1,145 @@
+import 'dart:convert';
+import 'dart:io';
+
+import 'package:flutter_test/flutter_test.dart';
+
+import 'package:harness_mobile/measurement/onboarding_measurement.dart';
+import 'package:harness_mobile/measurement/product_measurement.dart';
+
+void main() {
+ late ProductMeasurement usage;
+ late OnboardingMeasurement onboarding;
+ late List<Map<String, dynamic>> reports;
+ late Map<String, dynamic> choice;
+
+ setUp(() {
+ reports = [];
+ choice = {'enabled': true, 'revision': 0};
+ usage = ProductMeasurement(
+ surface: 'phone',
+ automatic: false,
+ now: () => DateTime.utc(2026, 10, 14, 12),
+ sendSetup: (r) async => {'accepted': true},
+ );
+ onboarding = OnboardingMeasurement(usage);
+ });
+ tearDown(() {
+ onboarding.dispose();
+ usage.dispose();
+ });
+
+ Future<void> signIn() async {
+ usage.account(
+ 'PRIVATE_ACCOUNT',
+ choice: () async => choice,
+ send: (r) async {
+ reports.add(jsonDecode(jsonEncode(r)));
+ return {'accepted': true};
+ },
+ );
+ await usage.flush();
+ }
+
+ Map<String, dynamic> counters() => {
+ for (final r in reports) ...(r['counters'] as Map<String, dynamic>),
+ };
+
+ test('a step started before sharing loads is counted once it does', () async {
+ onboarding.start(ProductFlow.computerWait);
+ await signIn();
+ onboarding.end(ProductFlow.computerWait, ProductOutcome.ok);
+ await usage.flush();
+ expect(counters(), {
+ 'ui_phone_computer_wait_started': 1,
+ 'ui_phone_computer_wait_ok': 1,
+ 'ui_phone_computer_wait_under_1s': 1,
+ });
+ });
+
+ test('a step that ends before sharing is confirmed is never counted', () async {
+ onboarding.start(ProductFlow.computerWait);
+ onboarding.end(ProductFlow.computerWait, ProductOutcome.ok);
+ await signIn();
+ await usage.flush();
+ expect(counters(), isEmpty);
+ });
+
+ test('nothing is counted while the account does not share', () async {
+ choice = {'enabled': false, 'revision': 1};
+ await signIn();
+ onboarding.start(ProductFlow.sessionOpen);
+ onboarding.end(ProductFlow.sessionOpen, ProductOutcome.ok);
+ await usage.flush();
+ expect(reports, isEmpty);
+ });
+
+ test('each step runs once per sign-in; signing out abandons it', () async {
+ await signIn();
+ onboarding.start(ProductFlow.sessionOpen);
+ onboarding.start(ProductFlow.sessionOpen);
+ onboarding.reset();
+ onboarding.end(ProductFlow.sessionOpen, ProductOutcome.ok);
+ onboarding.start(ProductFlow.sessionOpen);
+ await usage.flush();
+ expect(counters(), {
+ 'ui_phone_session_open_started': 2,
+ 'ui_phone_session_open_cancelled': 1,
+ 'ui_phone_session_open_under_1s': 1,
+ });
+ });
+
+ test('the notification answer is an outcome, never more', () async {
+ await signIn();
+ await onboarding.askNotifications(() async => false);
+ await onboarding.askNotifications(() async => true);
+ await usage.flush();
+ expect(counters(), {
+ 'ui_phone_notify_permission_started': 1,
+ 'ui_phone_notify_permission_cancelled': 1,
+ 'ui_phone_notify_permission_under_1s': 1,
+ });
+ });
+
+ test('time spent waiting for sharing lands in the duration', () async {
+ await signIn();
+ usage.begin(
+ ProductFlow.firstMessage,
+ elapsed: const Duration(seconds: 12),
+ )(ProductOutcome.ok);
+ await usage.flush();
+ expect(counters()['ui_phone_first_message_10s_to_1m'], 1);
+ });
+
+ test('a sign-in counts the total and the button, without identifiers', () async {
+ await signIn();
+ usage.beginEach([ProductFlow.signIn, ProductFlow.signInGoogle])(
+ ProductOutcome.ok,
+ );
+ await usage.flush();
+ expect(reports.single.keys.toSet(), {
+ 'schemaVersion',
+ 'id',
+ 'day',
+ 'counters',
+ 'revision',
+ });
+ expect(counters(), {
+ 'ui_phone_sign_in_started': 1,
+ 'ui_phone_sign_in_ok': 1,
+ 'ui_phone_sign_in_under_1s': 1,
+ 'ui_phone_sign_in_google_started': 1,
+ 'ui_phone_sign_in_google_ok': 1,
+ 'ui_phone_sign_in_google_under_1s': 1,
+ });
+ expect(jsonEncode(reports), isNot(contains('PRIVATE_ACCOUNT')));
+ });
+
+ test('every flow is in the backend vocabulary', () {
+ final vocabulary = File(
+ '../backend/src/types/productUsage.ts',
+ ).readAsStringSync();
+ for (final flow in ProductFlow.values) {
+ expect(vocabulary, contains("'${flow.wire}'"), reason: flow.wire);
+ }
+ });
+}