@@ -20,6 +20,7 @@ import '../cache.dart';
2020import '../compile.dart' show kDdcCanaryFeatures;
2121import '../context/tool_context.dart' ;
2222import '../flutter_plugins.dart' ;
23+ import '../globals.dart' as globals;
2324import '../platform_plugins.dart' ;
2425import '../plugins.dart' ;
2526import '../project.dart' ;
@@ -109,6 +110,7 @@ class WebBuilder {
109110 final migration = ProjectMigration (migrators);
110111 await migration.run ();
111112
113+ final String buildSettingsString = _buildEventAnalyticsSettings (configs: compilerConfigs);
112114 final Status status = logger.startProgress ('Compiling $target for the Web...' );
113115 final sw = Stopwatch ()..start ();
114116 try {
@@ -160,6 +162,11 @@ class WebBuilder {
160162 : null ,
161163 );
162164 }
165+ _sendFailedBuildAnalytics (
166+ compilerConfigs: compilerConfigs,
167+ exceptions: result.exceptions,
168+ settings: buildSettingsString,
169+ );
163170 throwToolExit ('Failed to compile application for the Web.' );
164171 }
165172 } on Exception catch (err) {
@@ -176,8 +183,6 @@ class WebBuilder {
176183 color: TerminalColor .green,
177184 );
178185
179- final String buildSettingsString = _buildEventAnalyticsSettings (configs: compilerConfigs);
180-
181186 _analytics.send (
182187 Event .flutterBuildInfo (label: 'web-compile' , buildType: 'web' , settings: buildSettingsString),
183188 );
@@ -192,6 +197,35 @@ class WebBuilder {
192197 ),
193198 );
194199 }
200+
201+ void _sendFailedBuildAnalytics ({
202+ required List <WebCompilerConfig > compilerConfigs,
203+ required Map <String , ExceptionMeasurement > exceptions,
204+ required String settings,
205+ }) {
206+ final bool hasDeprecatedJsInteropFlag = compilerConfigs.any (
207+ (WebCompilerConfig config) =>
208+ config is JsCompilerConfig && config.deprecatedJsInterop != null ,
209+ );
210+ if (! hasDeprecatedJsInteropFlag) {
211+ return ;
212+ }
213+ final List <String > failedTargets = < String > {
214+ for (final ExceptionMeasurement measurement in exceptions.values) measurement.target,
215+ }.toList ()..sort ();
216+ final rawError = failedTargets.isEmpty
217+ ? 'web-compile-failure'
218+ : '${failedTargets .join (',' )}-failure' ;
219+ final error = rawError.length > 100 ? '${rawError .substring (0 , 92 )}...-fail' : rawError;
220+ _analytics.send (
221+ Event .flutterBuildInfo (
222+ label: 'web-compile' ,
223+ buildType: 'web' ,
224+ settings: settings,
225+ error: error,
226+ ),
227+ );
228+ }
195229}
196230
197231/// Web rendering backend mode.
@@ -287,8 +321,41 @@ String _buildEventAnalyticsSettings({required List<WebCompilerConfig> configs})
287321 values['web-renderer' ] = renderers.join (',' );
288322 values['web-target' ] = targets.join (',' );
289323
290- final List <String > sortedList =
291- values.entries.map ((MapEntry <String , Object > e) => '${e .key }: ${e .value };' ).toList ()..sort ();
324+ String formatValues (Map <String , Object > entries) {
325+ final List <String > sortedList =
326+ entries.entries.map ((MapEntry <String , Object > e) => '${e .key }: ${e .value };' ).toList ()
327+ ..sort ();
328+ return sortedList.join (' ' );
329+ }
330+
331+ final String result = formatValues (values);
332+ // GA4 / package:unified_analytics enforces a 100-character limit on event
333+ // parameter values. Drop `optimizationLevel` if the combined settings
334+ // exceed the limit.
335+ if (result.length > 100 && values.remove ('optimizationLevel' ) != null ) {
336+ return formatValues (values);
337+ }
338+ return result;
339+ }
292340
293- return sortedList.join (' ' );
341+ /// Sends an [Event.flutterBuildInfo] event for a DDC web compilation when
342+ /// `--[no-]deprecated-js-interop` (`[deprecatedJsInterop]` ) was explicitly set.
343+ void sendDdcCompileAnalytics ({
344+ required bool ? deprecatedJsInterop,
345+ required String command,
346+ required bool succeeded,
347+ Analytics ? analytics,
348+ }) {
349+ if (deprecatedJsInterop == null ) {
350+ return ;
351+ }
352+ (analytics ?? globals.analytics).send (
353+ Event .flutterBuildInfo (
354+ label: 'web-compile' ,
355+ buildType: 'web' ,
356+ command: command,
357+ settings: 'deprecatedJsInterop: $deprecatedJsInterop ; web-compiler: ddc;' ,
358+ error: succeeded ? null : 'ddc-compile-failure' ,
359+ ),
360+ );
294361}
0 commit comments