Skip to content

Commit

Permalink
[Inspector V2] Fix inspector analytics (#8684)
Browse files Browse the repository at this point in the history
  • Loading branch information
elliette authored Jan 10, 2025
1 parent a81315a commit 81c9bad
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import 'package:logging/logging.dart';
import 'package:vm_service/vm_service.dart';

import '../../service/service_extensions.dart' as extensions;
import '../../shared/analytics/analytics.dart' as ga;
import '../../shared/analytics/constants.dart' as gac;
import '../../shared/analytics/metrics.dart';
import '../../shared/console/eval/inspector_tree.dart';
import '../../shared/console/primitives/simple_items.dart';
import '../../shared/diagnostics/diagnostics_node.dart';
Expand Down Expand Up @@ -666,6 +669,13 @@ class InspectorController extends DisposableController
subtreeRoot = newSelection;

applyNewSelection(newSelection, detailsSelection, true);

// Send an event that a widget was selected on the device.
ga.select(
gac.inspector,
gac.onDeviceSelection,
screenMetricsProvider: () => InspectorScreenMetrics.legacy(),
);
} catch (error, st) {
if (selectionGroups.next == group) {
_log.shout(error, error, st);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import '../../service/service_extension_widgets.dart';
import '../../service/service_extensions.dart' as extensions;
import '../../shared/analytics/analytics.dart' as ga;
import '../../shared/analytics/constants.dart' as gac;
import '../../shared/analytics/metrics.dart';
import '../../shared/console/eval/inspector_tree.dart';
import '../../shared/globals.dart';
import '../../shared/managers/error_badge_manager.dart';
Expand Down Expand Up @@ -265,7 +266,11 @@ class InspectorScreenBodyState extends State<InspectorScreenBody>
}

void _refreshInspector() {
ga.select(gac.inspector, gac.refresh);
ga.select(
gac.inspector,
gac.refresh,
screenMetricsProvider: () => InspectorScreenMetrics.legacy(),
);
unawaited(
blockWhileInProgress(() async {
// If the user is force refreshing the inspector before the first load has
Expand All @@ -275,7 +280,11 @@ class InspectorScreenBodyState extends State<InspectorScreenBody>
// We do not want to complete this timing operation because the force
// refresh will skew the results.
ga.cancelTimingOperation(InspectorScreen.id, gac.pageReady);
ga.select(gac.inspector, gac.refreshEmptyTree);
ga.select(
gac.inspector,
gac.refreshEmptyTree,
screenMetricsProvider: () => InspectorScreenMetrics.legacy(),
);
controller.firstInspectorTreeLoadCompleted = true;
}
await controller.onForceRefresh();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,11 @@ class InspectorTreeController extends DisposableController

void onSelectNode(InspectorTreeNode? node) {
selection = node;
ga.select(gac.inspector, gac.treeNodeSelection);
ga.select(
gac.inspector,
gac.treeNodeSelection,
screenMetricsProvider: () => InspectorScreenMetrics.legacy(),
);
expandPath(node);
}

Expand Down Expand Up @@ -1002,7 +1006,14 @@ class _InspectorTreeState extends State<InspectorTree>
if (!controller.firstInspectorTreeLoadCompleted && widget.isSummaryTree) {
final screenId = widget.screenId;
if (screenId != null) {
ga.timeEnd(screenId, gac.pageReady);
ga.timeEnd(
screenId,
gac.pageReady,
screenMetricsProvider:
() => InspectorScreenMetrics.legacy(
rowCount: treeControllerLocal.numRows,
),
);
unawaited(
serviceConnection.sendDwdsEvent(
screen: screenId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class FlutterInspectorSettingsDialog extends StatelessWidget {
description:
'Disable the redesigned Flutter inspector. Please know that '
'the legacy inspector may be removed in a future release.',
gaItem: gac.inspectorV2Enabled,
gaItem: gac.inspectorV2Disabled,
),
),
const SizedBox(height: largeSpacing),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import 'package:vm_service/vm_service.dart';
import '../../service/service_extensions.dart' as extensions;
import '../../shared/analytics/analytics.dart' as ga;
import '../../shared/analytics/constants.dart' as gac;
import '../../shared/analytics/metrics.dart';
import '../../shared/console/eval/inspector_tree_v2.dart';
import '../../shared/console/primitives/simple_items.dart';
import '../../shared/diagnostics/diagnostics_node.dart';
Expand Down Expand Up @@ -392,7 +393,11 @@ class InspectorController extends DisposableController
// We do not want to complete this timing operation because the force
// refresh will skew the results.
ga.cancelTimingOperation(InspectorScreen.id, gac.pageReady);
ga.select(gac.inspector, gac.refreshEmptyTree);
ga.select(
gac.inspector,
gac.refreshEmptyTree,
screenMetricsProvider: () => InspectorScreenMetrics.v2(),
);
firstInspectorTreeLoadCompleted = true;
}
await onForceRefresh();
Expand Down Expand Up @@ -766,6 +771,13 @@ class InspectorController extends DisposableController
selectedNode: newSelection,
group: group,
);

// Send an event that a widget was selected on the device.
ga.select(
gac.inspector,
gac.onDeviceSelection,
screenMetricsProvider: () => InspectorScreenMetrics.v2(),
);
} catch (error, st) {
if (selectionGroups.next == group) {
_log.shout(error, error, st);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:flutter/material.dart';

import '../../shared/analytics/analytics.dart' as ga;
import '../../shared/analytics/constants.dart' as gac;
import '../../shared/analytics/metrics.dart';
import '../../shared/console/eval/inspector_tree_v2.dart';
import '../../shared/globals.dart';
import '../../shared/managers/banner_messages.dart';
Expand Down Expand Up @@ -219,7 +220,11 @@ class InspectorScreenBodyState extends State<InspectorScreenBody>
}

void _refreshInspector() {
ga.select(gac.inspector, gac.refresh);
ga.select(
gac.inspector,
gac.refresh,
screenMetricsProvider: () => InspectorScreenMetrics.v2(),
);
unawaited(
blockWhileInProgress(() async {
await controller.refreshInspector();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,11 @@ class InspectorTreeController extends DisposableController

void onSelectNode(InspectorTreeNode? node) {
setSelectedNode(node, notifyFlutterInspector: true);
ga.select(gac.inspector, gac.treeNodeSelection);
ga.select(
gac.inspector,
gac.treeNodeSelection,
screenMetricsProvider: () => InspectorScreenMetrics.v2(),
);
final diagnostic = node?.diagnostic;
if (diagnostic != null && diagnostic.groupIsHidden) {
diagnostic.hideableGroupLeader?.toggleHiddenGroup();
Expand Down Expand Up @@ -1136,7 +1140,12 @@ class _InspectorTreeState extends State<InspectorTree>
if (!controller.firstInspectorTreeLoadCompleted) {
final screenId = widget.screenId;
if (screenId != null) {
ga.timeEnd(screenId, gac.pageReady);
ga.timeEnd(
screenId,
gac.pageReady,
screenMetricsProvider:
() => InspectorScreenMetrics.v2(rowCount: rows.length),
);
unawaited(
serviceConnection.sendDwdsEvent(
screen: screenId,
Expand Down
20 changes: 14 additions & 6 deletions packages/devtools_app/lib/src/shared/analytics/_analytics_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ extension type GtagEventDevTools._(JSObject _) implements GtagEvent {

// NOTE: Do not reorder any of these. Order here must match the order in the
// Google Analytics console.
// IMPORTANT! Only string and int values are supported. All other value
// types will be ignored in GA4.
String? user_app, // dimension1 (flutter or web)
String? user_build, // dimension2 (debug or profile)
String? user_platform, // dimension3 (android/ios/fuchsia/linux/mac/windows)
Expand Down Expand Up @@ -112,7 +114,7 @@ extension type GtagEventDevTools._(JSObject _) implements GtagEvent {
String? android_app_id, //metric13
String? ios_bundle_id, //metric14
// Inspector screen metrics. See [InspectorScreenMetrics].
bool? is_v2_inspector, // metric15
String? is_v2_inspector, // metric15
});

factory GtagEventDevTools._create({
Expand Down Expand Up @@ -207,7 +209,9 @@ extension type GtagEventDevTools._(JSObject _) implements GtagEvent {
: null,
// [InspectorScreenMetrics]
is_v2_inspector:
screenMetrics is InspectorScreenMetrics ? screenMetrics.isV2 : null,
screenMetrics is InspectorScreenMetrics
? screenMetrics.isV2.toString()
: null,
);
}

Expand Down Expand Up @@ -243,7 +247,7 @@ extension type GtagEventDevTools._(JSObject _) implements GtagEvent {
external int? get inspector_tree_controller_id;
external String? get android_app_id;
external String? get ios_bundle_id;
external bool? get is_v2_inspector;
external String? get is_v2_inspector;
}

extension type GtagExceptionDevTools._(JSObject _) implements GtagException {
Expand All @@ -254,6 +258,8 @@ extension type GtagExceptionDevTools._(JSObject _) implements GtagException {

// NOTE: Do not reorder any of these. Order here must match the order in the
// Google Analytics console.
// IMPORTANT! Only string and int values are supported. All other value
// types will be ignored in GA4.
String? user_app, // dimension1 (flutter or web)
String? user_build, // dimension2 (debug or profile)
String? user_platform, // dimension3 (android or ios)
Expand Down Expand Up @@ -298,7 +304,7 @@ extension type GtagExceptionDevTools._(JSObject _) implements GtagException {
String? android_app_id, //metric13
String? ios_bundle_id, //metric14
// Inspector screen metrics. See [InspectorScreenMetrics].
bool? is_v2_inspector, // metric15
String? is_v2_inspector, // metric15
});

factory GtagExceptionDevTools._create(
Expand Down Expand Up @@ -385,7 +391,9 @@ extension type GtagExceptionDevTools._(JSObject _) implements GtagException {
: null,
// [InspectorScreenMetrics]
is_v2_inspector:
screenMetrics is InspectorScreenMetrics ? screenMetrics.isV2 : null,
screenMetrics is InspectorScreenMetrics
? screenMetrics.isV2.toString()
: null,
);
}

Expand Down Expand Up @@ -1026,7 +1034,7 @@ final class _DevToolsEventMetrics extends ua.CustomMetrics {
final int? rootSetCount;
final int? rowCount;
final int? inspectorTreeControllerId;
final bool? isV2Inspector;
final String? isV2Inspector;

// [DeepLinkScreenMetrics]
final String? androidAppId;
Expand Down
2 changes: 2 additions & 0 deletions packages/devtools_app/lib/src/shared/analytics/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ const selectWidgetMode = 'selectWidgetMode';
const enableOnDeviceInspector = 'enableOnDeviceInspector';
const showOnDeviceInspector = 'showInspector';
const treeNodeSelection = 'treeNodeSelection';
const onDeviceSelection = 'onDeviceSelection';
const inspectorSettings = 'inspectorSettings';
const loggingSettings = 'loggingSettings';
const refreshPubRoots = 'refreshPubRoots';
Expand Down Expand Up @@ -119,6 +120,7 @@ const wasm = 'wasm';
const verboseLogging = 'verboseLogging';
const inspectorHoverEvalMode = 'inspectorHoverEvalMode';
const inspectorV2Enabled = 'inspectorV2Enabled';
const inspectorV2Disabled = 'inspectorV2Disabled';
const inspectorAutoRefreshEnabled = 'inspectorAutoRefreshEnabled';
const inspectorV2Docs = 'inspectorV2Docs';
const clearLogs = 'clearLogs';
Expand Down
12 changes: 6 additions & 6 deletions packages/devtools_app/lib/src/shared/analytics/metrics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ class ProfilerScreenMetrics extends ScreenAnalyticsMetrics {

class InspectorScreenMetrics extends ScreenAnalyticsMetrics {
InspectorScreenMetrics.legacy({
required this.rootSetCount,
required this.rowCount,
required this.inspectorTreeControllerId,
this.rootSetCount,
this.rowCount,
this.inspectorTreeControllerId,
}) : isV2 = false;

InspectorScreenMetrics.v2({
required this.rootSetCount,
required this.rowCount,
required this.inspectorTreeControllerId,
this.rootSetCount,
this.rowCount,
this.inspectorTreeControllerId,
}) : isV2 = true;

static const summaryTreeGaId = 0;
Expand Down

0 comments on commit 81c9bad

Please sign in to comment.