Skip to content
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
227 changes: 77 additions & 150 deletions packages/devtools_app/lib/src/shared/analytics/_analytics_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
library;

import 'dart:async';
import 'dart:js_interop';

import 'package:flutter/foundation.dart';
import 'package:js/js.dart';
import 'package:logging/logging.dart';
import 'package:unified_analytics/unified_analytics.dart' as ua;
import 'package:web/web.dart';
Expand Down Expand Up @@ -49,9 +49,7 @@ final _log = Logger('_analytics_web');
@JS('initializeGA')
external void initializeGA();

@JS()
@anonymous
class GtagEventDevTools extends GtagEvent {
extension type GtagEventDevTools._(JSObject _) implements GtagEvent {
// TODO(kenz): try to make this accept a JSON map of extra parameters rather
// than a fixed list of fields. See
// https://github.com/flutter/devtools/pull/3281#discussion_r692376353.
Expand All @@ -62,9 +60,7 @@ class GtagEventDevTools extends GtagEvent {

int value,
bool non_interaction,
// This code is going away so not worth cleaning up to be free of dynamic.
// ignore: avoid-dynamic
dynamic custom_map,
JSObject? custom_map,

// NOTE: Do not reorder any of these. Order here must match the order in the
// Google Analytics console.
Expand Down Expand Up @@ -113,72 +109,112 @@ class GtagEventDevTools extends GtagEvent {
int? inspector_tree_controller_id, // metric12
});

@override
external String? get event_category;
// Custom dimensions:
external String? get user_app;
external String? get user_build;
external String? get user_platform;
external String? get devtools_platform;
external String? get devtools_chrome;
external String? get devtools_version;
external String? get ide_launched;
external String? get flutter_client_id;
external String? get is_external_build;
external String? get is_embedded;
external String? get g3_username;
external String? get ide_launched_feature;

// Custom metrics:
external int? get ui_duration_micros;
external int? get raster_duration_micros;
external int? get shader_compilation_duration_micros;
external int? get cpu_sample_count;
external int? get cpu_stack_depth;
external int? get trace_event_count;
external int? get heap_diff_objects_before;
external int? get heap_diff_objects_after;
external int? get heap_objects_total;
external int? get root_set_count;
external int? get row_count;
external int? get inspector_tree_controller_id;
}

@override
external String? get event_label;
extension type GtagExceptionDevTools._(JSObject _) implements GtagException {
external factory GtagExceptionDevTools({
String? description,
bool fatal,

@override
external String? get send_to;
// NOTE: Do not reorder any of these. Order here must match the order in the
// Google Analytics console.

@override
external int get value; // Positive number.
String? user_app, // dimension1 (flutter or web)
String? user_build, // dimension2 (debug or profile)
String? user_platform, // dimension3 (android or ios)
String? devtools_platform, // dimension4 linux/android/mac/windows
String? devtools_chrome, // dimension5 Chrome version #
String? devtools_version, // dimension6 DevTools version #
String? ide_launched, // dimension7 IDE launched DevTools
String? flutter_client_id, // dimension8 Flutter tool clientId
String? is_external_build, // dimension9 External build or google3
String? is_embedded, // dimension10 Whether devtools is embedded
String? g3_username, // dimension11 g3 username (null for external users)

@override
external bool get non_interaction;
// dimension12 IDE feature that launched Devtools
// The following is a non-exhaustive list of possible values for this dimension:
// "command" - VS Code command palette
// "sidebarContent" - the content of the sidebar (e.g. the DevTools dropdown for a debug session)
// "sidebarTitle" - the DevTools action in the sidebar title
// "touchbar" - MacOS touchbar button
// "launchConfiguration" - configured explicitly in launch configuration
// "onDebugAutomatic" - configured to always run on debug session start
// "onDebugPrompt" - user responded to prompt when running a debug session
// "languageStatus" - launched from the language status popout
String? ide_launched_feature,

@override
external Object get custom_map;
// Performance screen metrics. See [PerformanceScreenMetrics].
int? ui_duration_micros, // metric1
int? raster_duration_micros, // metric2
int? shader_compilation_duration_micros, // metric3
// Profiler screen metrics. See [ProfilerScreenMetrics].
int? cpu_sample_count, // metric4
int? cpu_stack_depth, // metric5
// Performance screen metric. See [PerformanceScreenMetrics].
int? trace_event_count, // metric6
// Memory screen metric. See [MemoryScreenMetrics].
int? heap_diff_objects_before, // metric7
int? heap_diff_objects_after, // metric8
int? heap_objects_total, // metric9
// Inspector screen metrics. See [InspectorScreenMetrics].
int? root_set_count, // metric10
int? row_count, // metric11
int? inspector_tree_controller_id, // metric12
});

// Custom dimensions:
external String? get user_app;

external String? get user_build;

external String? get user_platform;

external String? get devtools_platform;

external String? get devtools_chrome;

external String? get devtools_version;

external String? get ide_launched;

external String? get flutter_client_id;

external String? get is_external_build;

external String? get is_embedded;

external String? get g3_username;

external String? get ide_launched_feature;

// Custom metrics:
external int? get ui_duration_micros;

external int? get raster_duration_micros;

external int? get shader_compilation_duration_micros;

external int? get cpu_sample_count;

external int? get cpu_stack_depth;

external int? get trace_event_count;

external int? get heap_diff_objects_before;

external int? get heap_diff_objects_after;

external int? get heap_objects_total;

external int? get root_set_count;

external int? get row_count;

external int? get inspector_tree_controller_id;
}

Expand Down Expand Up @@ -318,115 +354,6 @@ GtagExceptionDevTools _gtagException(
);
}

