Skip to content

Commit d4dd0fd

Browse files
authored
[Property Editor] Add analytics to the Property Editor (#8840)
1 parent 8228fbb commit d4dd0fd

File tree

4 files changed

+60
-23
lines changed

4 files changed

+60
-23
lines changed

packages/devtools_app/lib/src/shared/analytics/constants/_property_editor_sidebar_constants.dart

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,24 @@
44

55
part of '../constants.dart';
66

7-
// TODO(elliette): Send the following events from the property editor.
8-
enum PropertyEditorEvents {
7+
enum PropertyEditorSidebar {
98
/// Analytics event that is sent when the property editor is updated with new
109
/// properties.
11-
widgetPropertiesUpdate,
12-
13-
/// Analytics event that is sent when a user requests a property edit.
14-
applyEditRequest;
10+
widgetPropertiesUpdate;
1511

1612
/// Analytics id to track events that come from the DTD editor sidebar.
1713
static String get id => 'propertyEditorSidebar';
14+
15+
/// Analytics event for an edit request.
16+
static String applyEditRequest({
17+
required String argName,
18+
required String argType,
19+
}) => 'applyEditRequest-$argType-$argName';
20+
21+
/// Analytics event on completion of an edit.
22+
static String applyEditComplete({
23+
required String argName,
24+
required String argType,
25+
bool succeeded = true,
26+
}) => 'applyEdit${succeeded ? 'Success' : 'Failure'}-$argType-$argName';
1827
}

packages/devtools_app/lib/src/standalone_ui/ide_shared/property_editor/property_editor_controller.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import 'package:devtools_app_shared/utils.dart';
66
import 'package:flutter/foundation.dart';
77

8+
import '../../../shared/analytics/analytics.dart' as ga;
9+
import '../../../shared/analytics/constants.dart' as gac;
810
import '../../../shared/editor/api_classes.dart';
911
import '../../../shared/editor/editor_client.dart';
1012

@@ -16,6 +18,8 @@ class PropertyEditorController extends DisposableController
1618

1719
final EditorClient editorClient;
1820

21+
String get gaId => gac.PropertyEditorSidebar.id;
22+
1923
TextDocument? _currentDocument;
2024
CursorPosition? _currentCursorPosition;
2125

@@ -44,6 +48,13 @@ class PropertyEditorController extends DisposableController
4448
position: cursorPosition,
4549
);
4650
final args = result?.args ?? <EditableArgument>[];
51+
// Register impression.
52+
ga.impression(
53+
gaId,
54+
// TODO(https://github.com/flutter/devtools/issues/8716): Postfix with
55+
// widget name.
56+
gac.PropertyEditorSidebar.widgetPropertiesUpdate.name,
57+
);
4758
_editableArgs.value = args;
4859
}),
4960
);

packages/devtools_app/lib/src/standalone_ui/ide_shared/property_editor/property_editor_inputs.dart

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import 'package:devtools_app_shared/utils.dart';
99
import 'package:flutter/material.dart';
1010
import 'package:flutter/services.dart';
1111

12+
import '../../../shared/analytics/analytics.dart' as ga;
13+
import '../../../shared/analytics/constants.dart' as gac;
1214
import '../../../shared/editor/api_classes.dart';
1315
import 'property_editor_controller.dart';
1416
import 'property_editor_types.dart';
@@ -221,16 +223,20 @@ mixin _PropertyInputMixin<T extends StatefulWidget, U> on State<T> {
221223
}) async {
222224
clearServerError();
223225
final argName = property.name;
224-
225-
// Can edit values to null.
226-
if (property.isNullable && property.isNully(valueAsString)) {
227-
await controller.editArgument(name: argName, value: null);
228-
return;
229-
}
230-
231-
final value = property.convertFromInputString(valueAsString) as U?;
226+
ga.select(
227+
gac.PropertyEditorSidebar.id,
228+
gac.PropertyEditorSidebar.applyEditRequest(
229+
argName: property.name,
230+
argType: property.type,
231+
),
232+
);
233+
final editToNull = property.isNullable && property.isNully(valueAsString);
234+
final value =
235+
editToNull
236+
? null
237+
: property.convertFromInputString(valueAsString) as U?;
232238
final response = await controller.editArgument(name: argName, value: value);
233-
_maybeHandleServerError(response, property: property);
239+
_handleServerResponse(response, property: property);
234240
}
235241

236242
InputDecoration decoration(
@@ -290,14 +296,25 @@ mixin _PropertyInputMixin<T extends StatefulWidget, U> on State<T> {
290296
});
291297
}
292298

293-
void _maybeHandleServerError(
299+
void _handleServerResponse(
294300
EditArgumentResponse? errorResponse, {
295301
required EditableProperty property,
296302
}) {
297-
if (errorResponse == null || errorResponse.success) return;
298-
setState(() {
299-
_serverError =
300-
'${errorResponse.errorType?.message ?? 'Encountered unknown error.'} (Property: ${property.name})';
301-
});
303+
final succeeded = errorResponse == null || errorResponse.success;
304+
if (!succeeded) {
305+
setState(() {
306+
_serverError =
307+
'${errorResponse.errorType?.message ?? 'Encountered unknown error.'} (Property: ${property.name})';
308+
});
309+
ga.reportError('property-editor $_serverError');
310+
}
311+
ga.select(
312+
gac.PropertyEditorSidebar.id,
313+
gac.PropertyEditorSidebar.applyEditComplete(
314+
argName: property.name,
315+
argType: property.type,
316+
succeeded: succeeded,
317+
),
318+
);
302319
}
303320
}

packages/devtools_app/lib/src/standalone_ui/ide_shared/property_editor/property_editor_panel.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import 'package:dtd/dtd.dart';
1010
import 'package:flutter/material.dart';
1111

1212
import '../../../shared/analytics/analytics.dart' as ga;
13-
import '../../../shared/analytics/constants.dart';
13+
import '../../../shared/analytics/constants.dart' as gac;
1414
import '../../../shared/editor/editor_client.dart';
1515
import '../../../shared/ui/common_widgets.dart';
1616
import 'property_editor_controller.dart';
@@ -37,7 +37,7 @@ class _PropertyEditorPanelState extends State<PropertyEditorPanel> {
3737
super.initState();
3838

3939
final editor = EditorClient(widget.dtd);
40-
ga.screen(PropertyEditorEvents.id);
40+
ga.screen(gac.PropertyEditorSidebar.id);
4141
unawaited(
4242
_editor = editor.initialized.then((_) {
4343
_propertyEditorController = PropertyEditorController(editor);

0 commit comments

Comments
 (0)