Skip to content

Commit d74f9e1

Browse files
authored
[UA] Add a Flutter event for plugins injected into an iOS/macOS project. (#2062)
Flutter is migrating from CocoaPods to Swift Package Manager to manage native dependencies on iOS and macOS. We'd like to answer the following questions: 1. Does the Swift Package Manager feature increase error rates? 2. Can we remove CocoaPods support from Flutter's tooling? 3. Can we tell plugin authors that they can remove CocoaPods integration from their plugins? This adds a telemetry event that Flutter will send when it injects plugins into an iOS or macOS project. This will happen whenever a user does commands like `flutter build ios`, `flutter build macos`, and more. Part of flutter/flutter#147602 Flutter PR: flutter/flutter#166773
1 parent f34228f commit d74f9e1

File tree

6 files changed

+110
-4
lines changed

6 files changed

+110
-4
lines changed

pkgs/unified_analytics/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 8.0.1
2+
- Added `Event.flutterInjectDarwinPlugins` event for plugins injected into an iOS/macOS project.
3+
14
## 8.0.0
25
- Send `enabled_features` as an event parameter in all events rather than as a user property.
36

pkgs/unified_analytics/lib/src/constants.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ const int kMaxLogFileSize = 25 * (1 << 20);
8787
const String kLogFileName = 'dart-flutter-telemetry.log';
8888

8989
/// The current version of the package, should be in line with pubspec version.
90-
const String kPackageVersion = '8.0.0';
90+
const String kPackageVersion = '8.0.1';
9191

9292
/// The minimum length for a session.
9393
const int kSessionDurationMinutes = 30;

pkgs/unified_analytics/lib/src/enums.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ enum DashEvent {
7474
),
7575
codeSizeAnalysis(
7676
label: 'code_size_analysis',
77-
description: 'Indicates when the "--analyize-size" command is run',
77+
description: 'Indicates when the "--analyze-size" command is run',
7878
toolOwner: DashTool.flutterTool,
7979
),
8080
commandUsageValues(
@@ -98,6 +98,11 @@ enum DashEvent {
9898
description: 'Provides information about flutter commands that ran',
9999
toolOwner: DashTool.flutterTool,
100100
),
101+
flutterInjectDarwinPlugins(
102+
label: 'flutter_inject_darwin_plugins',
103+
description: 'Information on plugins injected into an iOS/macOS project',
104+
toolOwner: DashTool.flutterTool,
105+
),
101106
hotReloadTime(
102107
label: 'hot_reload_time',
103108
description: 'Hot reload duration',

pkgs/unified_analytics/lib/src/event.dart

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,71 @@ final class Event {
557557
},
558558
);
559559

560+
/// Provides information about the plugins injected into an iOS or macOS
561+
/// project.
562+
///
563+
/// This event is not sent if a project has no plugins.
564+
///
565+
/// [platform] - The project's platform. Either 'ios' or 'macos'.
566+
///
567+
/// [isModule] - whether the project is an add-to-app Flutter module.
568+
///
569+
/// [swiftPackageManagerUsable] - if `true`, Swift Package Manager can be used
570+
/// for the project's plugins if any are Swift Package Manager compatible.
571+
///
572+
/// [swiftPackageManagerFeatureEnabled] - if the Swift Package Manager feature
573+
/// flag is on. If false, Swift Package Manager is off for all projects on
574+
/// the development machine.
575+
///
576+
/// [projectDisabledSwiftPackageManager] - if the project's .pubspec has
577+
/// `disable-swift-package-manager: true`. This turns off Swift Package
578+
/// Manager for a single project.
579+
///
580+
/// [projectHasSwiftPackageManagerIntegration] - if the Xcode project has
581+
/// Swift Package Manager integration. If `false`, the project needs to be
582+
/// migrated.
583+
///
584+
/// [pluginCount] - the total number of plugins for this project. A plugin
585+
/// can be compatible with both Swift Package Manager and CocoaPods. Plugins
586+
/// compatible with both will be counted in both [swiftPackageCount] and
587+
/// [podCount]. Swift Package Manager was used to inject all plugins if
588+
/// [pluginCount] is equal to [swiftPackageCount].
589+
///
590+
/// [swiftPackageCount] - the number of plugins compatible with Swift Package
591+
/// Manager. This is less than or equal to [pluginCount]. If
592+
/// [swiftPackageCount] is less than [pluginCount], the project uses CocoaPods
593+
/// to inject plugins.
594+
///
595+
/// [podCount] - the number of plugins compatible with CocoaPods. This is less
596+
/// than or equal to [podCount].
597+
Event.flutterInjectDarwinPlugins({
598+
required String platform,
599+
required bool isModule,
600+
required bool swiftPackageManagerUsable,
601+
required bool swiftPackageManagerFeatureEnabled,
602+
required bool projectDisabledSwiftPackageManager,
603+
required bool projectHasSwiftPackageManagerIntegration,
604+
required int pluginCount,
605+
required int swiftPackageCount,
606+
required int podCount,
607+
}) : this._(
608+
eventName: DashEvent.flutterInjectDarwinPlugins,
609+
eventData: {
610+
'platform': platform,
611+
'isModule': isModule,
612+
'swiftPackageManagerUsable': swiftPackageManagerUsable,
613+
'swiftPackageManagerFeatureEnabled':
614+
swiftPackageManagerFeatureEnabled,
615+
'projectDisabledSwiftPackageManager':
616+
projectDisabledSwiftPackageManager,
617+
'projectHasSwiftPackageManagerIntegration':
618+
projectHasSwiftPackageManagerIntegration,
619+
'pluginCount': pluginCount,
620+
'swiftPackageCount': swiftPackageCount,
621+
'podCount': podCount,
622+
},
623+
);
624+
560625
// TODO: eliasyishak, remove this or replace once we have a generic
561626
// timing event that can be used by potentially more than one DashTool
562627
Event.hotReloadTime({required int timeMs})

pkgs/unified_analytics/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: >-
55
# LINT.IfChange
66
# When updating this, keep the version consistent with the changelog and the
77
# value in lib/src/constants.dart.
8-
version: 8.0.0
8+
version: 8.0.1
99
# LINT.ThenChange(lib/src/constants.dart)
1010
repository: https://github.com/dart-lang/tools/tree/main/pkgs/unified_analytics
1111
issue_tracker: https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Aunified_analytics

pkgs/unified_analytics/test/event_test.dart

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,39 @@ void main() {
400400
expect(constructedEvent.eventData.length, 4);
401401
});
402402

403+
test('Event.flutterInjectDarwinPlugins constructed', () {
404+
Event generateEvent() => Event.flutterInjectDarwinPlugins(
405+
platform: 'ios',
406+
isModule: true,
407+
swiftPackageManagerUsable: true,
408+
swiftPackageManagerFeatureEnabled: true,
409+
projectDisabledSwiftPackageManager: false,
410+
projectHasSwiftPackageManagerIntegration: true,
411+
pluginCount: 123,
412+
swiftPackageCount: 456,
413+
podCount: 678,
414+
);
415+
416+
final constructedEvent = generateEvent();
417+
418+
expect(generateEvent, returnsNormally);
419+
expect(constructedEvent.eventName, DashEvent.flutterInjectDarwinPlugins);
420+
expect(constructedEvent.eventData['platform'], 'ios');
421+
expect(constructedEvent.eventData['isModule'], isTrue);
422+
expect(constructedEvent.eventData['swiftPackageManagerUsable'], isTrue);
423+
expect(constructedEvent.eventData['swiftPackageManagerFeatureEnabled'],
424+
isTrue);
425+
expect(constructedEvent.eventData['projectDisabledSwiftPackageManager'],
426+
isFalse);
427+
expect(
428+
constructedEvent.eventData['projectHasSwiftPackageManagerIntegration'],
429+
isTrue);
430+
expect(constructedEvent.eventData['pluginCount'], 123);
431+
expect(constructedEvent.eventData['swiftPackageCount'], 456);
432+
expect(constructedEvent.eventData['podCount'], 678);
433+
expect(constructedEvent.eventData.length, 9);
434+
});
435+
403436
test('Event.codeSizeAnalysis constructed', () {
404437
Event generateEvent() => Event.codeSizeAnalysis(platform: 'platform');
405438

@@ -634,7 +667,7 @@ void main() {
634667

635668
// Change this integer below if your PR either adds or removes
636669
// an Event constructor
637-
final eventsAccountedForInTests = 27;
670+
final eventsAccountedForInTests = 28;
638671
expect(eventsAccountedForInTests, constructorCount,
639672
reason: 'If you added or removed an event constructor, '
640673
'ensure you have updated '

0 commit comments

Comments
 (0)