amplitude / amplitude/Amplitude-Flutter
Amplitude.track does not await isBuilt: events tracked before init (e.g. first screen view) are silently dropped
- Langage dominant
- Dart
- Étoiles
- 133
- Forks
- 108
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
## Summary
`Amplitude.track` invokes the platform method channel immediately without awaiting `isBuilt`, so events tracked before initialization completes can be silently dropped. In practice the first `[Amplitude] Screen Viewed` from the initial route's `didPush` (via `AmplitudeNavigatorObserver`) is the most likely casualty, since apps typically construct the observer in the same frame they construct `Amplitude`.
This was originally flagged by Cursor Bugbot on #309 ("Screen views lost before init") and was not addressed there. Confirmed still present in the published 4.7.1 `lib/amplitude.dart`:
```dart
Future track(
BaseEvent event, [
EventOptions? options,
]) async {
if (options != null) {
event.mergeEventOptions(options);
}
return await _channel.invokeMethod('track',
{'instanceName': configuration.instanceName, 'event': event.toMap()});
}
```
`isBuilt` exists (`lib/amplitude.dart` sets it from `_init()` in the constructor) but `track` never awaits it, unlike what the class-level docs suggest callers should do manually.
## Steps to reproduce
1. Construct `Amplitude(Configuration(...))` and immediately `runApp` with an `AmplitudeNavigatorObserver` attached (the documented setup).
2. The initial route's `didPush` fires during the first frame, calling `track` while the native plugin is still initializing.
3. The first `[Amplitude] Screen Viewed` event is dropped with no error surfaced.
## Expected behavior
`track` (and the other event-emitting methods) should queue or await initialization, e.g. `await isBuilt;` before `invokeMethod`, so early events are delivered once init completes.
## Scope note
This is an SDK-wide race in `track`, not specific to any autocapture source; it affects manual `track` calls made early in app startup the same way. Filed separately from the widget tap autocapture PR (#317) on purpose since it is independent of that change.
Guide de contribution
Ouvrir le guide de contribution
Évaluation
Cette issue n'a pas encore été évaluée.