parseRawConsentInfo function
Create BasicConsentInfo from the raw consent information, which is made available by an CMP SDK.
Implementation
BasicConsentInfo? parseRawConsentInfo(Map<String, dynamic> raw) {
final sdkId = raw[_cmpSdkIDKey] as int?;
// The sdk id should be set as early as possible by the CMP sdk to
// signal its existence.
// https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/TCFv2/IAB%20Tech%20Lab%20-%20CMP%20API%20v2.md#in-app-details
if (sdkId == null) {
return null;
}
final sdkVersion = raw[_cmpSdkVersionKey] as int?;
final policyVersion = raw[_policyVersionKey] as int?;
final gdprApplies = (raw[_gdprAppliesKey] as int?)?.let(_parseNumberAsBool);
if (gdprApplies != true) {
return BasicConsentInfo(
raw: raw,
sdkId: sdkId,
sdkVersion: sdkVersion,
policyVersion: policyVersion,
gdprApplies: gdprApplies,
);
}
List<DataUsagePurpose> parseDataUsagePurposes(Object? info) =>
(info as String?)?.let(_parseDataUsagePurposeBinaryString) ?? [];
return ConsentInfo(
raw: raw,
sdkId: sdkId,
sdkVersion: sdkVersion,
policyVersion: policyVersion,
gdprApplies: true,
purposeConsents: parseDataUsagePurposes(raw[_purposeConsentsKey]),
purposeLegitimateInterests:
parseDataUsagePurposes(raw[_purposeLegitimateInterestsKey]),
publisherConsents: parseDataUsagePurposes(raw[_publisherConsentKey]),
publisherLegitimateInterests:
parseDataUsagePurposes(raw[_publisherLegitimateInterestKey]),
);
}