amplitude / amplitude/Amplitude-Flutter
Amplitude.track does not await isBuilt: events tracked before init (e.g. first screen view) are silently dropped
- Linguagem predominante
- Dart
- Estrelas
- 133
- Forks
- 109
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Descrição
## 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.
Guia de contribuição
Direção de pesquisa
Start in lib/amplitude.dart, especially track and the isBuilt value set from _init() in the constructor. Reproduce with Amplitude(Configuration(...)) plus an AmplitudeNavigatorObserver so the initial didPush calls track before init completes. Done means track and the other event-emitting methods do not invoke the platform channel until initialization has completed, so early events are delivered.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- dart, flutter
- Domínio
- mobile
- Tipo de issue
- Bug
- Dificuldade
- 3/5
- Tempo estimado
- Meio dia
- Status de atividade
- Pouca atividade
- Clareza
- Claramente especificada
- Facilidade para iniciantes
- 52/100