diff --git a/packages/devtools_app/lib/src/screens/dtd/dtd_tools_screen.dart b/packages/devtools_app/lib/src/screens/dtd/dtd_tools_screen.dart index cf74e65e6e3..000fbedbabd 100644 --- a/packages/devtools_app/lib/src/screens/dtd/dtd_tools_screen.dart +++ b/packages/devtools_app/lib/src/screens/dtd/dtd_tools_screen.dart @@ -9,6 +9,8 @@ import 'package:devtools_app_shared/ui.dart'; import 'package:dtd/dtd.dart'; import 'package:material_ui/material_ui.dart'; +import '../../shared/analytics/analytics.dart' as ga; +import '../../shared/analytics/constants.dart' as gac; import '../../shared/development_helpers.dart'; import '../../shared/framework/screen.dart'; import '../../shared/globals.dart'; @@ -31,9 +33,20 @@ class DTDToolsScreen extends Screen { Widget buildScreenBody(BuildContext _) => const DTDToolsScreenBody(); } -class DTDToolsScreenBody extends StatelessWidget { +class DTDToolsScreenBody extends StatefulWidget { const DTDToolsScreenBody({super.key}); + @override + State createState() => _DTDToolsScreenBodyState(); +} + +class _DTDToolsScreenBodyState extends State { + @override + void initState() { + super.initState(); + ga.screen(gac.dtdTools); + } + @override Widget build(BuildContext context) { final controller = screenControllers.lookup(); diff --git a/packages/devtools_app/lib/src/screens/vm_developer/isolate_statistics/isolate_statistics_view.dart b/packages/devtools_app/lib/src/screens/vm_developer/isolate_statistics/isolate_statistics_view.dart index dd59a5f657d..fe24652a156 100644 --- a/packages/devtools_app/lib/src/screens/vm_developer/isolate_statistics/isolate_statistics_view.dart +++ b/packages/devtools_app/lib/src/screens/vm_developer/isolate_statistics/isolate_statistics_view.dart @@ -24,7 +24,11 @@ import 'isolate_statistics_view_controller.dart'; /// isolate. class IsolateStatisticsView extends VMDeveloperView { const IsolateStatisticsView() - : super(title: 'Isolates', icon: Icons.bar_chart); + : super( + title: 'Isolates', + icon: Icons.bar_chart, + gaEvent: gac.VmToolsEvents.isolateStatistics, + ); @override bool get showIsolateSelector => true; diff --git a/packages/devtools_app/lib/src/screens/vm_developer/object_inspector/object_inspector_view.dart b/packages/devtools_app/lib/src/screens/vm_developer/object_inspector/object_inspector_view.dart index b4711b5fc6f..d321d3b3a65 100644 --- a/packages/devtools_app/lib/src/screens/vm_developer/object_inspector/object_inspector_view.dart +++ b/packages/devtools_app/lib/src/screens/vm_developer/object_inspector/object_inspector_view.dart @@ -23,7 +23,11 @@ import 'object_viewport.dart'; /// information about objects in the Dart VM. class ObjectInspectorView extends VMDeveloperView { ObjectInspectorView() - : super(title: 'Objects', icon: Icons.data_object_outlined); + : super( + title: 'Objects', + icon: Icons.data_object_outlined, + gaEvent: gac.VmToolsEvents.objectInspector, + ); @override bool get showIsolateSelector => true; diff --git a/packages/devtools_app/lib/src/screens/vm_developer/process_memory/process_memory_view.dart b/packages/devtools_app/lib/src/screens/vm_developer/process_memory/process_memory_view.dart index d970490433a..bfa11aeef7c 100644 --- a/packages/devtools_app/lib/src/screens/vm_developer/process_memory/process_memory_view.dart +++ b/packages/devtools_app/lib/src/screens/vm_developer/process_memory/process_memory_view.dart @@ -31,7 +31,11 @@ import 'process_memory_view_controller.dart'; /// process's memory footprint. class VMProcessMemoryView extends VMDeveloperView { const VMProcessMemoryView() - : super(title: 'Process Memory', icon: Icons.memory); + : super( + title: 'Process Memory', + icon: Icons.memory, + gaEvent: gac.VmToolsEvents.processMemory, + ); @override Widget build(BuildContext context) => VMProcessMemoryViewBody(); diff --git a/packages/devtools_app/lib/src/screens/vm_developer/queued_microtasks/queued_microtasks_view.dart b/packages/devtools_app/lib/src/screens/vm_developer/queued_microtasks/queued_microtasks_view.dart index 516b3492139..19b387390d0 100644 --- a/packages/devtools_app/lib/src/screens/vm_developer/queued_microtasks/queued_microtasks_view.dart +++ b/packages/devtools_app/lib/src/screens/vm_developer/queued_microtasks/queued_microtasks_view.dart @@ -161,7 +161,11 @@ class MicrotaskStackTraceView extends StatelessWidget { class QueuedMicrotasksView extends VMDeveloperView { const QueuedMicrotasksView() - : super(title: 'Queued Microtasks', icon: Icons.pending_actions); + : super( + title: 'Queued Microtasks', + icon: Icons.pending_actions, + gaEvent: gac.VmToolsEvents.queuedMicrotasks, + ); @override bool get showIsolateSelector => true; diff --git a/packages/devtools_app/lib/src/screens/vm_developer/vm_developer_tools_screen.dart b/packages/devtools_app/lib/src/screens/vm_developer/vm_developer_tools_screen.dart index ded2471ed0b..d4aa3707002 100644 --- a/packages/devtools_app/lib/src/screens/vm_developer/vm_developer_tools_screen.dart +++ b/packages/devtools_app/lib/src/screens/vm_developer/vm_developer_tools_screen.dart @@ -7,6 +7,8 @@ import 'package:flutter/foundation.dart'; import 'package:material_ui/material_ui.dart'; import '../../service/vm_flags.dart' as vm_flags; +import '../../shared/analytics/analytics.dart' as ga; +import '../../shared/analytics/constants.dart' as gac; import '../../shared/framework/screen.dart'; import '../../shared/globals.dart'; import 'isolate_statistics/isolate_statistics_view.dart'; @@ -17,13 +19,20 @@ import 'vm_developer_tools_controller.dart'; import 'vm_statistics/vm_statistics_view.dart'; abstract class VMDeveloperView { - const VMDeveloperView({required this.title, required this.icon}); + const VMDeveloperView({ + required this.title, + required this.icon, + required this.gaEvent, + }); /// The user-facing name of the page. final String title; final IconData icon; + /// The analytics id sent when this page is selected. + final gac.VmToolsEvents gaEvent; + /// Whether this view should display the isolate selector in the status /// line. /// @@ -46,7 +55,7 @@ class VMDeveloperToolsScreen extends Screen { const VMDeveloperToolsScreenBody(); } -class VMDeveloperToolsScreenBody extends StatelessWidget { +class VMDeveloperToolsScreenBody extends StatefulWidget { const VMDeveloperToolsScreenBody({super.key}); // The value of the `--profile-microtasks` VM flag cannot be modified once @@ -66,9 +75,40 @@ class VMDeveloperToolsScreenBody extends StatelessWidget { if (showQueuedMicrotasks) const QueuedMicrotasksView(), ]; + @override + State createState() => + _VMDeveloperToolsScreenBodyState(); +} + +class _VMDeveloperToolsScreenBodyState + extends State { + late final VMDeveloperToolsController controller; + + List get views => VMDeveloperToolsScreenBody.views; + + @override + void initState() { + super.initState(); + ga.screen(gac.vmTools); + controller = screenControllers.lookup(); + // Record the view that is visible when the screen opens, as tabbed views + // do (see `AnalyticsTabbedView`). + ga.select( + gac.vmTools, + views[controller.selectedIndex.value].gaEvent.name, + nonInteraction: true, + ); + } + + void _selectView(int index) { + if (index != controller.selectedIndex.value) { + ga.select(gac.vmTools, views[index].gaEvent.name); + } + controller.selectIndex(index); + } + @override Widget build(BuildContext context) { - final controller = screenControllers.lookup(); return ValueListenableBuilder( valueListenable: controller.selectedIndex, builder: (context, selectedIndex, _) { @@ -78,7 +118,7 @@ class VMDeveloperToolsScreenBody extends StatelessWidget { NavigationRail( selectedIndex: selectedIndex, labelType: NavigationRailLabelType.all, - onDestinationSelected: controller.selectIndex, + onDestinationSelected: _selectView, destinations: [ for (final view in views) NavigationRailDestination( diff --git a/packages/devtools_app/lib/src/screens/vm_developer/vm_statistics/vm_statistics_view.dart b/packages/devtools_app/lib/src/screens/vm_developer/vm_statistics/vm_statistics_view.dart index c25fd1ccac1..129fae688c7 100644 --- a/packages/devtools_app/lib/src/screens/vm_developer/vm_statistics/vm_statistics_view.dart +++ b/packages/devtools_app/lib/src/screens/vm_developer/vm_statistics/vm_statistics_view.dart @@ -18,7 +18,12 @@ import '../vm_service_private_extensions.dart'; import 'vm_statistics_view_controller.dart'; class VMStatisticsView extends VMDeveloperView { - const VMStatisticsView() : super(title: 'VM', icon: Icons.devices); + const VMStatisticsView() + : super( + title: 'VM', + icon: Icons.devices, + gaEvent: gac.VmToolsEvents.vmStatistics, + ); @override Widget build(BuildContext context) => VMStatisticsViewBody(); diff --git a/packages/devtools_app/lib/src/shared/analytics/constants.dart b/packages/devtools_app/lib/src/shared/analytics/constants.dart index a19a5f1db14..dba48e5e2c9 100644 --- a/packages/devtools_app/lib/src/shared/analytics/constants.dart +++ b/packages/devtools_app/lib/src/shared/analytics/constants.dart @@ -20,6 +20,7 @@ part 'constants/_memory_constants.dart'; part 'constants/_network_constants.dart'; part 'constants/_performance_constants.dart'; part 'constants/_property_editor_sidebar_constants.dart'; +part 'constants/_vm_tools_constants.dart'; // Type of events (event_category): const screenViewEvent = 'screen'; // Active screen (tab selected). @@ -41,6 +42,7 @@ final debugger = ScreenMetaData.debugger.id; final logging = ScreenMetaData.logging.id; final appSize = ScreenMetaData.appSize.id; final vmTools = ScreenMetaData.vmTools.id; +final dtdTools = ScreenMetaData.dtdTools.id; const console = 'console'; final simple = ScreenMetaData.simple.id; final deeplink = ScreenMetaData.deepLinks.id; diff --git a/packages/devtools_app/lib/src/shared/analytics/constants/_vm_tools_constants.dart b/packages/devtools_app/lib/src/shared/analytics/constants/_vm_tools_constants.dart new file mode 100644 index 00000000000..9dabc7d6a8d --- /dev/null +++ b/packages/devtools_app/lib/src/shared/analytics/constants/_vm_tools_constants.dart @@ -0,0 +1,14 @@ +// Copyright 2026 The Flutter Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file or at https://developers.google.com/open-source/licenses/bsd. + +part of '../constants.dart'; + +/// Analytics ids for the views in the VM Tools screen's navigation rail. +enum VmToolsEvents { + vmStatistics, + isolateStatistics, + objectInspector, + processMemory, + queuedMicrotasks, +}