yx_tracking_flutter/lib/yx_tracking_flutter.dart

72 lines
2.2 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'dart:async';
import 'src/config/analytics_config.dart';
import 'src/core/analytics_core.dart';
import 'src/core/interceptors.dart';
import 'src/model/device_info.dart';
import 'src/model/recent_event_summary.dart';
import 'src/model/user_info.dart';
export 'src/config/analytics_config.dart';
export 'src/core/interceptors.dart';
export 'src/model/device_info.dart';
export 'src/model/event.dart';
export 'src/model/recent_event_summary.dart';
export 'src/model/user_info.dart';
/// 对外唯一入口Facade
class Analytics {
Analytics._();
static final AnalyticsCore _core = AnalyticsCore();
static Future<void> init(AnalyticsConfig config) => _core.init(config);
static Future<void> track(
String eventType, {
Map<String, dynamic>? eventParams,
Map<String, dynamic>? customTags,
int? timestamp,
}) {
return _core.track(
eventType,
eventParams: eventParams,
customTags: customTags,
timestamp: timestamp,
);
}
static Future<void> setUser(UserInfo? userInfo) => _core.setUser(userInfo);
static Future<void> setDeviceInfo(DeviceInfo deviceInfo) =>
_core.setDeviceInfo(deviceInfo);
static Future<void> flush({bool force = false}) => _core.flush(force: force);
/// 当前本地缓存事件数量(用于调试/演示)。
static Future<int> cachedEventCount() => _core.cachedEventCount();
/// 最近事件摘要(用于调试面板)。
static Future<List<RecentEventSummary>> cachedRecentEvents({int limit = 20}) =>
_core.cachedRecentEvents(limit: limit);
/// Phase 2手动触发一次配置刷新默认强制刷新
static Future<void> refreshConfig({bool force = true}) =>
_core.refreshConfig(force: force);
/// Phase 3立即上报一次 SDK 指标(调试/测试用)。
static Future<void> reportMetricsNow() => _core.reportMetricsNow();
/// Phase 3注册事件拦截器。
static void addInterceptor(AnalyticsInterceptor interceptor) {
_core.addInterceptor(interceptor);
}
static void setDebug(bool enabled) {
unawaited(_core.setDebug(enabled));
}
/// 可选:当宿主确定不再需要 SDK 时调用。
static Future<void> dispose() => _core.dispose();
}