@@ -22,6 +22,7 @@ import 'src/commands/pub.dart';
22
22
import 'src/commands/run.dart' ;
23
23
import 'src/commands/test.dart' ;
24
24
import 'src/core.dart' ;
25
+ import 'src/events.dart' ;
25
26
import 'src/experiments.dart' ;
26
27
import 'src/sdk.dart' ;
27
28
import 'src/utils.dart' ;
@@ -35,10 +36,6 @@ Future<void> runDartdev(List<String> args, SendPort port) async {
35
36
final stopwatch = Stopwatch ();
36
37
int result;
37
38
38
- // The Analytics instance used to report information back to Google Analytics,
39
- // see lib/src/analytics.dart.
40
- Analytics analytics;
41
-
42
39
// The exit code for the dartdev process, null indicates that it has not yet
43
40
// been set yet. The value is set in the catch and finally blocks below.
44
41
int exitCode;
@@ -47,7 +44,9 @@ Future<void> runDartdev(List<String> args, SendPort port) async {
47
44
Object exception;
48
45
StackTrace stackTrace;
49
46
50
- analytics =
47
+ // The Analytics instance used to report information back to Google Analytics,
48
+ // see lib/src/analytics.dart.
49
+ Analytics analytics =
51
50
createAnalyticsInstance (args.contains ('--disable-dartdev-analytics' ));
52
51
53
52
// If we have not printed the analyticsNoticeOnFirstRunMessage to stdout,
@@ -92,11 +91,13 @@ Future<void> runDartdev(List<String> args, SendPort port) async {
92
91
// RunCommand.ddsHost = ddsUrl[0];
93
92
// RunCommand.ddsPort = ddsUrl[1];
94
93
}
94
+
95
95
String commandName;
96
96
97
97
try {
98
98
stopwatch.start ();
99
99
final runner = DartdevRunner (args);
100
+
100
101
// Run can't be called with the '--disable-dartdev-analytics' flag, remove
101
102
// it if it is contained in args.
102
103
if (args.contains ('--disable-dartdev-analytics' )) {
@@ -119,14 +120,6 @@ Future<void> runDartdev(List<String> args, SendPort port) async {
119
120
)
120
121
.toList ();
121
122
122
- // Before calling to run, send the first ping to analytics to have the first
123
- // ping, as well as the command itself, running in parallel.
124
- if (analytics.enabled) {
125
- commandName = getCommandStr (args, runner.commands.keys.toList ());
126
- // ignore: unawaited_futures
127
- analytics.sendEvent (eventCategory, commandName);
128
- }
129
-
130
123
// If ... help pub ... is in the args list, remove 'help', and add '--help'
131
124
// to the end of the list. This will make it possible to use the help
132
125
// command to access subcommands of pub such as `dart help pub publish`, see
@@ -135,6 +128,17 @@ Future<void> runDartdev(List<String> args, SendPort port) async {
135
128
args = PubUtils .modifyArgs (args);
136
129
}
137
130
131
+ // For the commands format and migrate, dartdev itself sends the
132
+ // sendScreenView notification to analytics, for all other
133
+ // dartdev commands (instances of DartdevCommand) the commands send this
134
+ // to analytics.
135
+ commandName = ArgParserUtils .getCommandStr (args);
136
+ if (analytics.enabled &&
137
+ (commandName == formatCmdName || commandName == migrateCmdName)) {
138
+ // ignore: unawaited_futures
139
+ analytics.sendScreenView (commandName);
140
+ }
141
+
138
142
// Finally, call the runner to execute the command, see DartdevRunner.
139
143
result = await runner.run (args);
140
144
} catch (e, st) {
@@ -157,7 +161,22 @@ Future<void> runDartdev(List<String> args, SendPort port) async {
157
161
158
162
// Send analytics before exiting
159
163
if (analytics.enabled) {
160
- analytics.setSessionValue (exitCodeParam, exitCode);
164
+ // For commands that are not DartdevCommand instances, we manually create
165
+ // and send the UsageEvent from here:
166
+ if (commandName == formatCmdName) {
167
+ // ignore: unawaited_futures
168
+ FormatUsageEvent (
169
+ exitCode: exitCode,
170
+ args: args,
171
+ ).send (analyticsInstance);
172
+ } else if (commandName == migrateCmdName) {
173
+ // ignore: unawaited_futures
174
+ MigrateUsageEvent (
175
+ exitCode: exitCode,
176
+ args: args,
177
+ ).send (analyticsInstance);
178
+ }
179
+
161
180
// ignore: unawaited_futures
162
181
analytics.sendTiming (commandName, stopwatch.elapsedMilliseconds,
163
182
category: 'commands' );
0 commit comments