diff --git a/pkgs/unified_analytics/CHANGELOG.md b/pkgs/unified_analytics/CHANGELOG.md index 7e42cbabc..f29141ce7 100644 --- a/pkgs/unified_analytics/CHANGELOG.md +++ b/pkgs/unified_analytics/CHANGELOG.md @@ -1,3 +1,6 @@ +## 7.0.2 +- Allow `LogStatsFile` to contain more granular event types (specifically `property_editor` events). + ## 7.0.1 - Fixed `UnsupportedError` thrown when Event.exception is called without providing a value for `args`. diff --git a/pkgs/unified_analytics/USAGE_GUIDE.md b/pkgs/unified_analytics/USAGE_GUIDE.md index ef5bbea1e..ffaf028ca 100644 --- a/pkgs/unified_analytics/USAGE_GUIDE.md +++ b/pkgs/unified_analytics/USAGE_GUIDE.md @@ -199,4 +199,10 @@ Explanation of the each key above - flutterChannelCount: count of flutter channels (can be 0 if developer is a Dart dev only) - toolCount: count of the Dart and Flutter tools sending analytics - recordCount: count of the total number of events in the log file -- eventCount: counts each unique event and how many times they occurred in the log file \ No newline at end of file +- eventCount: counts each unique event and how many times they occurred in the log file + +Note: You can test any changes to the `LogFileStats` during development by running: + +```shell +dart run example/log_stats.dart +``` \ No newline at end of file diff --git a/pkgs/unified_analytics/example/log_stats.dart b/pkgs/unified_analytics/example/log_stats.dart new file mode 100644 index 000000000..0e19a5f28 --- /dev/null +++ b/pkgs/unified_analytics/example/log_stats.dart @@ -0,0 +1,22 @@ +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'package:unified_analytics/unified_analytics.dart'; + +final Analytics analytics = Analytics.development( + tool: DashTool.flutterTool, + flutterChannel: 'ey-test-channel', + flutterVersion: 'Flutter 3.29.2', + clientIde: 'VSCode', + dartVersion: 'Dart 3.7.2', +); + +/// Simple CLI to print the logFileStats to the console. +/// +/// Run with: dart run example/log_stats.dart +void main() async { + print(analytics.logFileStats()); + // Close the client connection on exit. + await analytics.close(); +} diff --git a/pkgs/unified_analytics/lib/src/constants.dart b/pkgs/unified_analytics/lib/src/constants.dart index 2be4d0a6c..5507f39c7 100644 --- a/pkgs/unified_analytics/lib/src/constants.dart +++ b/pkgs/unified_analytics/lib/src/constants.dart @@ -87,7 +87,7 @@ const int kMaxLogFileSize = 25 * (1 << 20); const String kLogFileName = 'dart-flutter-telemetry.log'; /// The current version of the package, should be in line with pubspec version. -const String kPackageVersion = '7.0.1'; +const String kPackageVersion = '7.0.2'; /// The minimum length for a session. const int kSessionDurationMinutes = 30; @@ -117,3 +117,12 @@ Privacy Policy (https://policies.google.com/privacy). /// If the message below is altered, the version should be incremented so that /// users can be prompted with the updated messaging. const int kToolsMessageVersion = 1; + +/// Constants for Dash tools + +/// DevTools: +const String devtoolsEventLabel = 'devtools_event'; + +const String propertyEditorId = 'propertyEditorSidebar'; + +const String propertyEditorLogStatsName = 'property_editor'; diff --git a/pkgs/unified_analytics/lib/src/log_handler.dart b/pkgs/unified_analytics/lib/src/log_handler.dart index a6ef2f5b6..48badad25 100644 --- a/pkgs/unified_analytics/lib/src/log_handler.dart +++ b/pkgs/unified_analytics/lib/src/log_handler.dart @@ -397,7 +397,10 @@ class LogItem { // a map for the one event in the value final eventProp = (record['events']! as List).first as Map; - final eventName = eventProp['name'] as String; + final eventName = _logItemEventName( + eventProp['name'] as String, + event: eventProp, + ); // Parse the data out of the `user_properties` value final userProps = record['user_properties'] as Map; @@ -462,3 +465,28 @@ class LogItem { ); } } + +/// Logic for creating a more granular event name for the [LogItem]. +String _logItemEventName( + String eventName, { + required Map event, +}) { + switch (eventName) { + case devtoolsEventLabel: + return _granularDevToolsEventName(eventName, event: event); + default: + return eventName; + } +} + +String _granularDevToolsEventName( + String eventName, { + required Map event, +}) { + final params = event['params'] as Map; + final screen = params['screen']; + if (screen is String && screen == propertyEditorId) { + return propertyEditorLogStatsName; + } + return eventName; +} diff --git a/pkgs/unified_analytics/pubspec.yaml b/pkgs/unified_analytics/pubspec.yaml index f0a99f12c..6ef64751b 100644 --- a/pkgs/unified_analytics/pubspec.yaml +++ b/pkgs/unified_analytics/pubspec.yaml @@ -5,7 +5,7 @@ description: >- # LINT.IfChange # When updating this, keep the version consistent with the changelog and the # value in lib/src/constants.dart. -version: 7.0.1 +version: 7.0.2 # LINT.ThenChange(lib/src/constants.dart) repository: https://github.com/dart-lang/tools/tree/main/pkgs/unified_analytics issue_tracker: https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Aunified_analytics diff --git a/pkgs/unified_analytics/test/log_handler_test.dart b/pkgs/unified_analytics/test/log_handler_test.dart index db14d96ce..3292d846d 100644 --- a/pkgs/unified_analytics/test/log_handler_test.dart +++ b/pkgs/unified_analytics/test/log_handler_test.dart @@ -22,6 +22,16 @@ void main() { late File logFile; final testEvent = Event.hotReloadTime(timeMs: 10); + final propertyEditorEvent = Event.devtoolsEvent( + label: devtoolsEventLabel, + screen: propertyEditorId, + eventCategory: 'test', + value: 1); + final devToolsEvent = Event.devtoolsEvent( + label: devtoolsEventLabel, + screen: 'inspector', + eventCategory: 'test', + value: 1); setUp(() { fs = MemoryFileSystem.test(style: FileSystemStyle.posix); @@ -71,6 +81,26 @@ void main() { expect(analytics.logFileStats()!.recordCount, countOfEventsToSend); }); + test('LogFileStats handles granular events', () async { + final countOfPropertyEditorEventsToSend = 5; + final countOfDevToolsEventsToSend = 10; + + for (var i = 0; i < countOfPropertyEditorEventsToSend; i++) { + analytics.send(propertyEditorEvent); + } + for (var i = 0; i < countOfDevToolsEventsToSend; i++) { + analytics.send(devToolsEvent); + } + + expect(analytics.logFileStats(), isNotNull); + expect(logFile.readAsLinesSync().length, + countOfPropertyEditorEventsToSend + countOfDevToolsEventsToSend); + expect(analytics.logFileStats()!.eventCount['property_editor'], + countOfPropertyEditorEventsToSend); + expect(analytics.logFileStats()!.eventCount['devtools_event'], + countOfDevToolsEventsToSend); + }); + test('The only record in the log file is malformed', () async { // Write invalid json for the only log record logFile.writeAsStringSync('{{\n');