[Property Editor] Add analytics to the Property Editor (#8840)

diff --git a/packages/devtools_app/lib/src/shared/analytics/constants/_property_editor_sidebar_constants.dart b/packages/devtools_app/lib/src/shared/analytics/constants/_property_editor_sidebar_constants.dart
index 8a6d018..4f543ea 100644
--- a/packages/devtools_app/lib/src/shared/analytics/constants/_property_editor_sidebar_constants.dart
+++ b/packages/devtools_app/lib/src/shared/analytics/constants/_property_editor_sidebar_constants.dart
@@ -4,15 +4,24 @@
 
 part of '../constants.dart';
 
-// TODO(elliette): Send the following events from the property editor.
-enum PropertyEditorEvents {
+enum PropertyEditorSidebar {
   /// Analytics event that is sent when the property editor is updated with new
   /// properties.
-  widgetPropertiesUpdate,
-
-  /// Analytics event that is sent when a user requests a property edit.
-  applyEditRequest;
+  widgetPropertiesUpdate;
 
   /// Analytics id to track events that come from the DTD editor sidebar.
   static String get id => 'propertyEditorSidebar';
+
+  /// Analytics event for an edit request.
+  static String applyEditRequest({
+    required String argName,
+    required String argType,
+  }) => 'applyEditRequest-$argType-$argName';
+
+  /// Analytics event on completion of an edit.
+  static String applyEditComplete({
+    required String argName,
+    required String argType,
+    bool succeeded = true,
+  }) => 'applyEdit${succeeded ? 'Success' : 'Failure'}-$argType-$argName';
 }
diff --git a/packages/devtools_app/lib/src/standalone_ui/ide_shared/property_editor/property_editor_controller.dart b/packages/devtools_app/lib/src/standalone_ui/ide_shared/property_editor/property_editor_controller.dart
index 0925099..b6e0b05 100644
--- a/packages/devtools_app/lib/src/standalone_ui/ide_shared/property_editor/property_editor_controller.dart
+++ b/packages/devtools_app/lib/src/standalone_ui/ide_shared/property_editor/property_editor_controller.dart
@@ -5,6 +5,8 @@
 import 'package:devtools_app_shared/utils.dart';
 import 'package:flutter/foundation.dart';
 
+import '../../../shared/analytics/analytics.dart' as ga;
+import '../../../shared/analytics/constants.dart' as gac;
 import '../../../shared/editor/api_classes.dart';
 import '../../../shared/editor/editor_client.dart';
 
@@ -16,6 +18,8 @@
 
   final EditorClient editorClient;
 
+  String get gaId => gac.PropertyEditorSidebar.id;
+
   TextDocument? _currentDocument;
   CursorPosition? _currentCursorPosition;
 
@@ -44,6 +48,13 @@
           position: cursorPosition,
         );
         final args = result?.args ?? <EditableArgument>[];
+        // Register impression.
+        ga.impression(
+          gaId,
+          // TODO(https://github.com/flutter/devtools/issues/8716): Postfix with
+          // widget name.
+          gac.PropertyEditorSidebar.widgetPropertiesUpdate.name,
+        );
         _editableArgs.value = args;
       }),
     );
diff --git a/packages/devtools_app/lib/src/standalone_ui/ide_shared/property_editor/property_editor_inputs.dart b/packages/devtools_app/lib/src/standalone_ui/ide_shared/property_editor/property_editor_inputs.dart
index 6bc2a30..a3bf292 100644
--- a/packages/devtools_app/lib/src/standalone_ui/ide_shared/property_editor/property_editor_inputs.dart
+++ b/packages/devtools_app/lib/src/standalone_ui/ide_shared/property_editor/property_editor_inputs.dart
@@ -9,6 +9,8 @@
 import 'package:flutter/material.dart';
 import 'package:flutter/services.dart';
 
+import '../../../shared/analytics/analytics.dart' as ga;
+import '../../../shared/analytics/constants.dart' as gac;
 import '../../../shared/editor/api_classes.dart';
 import 'property_editor_controller.dart';
 import 'property_editor_types.dart';
@@ -221,16 +223,20 @@
   }) async {
     clearServerError();
     final argName = property.name;
-
-    // Can edit values to null.
-    if (property.isNullable && property.isNully(valueAsString)) {
-      await controller.editArgument(name: argName, value: null);
-      return;
-    }
-
-    final value = property.convertFromInputString(valueAsString) as U?;
+    ga.select(
+      gac.PropertyEditorSidebar.id,
+      gac.PropertyEditorSidebar.applyEditRequest(
+        argName: property.name,
+        argType: property.type,
+      ),
+    );
+    final editToNull = property.isNullable && property.isNully(valueAsString);
+    final value =
+        editToNull
+            ? null
+            : property.convertFromInputString(valueAsString) as U?;
     final response = await controller.editArgument(name: argName, value: value);
-    _maybeHandleServerError(response, property: property);
+    _handleServerResponse(response, property: property);
   }
 
   InputDecoration decoration(
@@ -290,14 +296,25 @@
     });
   }
 
-  void _maybeHandleServerError(
+  void _handleServerResponse(
     EditArgumentResponse? errorResponse, {
     required EditableProperty property,
   }) {
-    if (errorResponse == null || errorResponse.success) return;
-    setState(() {
-      _serverError =
-          '${errorResponse.errorType?.message ?? 'Encountered unknown error.'} (Property: ${property.name})';
-    });
+    final succeeded = errorResponse == null || errorResponse.success;
+    if (!succeeded) {
+      setState(() {
+        _serverError =
+            '${errorResponse.errorType?.message ?? 'Encountered unknown error.'} (Property: ${property.name})';
+      });
+      ga.reportError('property-editor $_serverError');
+    }
+    ga.select(
+      gac.PropertyEditorSidebar.id,
+      gac.PropertyEditorSidebar.applyEditComplete(
+        argName: property.name,
+        argType: property.type,
+        succeeded: succeeded,
+      ),
+    );
   }
 }
diff --git a/packages/devtools_app/lib/src/standalone_ui/ide_shared/property_editor/property_editor_panel.dart b/packages/devtools_app/lib/src/standalone_ui/ide_shared/property_editor/property_editor_panel.dart
index 761eaf8..b0c67e9 100644
--- a/packages/devtools_app/lib/src/standalone_ui/ide_shared/property_editor/property_editor_panel.dart
+++ b/packages/devtools_app/lib/src/standalone_ui/ide_shared/property_editor/property_editor_panel.dart
@@ -10,7 +10,7 @@
 import 'package:flutter/material.dart';
 
 import '../../../shared/analytics/analytics.dart' as ga;
-import '../../../shared/analytics/constants.dart';
+import '../../../shared/analytics/constants.dart' as gac;
 import '../../../shared/editor/editor_client.dart';
 import '../../../shared/ui/common_widgets.dart';
 import 'property_editor_controller.dart';
@@ -37,7 +37,7 @@
     super.initState();
 
     final editor = EditorClient(widget.dtd);
-    ga.screen(PropertyEditorEvents.id);
+    ga.screen(gac.PropertyEditorSidebar.id);
     unawaited(
       _editor = editor.initialized.then((_) {
         _propertyEditorController = PropertyEditorController(editor);