Skip to content

Event Constructor added for devtools event #258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkgs/unified_analytics/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 6.1.0

- Added new event constructor `Event.devtoolsEvent` for the single devtools event with a new enum value `DashEvent.devtoolsEvent`

## 6.0.0

- Consolidate `Session` functionality into `UserProperty` to prevent race condition crash where session logic crashed before initializing `UserProperty`
Expand Down
2 changes: 1 addition & 1 deletion pkgs/unified_analytics/lib/src/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const int kLogFileLength = 2500;
const String kLogFileName = 'dart-flutter-telemetry.log';

/// The current version of the package, should be in line with pubspec version.
const String kPackageVersion = '6.0.0';
const String kPackageVersion = '6.1.0';

/// The minimum length for a session.
const int kSessionDurationMinutes = 30;
Expand Down
8 changes: 8 additions & 0 deletions pkgs/unified_analytics/lib/src/enums.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ enum DashEvent {
toolOwner: DashTool.dartTool,
),

// Events for Flutter devtools

devtoolsEvent(
label: 'devtools_event',
description: 'Information for various devtools events',
toolOwner: DashTool.devtools,
),

// Events for the Flutter CLI

appleUsageEvent(
Expand Down
90 changes: 90 additions & 0 deletions pkgs/unified_analytics/lib/src/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,96 @@ final class Event {
if (exitCode != null) 'exitCode': exitCode,
};

/// Event that is sent from devtools for various different actions as
/// indicated by the [eventCategory].
Event.devtoolsEvent({
required String eventCategory,
required String label,
required int value,

// Defaulted values
bool userInitiatedInteraction = true,

// Optional parameters
String? g3Username,
String? userApp,
String? userBuild,
String? userPlatform,
String? devtoolsPlatform,
String? devtoolsChrome,
String? devtoolsVersion,
String? ideLaunched,
String? isExternalBuild,
String? isEmbedded,
String? ideLaunchedFeature,

// PerformanceScreenMetrics
int? uiDurationMicros,
int? rasterDurationMicros,
int? shaderCompilationDurationMicros,
int? traceEventCount,

// ProfilerScreenMetrics
int? cpuSampleCount,
int? cpuStackDepth,

// MemoryScreenMetrics
int? heapDiffObjectsBefore,
int? heapDiffObjectsAfter,
int? heapObjectsTotal,

// InspectorScreenMetrics
int? rootSetCount,
int? rowCount,
int? inspectorTreeControllerId,
}) : eventName = DashEvent.devtoolsEvent,
eventData = {
'eventCategory': eventCategory,
'label': label,
'value': value,

'userInitiatedInteraction': userInitiatedInteraction,

// Optional parameters
if (g3Username != null) 'g3Username': g3Username,
if (userApp != null) 'userApp': userApp,
if (userBuild != null) 'userBuild': userBuild,
if (userPlatform != null) 'userPlatform': userPlatform,
if (devtoolsPlatform != null) 'devtoolsPlatform': devtoolsPlatform,
if (devtoolsChrome != null) 'devtoolsChrome': devtoolsChrome,
if (devtoolsVersion != null) 'devtoolsVersion': devtoolsVersion,
if (ideLaunched != null) 'ideLaunched': ideLaunched,
if (isExternalBuild != null) 'isExternalBuild': isExternalBuild,
if (isEmbedded != null) 'isEmbedded': isEmbedded,
if (ideLaunchedFeature != null)
'ideLaunchedFeature': ideLaunchedFeature,

// PerformanceScreenMetrics
if (uiDurationMicros != null) 'uiDurationMicros': uiDurationMicros,
if (rasterDurationMicros != null)
'rasterDurationMicros': rasterDurationMicros,
if (shaderCompilationDurationMicros != null)
'shaderCompilationDurationMicros': shaderCompilationDurationMicros,
if (traceEventCount != null) 'traceEventCount': traceEventCount,

// ProfilerScreenMetrics
if (cpuSampleCount != null) 'cpuSampleCount': cpuSampleCount,
if (cpuStackDepth != null) 'cpuStackDepth': cpuStackDepth,

// MemoryScreenMetrics
if (heapDiffObjectsBefore != null)
'heapDiffObjectsBefore': heapDiffObjectsBefore,
if (heapDiffObjectsAfter != null)
'heapDiffObjectsAfter': heapDiffObjectsAfter,
if (heapObjectsTotal != null) 'heapObjectsTotal': heapObjectsTotal,

// InspectorScreenMetrics
if (rootSetCount != null) 'rootSetCount': rootSetCount,
if (rowCount != null) 'rowCount': rowCount,
if (inspectorTreeControllerId != null)
'inspectorTreeControllerId': inspectorTreeControllerId,
};

Comment on lines +359 to +448
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this look like everything is being captured from the _gtagEvent function?

Referenced from here: https://github.com/eliasyishak/devtools/blob/migrate-select-event/packages/devtools_app/lib/src/shared/analytics/_analytics_web.dart#L196-L254

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have included all of the fields from the linked function above, except for sent_to and flutter_client_id and that is because we have the "send to" for GA4 within the package and the client id is managed by the package and added to the payload on send requests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/// Event that contains the results for a specific doctor validator.
///
/// [validatorName] - the name for the doctor validator.
Expand Down
2 changes: 1 addition & 1 deletion pkgs/unified_analytics/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: >-
to Google Analytics.
# When updating this, keep the version consistent with the changelog and the
# value in lib/src/constants.dart.
version: 6.0.0
version: 6.1.0
repository: https://github.com/dart-lang/tools/tree/main/pkgs/unified_analytics

environment:
Expand Down
67 changes: 66 additions & 1 deletion pkgs/unified_analytics/test/event_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,71 @@ void main() {
expect(constructedEvent.eventData.length, 3);
});

