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,459 @@
|
||||
import 'package:analytics_sdk/const/event_type.dart';
|
||||
import 'package:analytics_sdk/manager/sdk_context.dart';
|
||||
|
||||
abstract class _AdSdkEvent {
|
||||
final String event;
|
||||
|
||||
late final String eventId;
|
||||
late final Map<String, dynamic> _commonFields;
|
||||
|
||||
_AdSdkEvent(this.event, List<String> eventIdFields) {
|
||||
_commonFields = SdkContext.generateCommonFields(event);
|
||||
eventId = SdkContext.generateEventIdFromCommonFields(
|
||||
_commonFields,
|
||||
eventIdFields,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> buildPayload();
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
..._commonFields,
|
||||
'event_id': eventId,
|
||||
'payload': buildPayload(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// 广告 SDK 初始化事件。
|
||||
class AdSdkInitEvent extends _AdSdkEvent {
|
||||
final int screenWidth;
|
||||
final int screenHeight;
|
||||
final int screenDpi;
|
||||
final String orientation;
|
||||
final String networkType;
|
||||
final String carrier;
|
||||
final String language;
|
||||
final String timezone;
|
||||
final String oaid;
|
||||
final String androidId;
|
||||
final String idfv;
|
||||
final String idfa;
|
||||
final bool lat;
|
||||
final String adSdkVersion;
|
||||
final int availableStorage;
|
||||
final int batteryLevel;
|
||||
final String cpu;
|
||||
final int storage;
|
||||
final String activationTime;
|
||||
|
||||
AdSdkInitEvent({
|
||||
this.screenWidth = 0,
|
||||
this.screenHeight = 0,
|
||||
this.screenDpi = 0,
|
||||
this.orientation = '',
|
||||
this.networkType = '',
|
||||
this.carrier = '',
|
||||
this.language = '',
|
||||
this.timezone = '',
|
||||
this.oaid = '',
|
||||
this.androidId = '',
|
||||
this.idfv = '',
|
||||
this.idfa = '',
|
||||
this.lat = false,
|
||||
required this.adSdkVersion,
|
||||
this.availableStorage = 0,
|
||||
this.batteryLevel = 0,
|
||||
this.cpu = '',
|
||||
this.storage = 0,
|
||||
this.activationTime = '',
|
||||
}) : super(EventType.adSdkInit.event, [
|
||||
screenWidth.toString(),
|
||||
screenHeight.toString(),
|
||||
screenDpi.toString(),
|
||||
orientation,
|
||||
networkType,
|
||||
carrier,
|
||||
language,
|
||||
timezone,
|
||||
oaid,
|
||||
androidId,
|
||||
idfv,
|
||||
idfa,
|
||||
lat.toString(),
|
||||
adSdkVersion,
|
||||
availableStorage.toString(),
|
||||
batteryLevel.toString(),
|
||||
cpu,
|
||||
storage.toString(),
|
||||
activationTime,
|
||||
]);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> buildPayload() => {
|
||||
'screen_width': screenWidth,
|
||||
'screen_height': screenHeight,
|
||||
'screen_dpi': screenDpi,
|
||||
'orientation': orientation,
|
||||
'network_type': networkType,
|
||||
'carrier': carrier,
|
||||
'language': language,
|
||||
'timezone': timezone,
|
||||
'oaid': oaid,
|
||||
'android_id': androidId,
|
||||
'idfv': idfv,
|
||||
'idfa': idfa,
|
||||
'lat': lat,
|
||||
'ad_sdk_version': adSdkVersion,
|
||||
'available_storage': availableStorage,
|
||||
'battery_level': batteryLevel,
|
||||
'cpu': cpu,
|
||||
'storage': storage,
|
||||
'activation_time': activationTime,
|
||||
};
|
||||
}
|
||||
|
||||
/// 广告请求事件。
|
||||
class AdRequestEvent extends _AdSdkEvent {
|
||||
final String requestId;
|
||||
final String adSlotKey;
|
||||
final String adType;
|
||||
final String? adId;
|
||||
|
||||
AdRequestEvent({
|
||||
required this.requestId,
|
||||
required this.adSlotKey,
|
||||
this.adType = '',
|
||||
this.adId,
|
||||
}) : super(EventType.adRequest.event, [
|
||||
requestId,
|
||||
adSlotKey,
|
||||
adType,
|
||||
adId ?? '',
|
||||
]);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> buildPayload() => {
|
||||
'request_id': requestId,
|
||||
'ad_slot_key': adSlotKey,
|
||||
'ad_type': adType,
|
||||
if (adId?.trim().isNotEmpty ?? false) 'ad_id': adId!.trim(),
|
||||
};
|
||||
}
|
||||
|
||||
/// 广告填充成功事件。
|
||||
class AdFillEvent extends _AdSdkEvent {
|
||||
final String traceId;
|
||||
final String requestId;
|
||||
final String adSlotKey;
|
||||
final String adId;
|
||||
final String adType;
|
||||
final int fillCount;
|
||||
|
||||
AdFillEvent({
|
||||
this.traceId = '',
|
||||
required this.requestId,
|
||||
required this.adSlotKey,
|
||||
required this.adId,
|
||||
required this.adType,
|
||||
required this.fillCount,
|
||||
}) : super(EventType.adFill.event, [
|
||||
if (traceId.isNotEmpty) traceId,
|
||||
requestId,
|
||||
adSlotKey,
|
||||
adId,
|
||||
adType,
|
||||
fillCount.toString(),
|
||||
]);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> buildPayload() => {
|
||||
'trace_id': traceId,
|
||||
'request_id': requestId,
|
||||
'ad_slot_key': adSlotKey,
|
||||
'ad_id': adId,
|
||||
'ad_type': adType,
|
||||
'fill_count': fillCount,
|
||||
};
|
||||
}
|
||||
|
||||
/// 广告无填充事件。
|
||||
class AdNoFillEvent extends _AdSdkEvent {
|
||||
final String requestId;
|
||||
final String adSlotKey;
|
||||
final String adType;
|
||||
final String reason;
|
||||
|
||||
AdNoFillEvent({
|
||||
required this.requestId,
|
||||
required this.adSlotKey,
|
||||
required this.adType,
|
||||
required this.reason,
|
||||
}) : super(EventType.adNoFill.event, [requestId, adSlotKey, adType, reason]);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> buildPayload() => {
|
||||
'request_id': requestId,
|
||||
'ad_slot_key': adSlotKey,
|
||||
'ad_type': adType,
|
||||
'reason': reason,
|
||||
};
|
||||
}
|
||||
|
||||
/// 广告素材加载成功事件。
|
||||
class AdLoadSuccessEvent extends _AdSdkEvent {
|
||||
final String traceId;
|
||||
final String requestId;
|
||||
final String adSlotKey;
|
||||
final String adId;
|
||||
final String adType;
|
||||
final int loadDuration;
|
||||
|
||||
AdLoadSuccessEvent({
|
||||
this.traceId = '',
|
||||
required this.requestId,
|
||||
required this.adSlotKey,
|
||||
required this.adId,
|
||||
required this.adType,
|
||||
required this.loadDuration,
|
||||
}) : super(EventType.adLoadSuccess.event, [
|
||||
if (traceId.isNotEmpty) traceId,
|
||||
requestId,
|
||||
adSlotKey,
|
||||
adId,
|
||||
adType,
|
||||
loadDuration.toString(),
|
||||
]);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> buildPayload() => {
|
||||
'trace_id': traceId,
|
||||
'request_id': requestId,
|
||||
'ad_slot_key': adSlotKey,
|
||||
'ad_id': adId,
|
||||
'ad_type': adType,
|
||||
'load_duration': loadDuration,
|
||||
};
|
||||
}
|
||||
|
||||
/// 广告素材加载失败事件。
|
||||
@Deprecated('ad_load_fail 已并入 ad_error,使用 MATERIAL_LOAD_FAIL 错误码。')
|
||||
class AdLoadFailEvent extends _AdSdkEvent {
|
||||
final String traceId;
|
||||
final String requestId;
|
||||
final String adSlotKey;
|
||||
final String adId;
|
||||
final String adType;
|
||||
final String errorCode;
|
||||
|
||||
AdLoadFailEvent({
|
||||
this.traceId = '',
|
||||
required this.requestId,
|
||||
required this.adSlotKey,
|
||||
required this.adId,
|
||||
required this.adType,
|
||||
required this.errorCode,
|
||||
}) : super(EventType.adLoadFail.event, [
|
||||
if (traceId.isNotEmpty) traceId,
|
||||
requestId,
|
||||
adSlotKey,
|
||||
adId,
|
||||
adType,
|
||||
errorCode,
|
||||
]);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> buildPayload() => {
|
||||
'trace_id': traceId,
|
||||
'request_id': requestId,
|
||||
'ad_slot_key': adSlotKey,
|
||||
'ad_id': adId,
|
||||
'ad_type': adType,
|
||||
'error_code': errorCode,
|
||||
};
|
||||
}
|
||||
|
||||
/// 广告 SDK 曝光事件。
|
||||
class AdImpressionSdkEvent extends _AdSdkEvent {
|
||||
final String traceId;
|
||||
final String requestId;
|
||||
final String adSlotKey;
|
||||
final String adId;
|
||||
final String adType;
|
||||
final String materialSize;
|
||||
|
||||
AdImpressionSdkEvent({
|
||||
this.traceId = '',
|
||||
required this.requestId,
|
||||
required this.adSlotKey,
|
||||
required this.adId,
|
||||
required this.adType,
|
||||
required this.materialSize,
|
||||
}) : super(EventType.adImpressionSdk.event, [
|
||||
traceId,
|
||||
requestId,
|
||||
adSlotKey,
|
||||
adId,
|
||||
adType,
|
||||
materialSize,
|
||||
]);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> buildPayload() => {
|
||||
'trace_id': traceId,
|
||||
'request_id': requestId,
|
||||
'ad_slot_key': adSlotKey,
|
||||
'ad_id': adId,
|
||||
'ad_type': adType,
|
||||
'material_size': materialSize,
|
||||
};
|
||||
}
|
||||
|
||||
/// 广告 SDK 点击事件。
|
||||
class AdClickSdkEvent extends _AdSdkEvent {
|
||||
final String traceId;
|
||||
final String requestId;
|
||||
final String adSlotKey;
|
||||
final String adId;
|
||||
final String adType;
|
||||
|
||||
AdClickSdkEvent({
|
||||
this.traceId = '',
|
||||
required this.requestId,
|
||||
required this.adSlotKey,
|
||||
required this.adId,
|
||||
required this.adType,
|
||||
}) : super(EventType.adClickSdk.event, [
|
||||
traceId,
|
||||
requestId,
|
||||
adSlotKey,
|
||||
adId,
|
||||
adType,
|
||||
]);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> buildPayload() => {
|
||||
'trace_id': traceId,
|
||||
'request_id': requestId,
|
||||
'ad_slot_key': adSlotKey,
|
||||
'ad_id': adId,
|
||||
'ad_type': adType,
|
||||
};
|
||||
}
|
||||
|
||||
/// 广告关闭事件。
|
||||
class AdCloseEvent extends _AdSdkEvent {
|
||||
final String traceId;
|
||||
final String requestId;
|
||||
final String adSlotKey;
|
||||
final String adId;
|
||||
final String adType;
|
||||
final String closeType;
|
||||
final int shownDuration;
|
||||
|
||||
AdCloseEvent({
|
||||
this.traceId = '',
|
||||
required this.requestId,
|
||||
required this.adSlotKey,
|
||||
required this.adId,
|
||||
required this.adType,
|
||||
required this.closeType,
|
||||
this.shownDuration = 0,
|
||||
}) : super(EventType.adClose.event, [
|
||||
if (traceId.isNotEmpty) traceId,
|
||||
requestId,
|
||||
adSlotKey,
|
||||
adId,
|
||||
adType,
|
||||
closeType,
|
||||
shownDuration.toString(),
|
||||
]);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> buildPayload() => {
|
||||
'trace_id': traceId,
|
||||
'request_id': requestId,
|
||||
'ad_slot_key': adSlotKey,
|
||||
'ad_id': adId,
|
||||
'ad_type': adType,
|
||||
'close_type': closeType,
|
||||
'shown_duration': shownDuration,
|
||||
};
|
||||
}
|
||||
|
||||
/// 广告跳过事件。
|
||||
class AdSkipEvent extends _AdSdkEvent {
|
||||
final String traceId;
|
||||
final String requestId;
|
||||
final String adSlotKey;
|
||||
final String adId;
|
||||
final String adType;
|
||||
final int shownDuration;
|
||||
|
||||
AdSkipEvent({
|
||||
this.traceId = '',
|
||||
required this.requestId,
|
||||
required this.adSlotKey,
|
||||
required this.adId,
|
||||
required this.adType,
|
||||
this.shownDuration = 0,
|
||||
}) : super(EventType.adSkip.event, [
|
||||
if (traceId.isNotEmpty) traceId,
|
||||
requestId,
|
||||
adSlotKey,
|
||||
adId,
|
||||
adType,
|
||||
shownDuration.toString(),
|
||||
]);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> buildPayload() => {
|
||||
'trace_id': traceId,
|
||||
'request_id': requestId,
|
||||
'ad_slot_key': adSlotKey,
|
||||
'ad_id': adId,
|
||||
'ad_type': adType,
|
||||
'shown_duration': shownDuration,
|
||||
};
|
||||
}
|
||||
|
||||
/// 广告错误事件。
|
||||
class AdErrorEvent extends _AdSdkEvent {
|
||||
final String traceId;
|
||||
final String requestId;
|
||||
final String adSlotKey;
|
||||
final String adType;
|
||||
final String errorCode;
|
||||
final String errorMsg;
|
||||
final String errorStage;
|
||||
|
||||
AdErrorEvent({
|
||||
this.traceId = '',
|
||||
this.requestId = '',
|
||||
required this.adSlotKey,
|
||||
required this.adType,
|
||||
required this.errorCode,
|
||||
required this.errorMsg,
|
||||
required this.errorStage,
|
||||
}) : super(EventType.adError.event, [
|
||||
if (traceId.isNotEmpty) traceId,
|
||||
requestId,
|
||||
adSlotKey,
|
||||
adType,
|
||||
errorCode,
|
||||
errorMsg,
|
||||
errorStage,
|
||||
]);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> buildPayload() => {
|
||||
'trace_id': traceId,
|
||||
'request_id': requestId,
|
||||
'ad_slot_key': adSlotKey,
|
||||
'ad_type': adType,
|
||||
'error_code': errorCode,
|
||||
'error_msg': errorMsg,
|
||||
'error_stage': errorStage,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user