@JS()
@anonymous
class GtagExceptionDevTools extends GtagException {
external factory GtagExceptionDevTools({
String? description,
bool fatal,

// NOTE: Do not reorder any of these. Order here must match the order in the
// Google Analytics console.

String? user_app, // dimension1 (flutter or web)
String? user_build, // dimension2 (debug or profile)
String? user_platform, // dimension3 (android or ios)
String? devtools_platform, // dimension4 linux/android/mac/windows
String? devtools_chrome, // dimension5 Chrome version #
String? devtools_version, // dimension6 DevTools version #
String? ide_launched, // dimension7 IDE launched DevTools
String? flutter_client_id, // dimension8 Flutter tool clientId
String? is_external_build, // dimension9 External build or google3
String? is_embedded, // dimension10 Whether devtools is embedded
String? g3_username, // dimension11 g3 username (null for external users)

// dimension12 IDE feature that launched Devtools
// The following is a non-exhaustive list of possible values for this dimension:
// "command" - VS Code command palette
// "sidebarContent" - the content of the sidebar (e.g. the DevTools dropdown for a debug session)
// "sidebarTitle" - the DevTools action in the sidebar title
// "touchbar" - MacOS touchbar button
// "launchConfiguration" - configured explicitly in launch configuration
// "onDebugAutomatic" - configured to always run on debug session start
// "onDebugPrompt" - user responded to prompt when running a debug session
// "languageStatus" - launched from the language status popout
String? ide_launched_feature,

// Performance screen metrics. See [PerformanceScreenMetrics].
int? ui_duration_micros, // metric1
int? raster_duration_micros, // metric2
int? shader_compilation_duration_micros, // metric3
// Profiler screen metrics. See [ProfilerScreenMetrics].
int? cpu_sample_count, // metric4
int? cpu_stack_depth, // metric5
// Performance screen metric. See [PerformanceScreenMetrics].
int? trace_event_count, // metric6
// Memory screen metric. See [MemoryScreenMetrics].
int? heap_diff_objects_before, // metric7
int? heap_diff_objects_after, // metric8
int? heap_objects_total, // metric9
// Inspector screen metrics. See [InspectorScreenMetrics].
int? root_set_count, // metric10
int? row_count, // metric11
int? inspector_tree_controller_id, // metric12
});

@override
external String? get description; // Description of the error.
@override
external bool get fatal; // Fatal error.

// Custom dimensions:
external String? get user_app;

external String? get user_build;

external String? get user_platform;

external String? get devtools_platform;

external String? get devtools_chrome;

external String? get devtools_version;

external String? get ide_launched;

external String? get flutter_client_id;

external String? get is_external_build;

external String? get is_embedded;

external String? get g3_username;

external String? get ide_launched_feature;

// Custom metrics:
external int? get ui_duration_micros;

external int? get raster_duration_micros;

external int? get shader_compilation_duration_micros;

external int? get cpu_sample_count;

external int? get cpu_stack_depth;

external int? get trace_event_count;

external int? get heap_diff_objects_before;

external int? get heap_diff_objects_after;

external int? get heap_objects_total;

external int? get root_set_count;

external int? get row_count;

external int? get inspector_tree_controller_id;
}

/// Whether google analytics are enabled.
Future<bool> isAnalyticsEnabled() async {
bool enabled = false;
Expand Down
30 changes: 10 additions & 20 deletions packages/devtools_app/lib/src/shared/analytics/gtags.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
@JS()
library;

import 'dart:js_interop';

import 'package:flutter/foundation.dart';
import 'package:js/js.dart';

import '../../shared/development_helpers.dart';
import 'analytics.dart' as ga;
Expand All @@ -17,7 +18,7 @@ import 'analytics.dart' as ga;
/// For debugging install the Chrome Plugin "Google Analytics Debugger".

@JS('gtag')
external void _gTagCommandName(String command, String name, [Object? params]);
external void _gTagCommandName(String command, String name, [JSObject? params]);

// TODO(jacobr): refactor this code if we do not migrate off gtags.
// ignore: avoid_classes_with_only_static_members
Expand All @@ -44,38 +45,27 @@ class GTag {
}
}

@JS()
@anonymous
class GtagEvent {
extension type GtagEvent._(JSObject _) implements JSObject {
external factory GtagEvent({
String? event_category,
String? event_label, // Event e.g., gaScreenViewEvent, gaSelectEvent, etc.
String? send_to, // UA ID of target GA property to receive event data.

int value = 0,
bool non_interaction = false,
Object? custom_map,
int value,
bool non_interaction,
JSObject? custom_map,
});

external String? get event_category;

external String? get event_label;

external String? get send_to;

external int get value; // Positive number.
external bool get non_interaction;

external Object? get custom_map; // Custom metrics
external JSObject? get custom_map; // Custom metrics
}

@JS()
@anonymous
class GtagException {
external factory GtagException({
String? description,
bool fatal = false,
});
extension type GtagException._(JSObject _) implements JSObject {
external factory GtagException({String? description, bool fatal});

external String? get description; // Description of the error.
external bool get fatal; // Fatal error.
Expand Down
1 change: 0 additions & 1 deletion packages/devtools_app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ dependencies:
http: ^1.1.0
image: ^4.1.3
intl: ^0.19.0
js: ^0.6.1+1
json_rpc_2: ^3.0.2
logging: ^1.1.1
meta: ^1.9.1
Expand Down