Initial commit: 91dj android client dev_1.0.0
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
import 'package:analytics_sdk/manager/page_name_manager.dart';
|
||||
import 'package:analytics_sdk/const/event_type.dart';
|
||||
import 'package:analytics_sdk/manager/sdk_context.dart';
|
||||
|
||||
/// 广告展示日志 (手动)
|
||||
/// 展示上报逻辑:
|
||||
/// 1. 进入 APP → TabA
|
||||
/// - 20 条曝光 → 上报 20 条(批量)
|
||||
/// 2. 切换到TabB
|
||||
/// - 20 条曝光 → 上报 20 条
|
||||
/// 3. 返回TabA → 上滑加载 10 条
|
||||
/// - 新 10 条渲染出来 → 上报 10 条
|
||||
/// 4. 用户再次上下滑动TabA
|
||||
/// - 所有广告已曝光,无需再上报
|
||||
|
||||
class AdImpressionEvent {
|
||||
final String event = EventType.adImpression.event;
|
||||
late final String eventId;
|
||||
|
||||
/// 页面唯一标识,建议使用 [AppPageEnum](如 `AppPageEnum.home.key`),
|
||||
/// 也可传入自定义字符串。
|
||||
final String pageKey;
|
||||
|
||||
/// 页面展示名称,建议与 [pageKey] 保持对应(如 `AppPageEnum.home.name`)。
|
||||
final String pageName;
|
||||
|
||||
/// 广告位标识:如 home_banner_1等 对应广告导入数据的advertiseLocationCode
|
||||
final String adSlotKey;
|
||||
|
||||
/// 本次广告请求唯一 ID。
|
||||
final String requestId;
|
||||
|
||||
/// 广告ID, 多个广告ID英文逗号分隔 对应广告导入数据的advertiseCode
|
||||
final String adId;
|
||||
|
||||
/// 实际素材尺寸,格式如 "1080x1920"。
|
||||
final String materialSize;
|
||||
|
||||
/// 素材ID(可选)多个素材ID英文逗号分隔,和广告ID一一对应,没有的填充空字符串
|
||||
final String creativeId;
|
||||
|
||||
/// 广告类型字符串,如 banner, feed, interstitial, reward_video 等,由广告中心定义
|
||||
final String adType;
|
||||
|
||||
late final Map<String, dynamic> _commonFields;
|
||||
|
||||
AdImpressionEvent({
|
||||
required String pageKey,
|
||||
required this.pageName,
|
||||
required this.adSlotKey,
|
||||
this.requestId = '',
|
||||
required this.adId,
|
||||
this.materialSize = '',
|
||||
this.creativeId = '',
|
||||
this.adType = '',
|
||||
}) : pageKey = PageNameMapper.normalizeKey(pageKey) {
|
||||
_commonFields = SdkContext.generateCommonFields(event);
|
||||
|
||||
eventId = SdkContext.generateEventIdFromCommonFields(_commonFields, [
|
||||
pageKey,
|
||||
pageName,
|
||||
adSlotKey,
|
||||
requestId,
|
||||
adId,
|
||||
adType,
|
||||
materialSize,
|
||||
creativeId,
|
||||
]);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
Map<String, dynamic> payload = {
|
||||
'page_key': pageKey,
|
||||
'page_name': pageName,
|
||||
'request_id': requestId,
|
||||
'ad_slot_key': adSlotKey,
|
||||
'ad_id': adId,
|
||||
'ad_type': adType,
|
||||
'material_size': materialSize,
|
||||
'creative_id': creativeId,
|
||||
};
|
||||
return {..._commonFields, 'event_id': eventId, "payload": payload};
|
||||
}
|
||||
|
||||
factory AdImpressionEvent.fromJson(Map<String, dynamic> json) {
|
||||
return AdImpressionEvent(
|
||||
pageKey: json['page_key'] as String,
|
||||
pageName: json['page_name'] as String,
|
||||
adSlotKey: json['ad_slot_key'] as String,
|
||||
requestId: json['request_id'] as String? ?? '',
|
||||
adId: json['ad_id'] as String,
|
||||
materialSize: json['material_size'] as String? ?? '',
|
||||
creativeId: json['creative_id'] as String? ?? '',
|
||||
adType: json['ad_type'] as String? ?? '',
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user