2023-12-21 09:14:40 +00:00
|
|
|
import 'package:guru_analytics_flutter/events_constants.dart';
|
|
|
|
|
import 'package:json_annotation/json_annotation.dart';
|
|
|
|
|
import 'package:guru_utils/converts/converts.dart';
|
|
|
|
|
|
|
|
|
|
/// Created by Haoyi on 2023/2/9
|
|
|
|
|
///
|
|
|
|
|
part 'analytics_model.g.dart';
|
|
|
|
|
|
|
|
|
|
@JsonSerializable()
|
|
|
|
|
class AnalyticsConfig {
|
2024-03-07 03:46:50 +00:00
|
|
|
static const _defaultGoogleDma = [1, 0, 12, 65];
|
|
|
|
|
static const _defaultDmaCountry = [];
|
2023-12-21 09:14:40 +00:00
|
|
|
@JsonKey(name: "cap", defaultValue: ["firebase", "facebook", "guru"])
|
|
|
|
|
@joinedStringConvert
|
|
|
|
|
final List<String> capabilities;
|
|
|
|
|
|
|
|
|
|
@JsonKey(name: "init_delay_s", defaultValue: 10)
|
|
|
|
|
final int delayedInSeconds;
|
|
|
|
|
|
|
|
|
|
@JsonKey(name: "expired_d", defaultValue: 7)
|
|
|
|
|
final int expiredInDays;
|
|
|
|
|
|
|
|
|
|
@JsonKey(name: "strategy", defaultValue: '')
|
|
|
|
|
final String strategy;
|
|
|
|
|
|
|
|
|
|
@JsonKey(name: "enabled_strategy", defaultValue: false)
|
|
|
|
|
final bool enabledStrategy;
|
|
|
|
|
|
2024-03-07 03:46:50 +00:00
|
|
|
/// ad_storage,analytics_storage,personalization,user_data
|
|
|
|
|
@JsonKey(name: "google_dma", defaultValue: _defaultGoogleDma)
|
|
|
|
|
final List<int> googleDmaMask;
|
|
|
|
|
|
|
|
|
|
@JsonKey(name: "dma_country", defaultValue: _defaultDmaCountry)
|
|
|
|
|
final List<String> dmaCountry;
|
|
|
|
|
|
2023-12-21 09:14:40 +00:00
|
|
|
AppEventCapabilities toAppEventCapabilities() {
|
|
|
|
|
int capValue = 0;
|
|
|
|
|
if (capabilities.contains("firebase")) {
|
|
|
|
|
capValue |= AppEventCapabilities.firebase;
|
|
|
|
|
}
|
|
|
|
|
if (capabilities.contains("facebook")) {
|
|
|
|
|
capValue |= AppEventCapabilities.facebook;
|
|
|
|
|
}
|
|
|
|
|
if (capabilities.contains("guru")) {
|
|
|
|
|
capValue |= AppEventCapabilities.guru;
|
|
|
|
|
}
|
|
|
|
|
return AppEventCapabilities(capValue);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-07 03:46:50 +00:00
|
|
|
bool googleDmaGranted(ConsentType type, int flags) {
|
|
|
|
|
if (type.index < googleDmaMask.length) {
|
|
|
|
|
return (googleDmaMask[type.index] & flags) == googleDmaMask[type.index];
|
|
|
|
|
}
|
|
|
|
|
return _defaultGoogleDma[type.index] & flags == _defaultGoogleDma[type.index];
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-21 09:14:40 +00:00
|
|
|
AnalyticsConfig(this.capabilities, this.delayedInSeconds, this.expiredInDays, this.strategy,
|
2024-03-07 03:46:50 +00:00
|
|
|
this.enabledStrategy, this.googleDmaMask, this.dmaCountry);
|
2023-12-21 09:14:40 +00:00
|
|
|
|
|
|
|
|
factory AnalyticsConfig.fromJson(Map<String, dynamic> json) => _$AnalyticsConfigFromJson(json);
|
|
|
|
|
|
|
|
|
|
Map<String, dynamic> toJson() => _$AnalyticsConfigToJson(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@JsonSerializable()
|
|
|
|
|
class UserIdentification {
|
|
|
|
|
@JsonKey(name: 'firebaseAppInstanceId', defaultValue: "")
|
|
|
|
|
final String firebaseAppInstanceId;
|
|
|
|
|
|
|
|
|
|
@JsonKey(name: 'idfa')
|
|
|
|
|
final String? idfa;
|
|
|
|
|
|
|
|
|
|
@JsonKey(name: "adid")
|
|
|
|
|
final String? adId;
|
|
|
|
|
|
|
|
|
|
@JsonKey(name: "gpsAdid")
|
|
|
|
|
final String? gpsAdId;
|
|
|
|
|
|
|
|
|
|
UserIdentification({this.firebaseAppInstanceId = '', this.idfa, this.adId, this.gpsAdId});
|
|
|
|
|
|
|
|
|
|
factory UserIdentification.fromJson(Map<String, dynamic> json) =>
|
|
|
|
|
_$UserIdentificationFromJson(json);
|
|
|
|
|
|
|
|
|
|
Map<String, dynamic> toJson() => _$UserIdentificationToJson(this);
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String toString() {
|
|
|
|
|
return 'UserIdentification{firebaseAppInstanceId: $firebaseAppInstanceId, idfa: $idfa, adId: $adId, gpsAdId: $gpsAdId}';
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-07 03:46:50 +00:00
|
|
|
|
|
|
|
|
class ConsentFieldName {
|
|
|
|
|
static const adStorage = "ad_storage";
|
|
|
|
|
static const analyticsStorage = "analytics_storage";
|
|
|
|
|
static const adPersonalization = "ad_personalization";
|
|
|
|
|
static const adUserData = "ad_user_data";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum ConsentType { adStorage, analyticsStorage, adPersonalization, adUserData }
|