Skip to content

Commit 48a544b

Browse files
authored
[pkgs/dash_analytics] Adding event for analyzer startup (#7)
* adding event for analyzer startup * switching from hyphens to underscore; GA4 restriction * making eventData nullable for events that don't need it * Update dash_analytics_example.dart * adding default to abstract method + removing `always_specify_types`
1 parent 5f9858f commit 48a544b

File tree

5 files changed

+39
-12
lines changed

5 files changed

+39
-12
lines changed

pkgs/dash_analytics/analysis_options.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ include: package:lints/recommended.yaml
1818
linter:
1919
rules:
2020
- always_declare_return_types
21-
- always_specify_types
2221
- camel_case_types
2322
- prefer_single_quotes
2423
- unawaited_futures

pkgs/dash_analytics/example/dash_analytics_example.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ void main() {
2323
print('###### START ###### $start');
2424

2525
print(analytics.telemetryEnabled);
26+
// [eventData] is an optional map to add relevant data
27+
// for the [eventName] being sent
2628
analytics.sendEvent(
2729
eventName: DashEvent.hotReloadTime,
2830
eventData: <String, int>{'time_ns': 345},

pkgs/dash_analytics/lib/src/analytics.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ abstract class Analytics {
127127
/// API to send events to Google Analytics to track usage
128128
Future<Response>? sendEvent({
129129
required DashEvent eventName,
130-
required Map<String, Object?> eventData,
130+
Map<String, Object?> eventData = const {},
131131
});
132132

133133
/// Pass a boolean to either enable or disable telemetry and make
@@ -243,7 +243,7 @@ class AnalyticsImpl implements Analytics {
243243
@override
244244
Future<Response>? sendEvent({
245245
required DashEvent eventName,
246-
required Map<String, Object?> eventData,
246+
Map<String, Object?> eventData = const {},
247247
}) {
248248
if (!telemetryEnabled) return null;
249249

@@ -290,7 +290,7 @@ class TestAnalytics extends AnalyticsImpl {
290290
@override
291291
Future<Response>? sendEvent({
292292
required DashEvent eventName,
293-
required Map<String, Object?> eventData,
293+
Map<String, Object?> eventData = const {},
294294
}) {
295295
if (!telemetryEnabled) return null;
296296

pkgs/dash_analytics/lib/src/enums.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
/// The [label] for each enum value is what will be logged, the [description]
88
/// is here for documentation purposes
99
enum DashEvent {
10+
analyzerServerStarted(
11+
label: 'analyzer_server_started',
12+
description: 'Dart Analyzer Server Started',
13+
toolOwner: DashTool.dartAnalyzer,
14+
),
1015
hotReloadTime(
1116
label: 'hot_reload_time',
1217
description: 'Hot reload duration',
@@ -26,14 +31,14 @@ enum DashEvent {
2631

2732
/// Officially-supported clients of this package.
2833
///
29-
/// All [label] values should use a hyphen as a delimiter
34+
/// All [label] values should use an underscore as a delimiter
3035
enum DashTool {
3136
flutterTools(
32-
label: 'flutter-tools',
37+
label: 'flutter_tools',
3338
description: 'Runs flutter applications from CLI',
3439
),
3540
dartAnalyzer(
36-
label: 'dart-analyzer',
41+
label: 'dart_analyzer',
3742
description: 'Analyzes dart code in workspace',
3843
);
3944

pkgs/dash_analytics/test/dash_analytics_test.dart

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -652,20 +652,41 @@ $initialToolName=${ConfigHandler.dateStamp},$toolsMessageVersion
652652
});
653653

654654
test(
655-
'All DashTools labels are made of characters that are letters or hyphens',
655+
'All DashTools labels are made of characters that are letters or underscores',
656656
() {
657-
// Regex pattern to match only letters or hyphens
658-
final RegExp toolLabelPattern = RegExp(r'^[a-zA-Z\-]+$');
657+
// Regex pattern to match only letters or underscores
658+
final RegExp toolLabelPattern = RegExp(r'^[a-zA-Z\_]+$');
659659
bool valid = true;
660+
final List<DashTool> invalidTools = <DashTool>[];
660661
for (DashTool tool in DashTool.values) {
661662
if (!toolLabelPattern.hasMatch(tool.label)) {
662663
valid = false;
664+
invalidTools.add(tool);
663665
}
664666
}
665667

666668
expect(valid, true,
667-
reason: 'All tool labels should have letters and hyphens '
668-
'as a delimiter if needed');
669+
reason: 'All tool labels should have letters and underscores '
670+
'as a delimiter if needed; invalid tools below\n$invalidTools');
671+
});
672+
673+
test(
674+
'All DashEvents labels are made of characters that are letters or underscores',
675+
() {
676+
// Regex pattern to match only letters or underscores
677+
final RegExp eventLabelPattern = RegExp(r'^[a-zA-Z\_]+$');
678+
bool valid = true;
679+
final List<DashEvent> invalidEvents = <DashEvent>[];
680+
for (DashEvent event in DashEvent.values) {
681+
if (!eventLabelPattern.hasMatch(event.label)) {
682+
valid = false;
683+
invalidEvents.add(event);
684+
}
685+
}
686+
687+
expect(valid, true,
688+
reason: 'All event labels should have letters and underscores '
689+
'as a delimiter if needed; invalid events below\n$invalidEvents');
669690
});
670691

671692
test('Check that log file is correctly persisting events sent', () {

0 commit comments

Comments
 (0)