docs: Sync documentation with codebase and fix bugs
Flutter CI / analyze-and-test (push) Has been cancelled Details

- Fix README.md duplicate ')' syntax error
- Fix IsolateEventStorage response format (add missing id/ok fields)
- Update todo list with Isolate storage and lifecycle features
- Add maxEventAge config explanation to design doc
- Update lifecycle description in overview doc
This commit is contained in:
Max 2026-01-28 12:21:28 +08:00
parent 61f07c500a
commit 14161727d5
6 changed files with 20 additions and 7 deletions

View File

@ -133,8 +133,8 @@ SDK 内部统一分层:
- `Timer.periodic` 实现定时 flush - `Timer.periodic` 实现定时 flush
- 控制并发:用一个「上传中」标志避免并发多次 flush - 控制并发:用一个「上传中」标志避免并发多次 flush
- 生命周期: - 生命周期:
- SDK 暴露 `flush()` - SDK 已实现 `Analytics.bindLifecycleObserver()`,自动在后台/销毁时 flush
- 应用可在自身生命周期(如 `WidgetsBindingObserver` 或 Router中调用 - 应用也可手动调用 `flush()`
## 3.2 Android SDK ## 3.2 Android SDK

View File

@ -74,6 +74,10 @@ class Analytics {
static Future<void> flush(); static Future<void> flush();
// Phase 1: Lifecycle
static void bindLifecycleObserver({bool flushOnBackground = true, bool flushOnDetached = true});
static void unbindLifecycleObserver();
static void setDebug(bool enabled); static void setDebug(bool enabled);
// Phase 3 // Phase 3
@ -109,6 +113,8 @@ class AnalyticsConfig {
this.maxRetryCount = 3, this.maxRetryCount = 3,
this.connectTimeout = const Duration(seconds: 5), this.connectTimeout = const Duration(seconds: 5),
this.readTimeout = const Duration(seconds: 5), this.readTimeout = const Duration(seconds: 5),
this.useIsolateStorage = true, // 默认开启 Isolate
this.maxEventAge = const Duration(days: 7), // 事件过期时间
}); });
} }
``` ```
@ -137,6 +143,7 @@ lib/
storage/ storage/
event_storage.dart // 抽象接口 event_storage.dart // 抽象接口
sqflite_event_storage.dart // SQLite 实现 sqflite_event_storage.dart // SQLite 实现
isolate_event_storage.dart // (New) Isolate 异步存储包装
network/ network/
api_client.dart // 与后端 API 通信 api_client.dart // 与后端 API 通信

View File

@ -42,7 +42,7 @@
- [x] 实现 `track` 主流程构造事件、入库、trim、达到 batchSize 触发 flush - [x] 实现 `track` 主流程构造事件、入库、trim、达到 batchSize 触发 flush
- [x] 实现 `flush`(互斥、防并发、批量发送、重试与退避) - [x] 实现 `flush`(互斥、防并发、批量发送、重试与退避)
- [x] 稳定性增强(重试退避、异常兜底、坏数据清理) - [x] 稳定性增强(重试退避、异常兜底、坏数据清理)
- [x] Phase 2 已接入ConfigManager、Validator、配置周期刷新、release 校验标记) - [x] Phase 2 已接入ConfigManager、Validator、配置周期刷新、release 校验标记)\n- [x] 实现 `IsolateEventStorage`(默认启用,后台 Isolate 执行 IO\n- [x] 实现生命周期监听(`bindLifecycleObserver`,后台/销毁时自动 flush
### 5. Facade 对外接口company_analytics.dart ### 5. Facade 对外接口company_analytics.dart

View File

@ -11,7 +11,8 @@
## 功能特性 ## 功能特性
- 统一事件模型自动补齐公共字段systemCode、deviceInfo、时间戳等 - 统一事件模型自动补齐公共字段systemCode、deviceInfo、时间戳等
- 本地持久化队列sqflite断网可缓存恢复后补发 - 本地持久化队列sqflite默认运行在独立 Isolate 中,避免阻塞 UI
- 应用生命周期监听(进入后台/销毁时自动 flush
- 批量上报 + 重试退避 + 队列上限裁剪 - 批量上报 + 重试退避 + 队列上限裁剪
- 配置下发(`GetSystemAllDimInfo`)与本地缓存 - 配置下发(`GetSystemAllDimInfo`)与本地缓存
- 事件校验Debug 详细日志Release 自动标记 `_sdk_*` - 事件校验Debug 详细日志Release 自动标记 `_sdk_*`
@ -35,6 +36,9 @@ Future<void> bootstrapAnalytics() async {
enableDebug: true, enableDebug: true,
), ),
); );
// 注册生命周期监听(推荐)
Analytics.bindLifecycleObserver();
} }
``` ```
@ -57,7 +61,7 @@ await Analytics.flush(force: true);
## 关键配置项AnalyticsConfig ## 关键配置项AnalyticsConfig
除了文档中的 Phase 1 配置项,还新增了以下能力配置: 除了文档中的 Phase 1 配置项,还新增了以下能力配置:
- `useIsolateStorage`: 是否使用 Isolate 进行存储操作(默认 `true`,强烈建议开启)
- `enableMetrics`:是否启用 SDK 自监控指标(默认 `true` - `enableMetrics`:是否启用 SDK 自监控指标(默认 `true`
- `metricsReportInterval`:指标上报周期(默认 10 分钟) - `metricsReportInterval`:指标上报周期(默认 10 分钟)
- `blockOnValidationError`Debug 下遇到校验 error 是否阻断发送(默认 `false` - `blockOnValidationError`Debug 下遇到校验 error 是否阻断发送(默认 `false`

View File

@ -4,5 +4,3 @@ analyzer:
exclude: exclude:
- coverage/** - coverage/**
# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options

View File

@ -327,6 +327,8 @@ Future<void> _storageWorkerEntry(_WorkerInit init) async {
} }
await storage.deleteByIds(ids.cast<int>()); await storage.deleteByIds(ids.cast<int>());
init.responsePort.send(<String, Object?>{ init.responsePort.send(<String, Object?>{
'id': id,
'ok': true,
'result': null, 'result': null,
}); });
case _msgCount: case _msgCount:
@ -368,6 +370,8 @@ Future<void> _storageWorkerEntry(_WorkerInit init) async {
} }
await storage.updateRetryCount(idValue, retry); await storage.updateRetryCount(idValue, retry);
init.responsePort.send(<String, Object?>{ init.responsePort.send(<String, Object?>{
'id': id,
'ok': true,
'result': null, 'result': null,
}); });
case _msgDispose: case _msgDispose: