Skip to content

Commit

Permalink
Add enabledFeatures key to Analytics constructors (#217)
Browse files Browse the repository at this point in the history
* Add `enabledFeatures` key to `Analytics` constructors

* Format fix

* Update versions

* Bump minor version instead
  • Loading branch information
eliasyishak authored Dec 11, 2023
1 parent ed81684 commit 56a30ce
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 3 deletions.
3 changes: 2 additions & 1 deletion pkgs/unified_analytics/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 5.7.1-wip
## 5.8.0

- Fix template string for consent message
- Add `enabledFeatures` to constructor to collect features enabled for each dash tool

## 5.7.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ final Analytics analytics = Analytics.development(
// This can be set to true while testing to validate
// against GA4 usage limitations (character limits, etc.)
enableAsserts: false,
enabledFeatures: 'feature-1,feature-2',
);

// Timing a process and sending the event
Expand Down
14 changes: 14 additions & 0 deletions pkgs/unified_analytics/lib/src/analytics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,18 @@ abstract class Analytics {
/// An optional parameter [clientIde] is also available for dart and flutter
/// tooling that are running from IDEs can be resolved. Such as "VSCode"
/// running the flutter-tool.
///
/// [enabledFeatures] is also an optional field that can be added to collect
/// any features that are enabled for a user. For example,
/// "enable-linux-desktop,cli-animations" are two features that can be enabled
/// for the flutter-tool.
factory Analytics({
required DashTool tool,
required String dartVersion,
String? flutterChannel,
String? flutterVersion,
String? clientIde,
String? enabledFeatures,
bool enableAsserts = false,
}) {
// Create the instance of the file system so clients don't need
Expand Down Expand Up @@ -87,6 +93,7 @@ abstract class Analytics {
surveyHandler: SurveyHandler(homeDirectory: homeDirectory, fs: fs),
enableAsserts: enableAsserts,
clientIde: clientIde,
enabledFeatures: enabledFeatures,
);
}

Expand All @@ -105,6 +112,7 @@ abstract class Analytics {
String? flutterChannel,
String? flutterVersion,
String? clientIde,
String? enabledFeatures,
bool enableAsserts = true,
}) {
// Create the instance of the file system so clients don't need
Expand Down Expand Up @@ -155,6 +163,7 @@ abstract class Analytics {
surveyHandler: SurveyHandler(homeDirectory: homeDirectory, fs: fs),
enableAsserts: enableAsserts,
clientIde: clientIde,
enabledFeatures: enabledFeatures,
);
}

Expand All @@ -172,6 +181,7 @@ abstract class Analytics {
String? flutterChannel,
String? flutterVersion,
String? clientIde,
String? enabledFeatures,
SurveyHandler? surveyHandler,
GAClient? gaClient,
int toolsMessageVersion = kToolsMessageVersion,
Expand All @@ -195,6 +205,7 @@ abstract class Analytics {
gaClient: gaClient ?? const FakeGAClient(),
enableAsserts: true,
clientIde: clientIde,
enabledFeatures: enabledFeatures,
);

/// The shared identifier for Flutter and Dart related tooling using
Expand Down Expand Up @@ -352,6 +363,7 @@ class AnalyticsImpl implements Analytics {
required String? flutterChannel,
required String? flutterVersion,
required String? clientIde,
required String? enabledFeatures,
required String dartVersion,
required DevicePlatform platform,
required this.toolsMessageVersion,
Expand Down Expand Up @@ -426,6 +438,7 @@ class AnalyticsImpl implements Analytics {
truncateStringToLength(io.Platform.operatingSystemVersion, 36),
locale: io.Platform.localeName,
clientIde: clientIde,
enabledFeatures: enabledFeatures,
);

// Initialize the log handler to persist events that are being sent
Expand Down Expand Up @@ -705,6 +718,7 @@ class FakeAnalytics extends AnalyticsImpl {
super.flutterChannel,
super.flutterVersion,
super.clientIde,
super.enabledFeatures,
}) : super(
gaClient: const FakeGAClient(),
enableAsserts: true,
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 = '5.7.1-wip';
const String kPackageVersion = '5.8.0';

/// The minimum length for a session.
const int kSessionDurationMinutes = 30;
Expand Down
3 changes: 3 additions & 0 deletions pkgs/unified_analytics/lib/src/user_property.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class UserProperty {
final String hostOsVersion;
final String locale;
final String? clientIde;
final String? enabledFeatures;

/// This class is intended to capture all of the user's
/// metadata when the class gets initialized as well as collecting
Expand All @@ -34,6 +35,7 @@ class UserProperty {
required this.hostOsVersion,
required this.locale,
required this.clientIde,
required this.enabledFeatures,
});

/// This method will take the data in this class and convert it into
Expand Down Expand Up @@ -69,5 +71,6 @@ class UserProperty {
'host_os_version': hostOsVersion,
'locale': locale,
'client_ide': clientIde,
'enabled_features': enabledFeatures,
};
}
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: 5.7.1-wip
version: 5.8.0
repository: https://github.com/dart-lang/tools/tree/main/pkgs/unified_analytics

environment:
Expand Down
3 changes: 3 additions & 0 deletions pkgs/unified_analytics/test/unified_analytics_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ void main() {
const hostOsVersion = 'Version 14.1 (Build 23B74)';
const locale = 'en';
const clientIde = 'VSCode';
const enabledFeatures = 'enable-linux-desktop,cli-animations';

final testEvent = Event.hotReloadTime(timeMs: 50);

Expand Down Expand Up @@ -122,6 +123,7 @@ void main() {
hostOsVersion: hostOsVersion,
locale: locale,
clientIde: clientIde,
enabledFeatures: enabledFeatures,
);
});

Expand Down Expand Up @@ -604,6 +606,7 @@ ${initialTool.label}=$dateStamp,$toolsMessageVersion
'host_os_version',
'locale',
'client_ide',
'enabled_features',
];
expect(analytics.userPropertyMap.keys.length, userPropertyKeys.length,
reason: 'There should only be ${userPropertyKeys.length} keys');
Expand Down

0 comments on commit 56a30ce

Please sign in to comment.