[Reland] Migration for the sendTiming events for package:unified_analytics (#139299)
Relanding based on this comment: - https://github.com/flutter/flutter/pull/139278#issuecomment-1832951108 Related to tracker issue: - https://github.com/flutter/flutter/issues/128251 <img width="278" alt="image" src="https://github.com/flutter/flutter/assets/42216813/cee7b9be-48d6-48e5-8c39-de28d0a1f0de"> The image above shows all of the instances where we have `sendTiming`. All of the call sites have been updated to use the new `Event.timing` event from `package:unified_analytics`.
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:args/command_runner.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:flutter_tools/src/base/common.dart';
|
||||
import 'package:flutter_tools/src/base/context.dart';
|
||||
@@ -347,3 +348,38 @@ FakeAnalytics getInitializedFakeAnalyticsInstance({
|
||||
clientIde: clientIde,
|
||||
);
|
||||
}
|
||||
|
||||
/// Returns "true" if the timing event searched for exists in [sentEvents].
|
||||
///
|
||||
/// This utility function allows us to check for an instance of
|
||||
/// [Event.timing] within a [FakeAnalytics] instance. Normally, we can
|
||||
/// use the equality operator for [Event] to check if the event exists, but
|
||||
/// we are unable to do so for the timing event because the elapsed time
|
||||
/// is variable so we cannot predict what that value will be in tests.
|
||||
///
|
||||
/// This function allows us to check for the other keys that have
|
||||
/// string values by removing the `elapsedMilliseconds` from the
|
||||
/// [Event.eventData] map and checking for a match.
|
||||
bool analyticsTimingEventExists({
|
||||
required List<Event> sentEvents,
|
||||
required String workflow,
|
||||
required String variableName,
|
||||
String? label,
|
||||
}) {
|
||||
final Map<String, String> lookup = <String, String>{
|
||||
'workflow': workflow,
|
||||
'variableName': variableName,
|
||||
if (label != null) 'label': label,
|
||||
};
|
||||
|
||||
for (final Event e in sentEvents) {
|
||||
final Map<String, Object?> eventData = e.eventData;
|
||||
eventData.remove('elapsedMilliseconds');
|
||||
|
||||
if (const DeepCollectionEquality().equals(lookup, eventData)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user