test('Event.devtoolsEvent constructed', () {
Event generateEvent() => Event.devtoolsEvent(
eventCategory: 'eventCategory',
label: 'label',
value: 1,
userInitiatedInteraction: true,
g3Username: 'g3Username',
userApp: 'userApp',
userBuild: 'userBuild',
userPlatform: 'userPlatform',
devtoolsPlatform: 'devtoolsPlatform',
devtoolsChrome: 'devtoolsChrome',
devtoolsVersion: 'devtoolsVersion',
ideLaunched: 'ideLaunched',
isExternalBuild: 'isExternalBuild',
isEmbedded: 'isEmbedded',
ideLaunchedFeature: 'ideLaunchedFeature',
uiDurationMicros: 123,
rasterDurationMicros: 123,
shaderCompilationDurationMicros: 123,
traceEventCount: 123,
cpuSampleCount: 123,
cpuStackDepth: 123,
heapDiffObjectsBefore: 123,
heapDiffObjectsAfter: 123,
heapObjectsTotal: 123,
rootSetCount: 123,
rowCount: 123,
inspectorTreeControllerId: 123,
);

final constructedEvent = generateEvent();

expect(generateEvent, returnsNormally);
expect(constructedEvent.eventData['eventCategory'], 'eventCategory');
expect(constructedEvent.eventData['label'], 'label');
expect(constructedEvent.eventData['value'], 1);
expect(constructedEvent.eventData['userInitiatedInteraction'], true);
expect(constructedEvent.eventData['g3Username'], 'g3Username');
expect(constructedEvent.eventData['userApp'], 'userApp');
expect(constructedEvent.eventData['userBuild'], 'userBuild');
expect(constructedEvent.eventData['userPlatform'], 'userPlatform');
expect(constructedEvent.eventData['devtoolsPlatform'], 'devtoolsPlatform');
expect(constructedEvent.eventData['devtoolsChrome'], 'devtoolsChrome');
expect(constructedEvent.eventData['devtoolsVersion'], 'devtoolsVersion');
expect(constructedEvent.eventData['ideLaunched'], 'ideLaunched');
expect(constructedEvent.eventData['isExternalBuild'], 'isExternalBuild');
expect(constructedEvent.eventData['isEmbedded'], 'isEmbedded');
expect(
constructedEvent.eventData['ideLaunchedFeature'], 'ideLaunchedFeature');
expect(constructedEvent.eventData['uiDurationMicros'], 123);
expect(constructedEvent.eventData['rasterDurationMicros'], 123);
expect(constructedEvent.eventData['shaderCompilationDurationMicros'], 123);
expect(constructedEvent.eventData['traceEventCount'], 123);
expect(constructedEvent.eventData['cpuSampleCount'], 123);
expect(constructedEvent.eventData['cpuStackDepth'], 123);
expect(constructedEvent.eventData['heapDiffObjectsBefore'], 123);
expect(constructedEvent.eventData['heapDiffObjectsAfter'], 123);
expect(constructedEvent.eventData['heapObjectsTotal'], 123);
expect(constructedEvent.eventData['rootSetCount'], 123);
expect(constructedEvent.eventData['rowCount'], 123);
expect(constructedEvent.eventData['inspectorTreeControllerId'], 123);
expect(constructedEvent.eventData.length, 27);
});

test('Confirm all constructors were checked', () {
var constructorCount = 0;
for (var declaration in reflectClass(Event).declarations.keys) {
Expand All @@ -563,7 +628,7 @@ void main() {

// Change this integer below if your PR either adds or removes
// an Event constructor
final eventsAccountedForInTests = 26;
final eventsAccountedForInTests = 27;
expect(eventsAccountedForInTests, constructorCount,
reason: 'If you added or removed an event constructor, '
'ensure you have updated '
Expand Down