@@ -387,36 +387,35 @@ - (MPKitExecStatus *)setConsentState:(nullable MPConsentState *)state {
387
387
return [self execStatus: MPKitReturnCodeSuccess];
388
388
}
389
389
390
- - (void ) updateConsent {
391
- NSArray <NSDictionary *> *mappings = [self mappingForKey: @" consentMappingSDK" ];
390
+ - (NSDictionary <NSString *, NSString *> *) consentDictionaryForCurrentUser {
391
+ NSArray <NSDictionary *> *mappings = [self mappingForKey: @" consentMappingSDK" ];
392
392
NSDictionary <NSString *, NSString *> *mappingsConfig;
393
393
if (mappings != nil ) {
394
- mappingsConfig = [self convertToKeyValuePairs: mappings];
394
+ mappingsConfig = [self convertToKeyValuePairs: mappings];
395
395
}
396
-
397
-
396
+
398
397
MParticleUser *currentUser = [[[MParticle sharedInstance ] identity ] currentUser ];
399
398
NSDictionary <NSString *, MPGDPRConsent *> *gdprConsents = currentUser.consentState .gdprConsentState ;
400
399
401
400
NSNumber *adStorage = [self resolvedConsentForMappingKey: kMPFIRGA4AdStorageKey
402
401
defaultKey: kMPFIRGA4DefaultAdStorageKey
403
402
gdprConsents: gdprConsents
404
- mapping: mappingsConfig];
403
+ mapping: mappingsConfig];
405
404
406
405
NSNumber *adUserData = [self resolvedConsentForMappingKey: kMPFIRGA4AdUserDataKey
407
406
defaultKey: kMPFIRGA4DefaultAdUserDataKey
408
407
gdprConsents: gdprConsents
409
- mapping: mappingsConfig];
408
+ mapping: mappingsConfig];
410
409
411
410
NSNumber *analyticsStorage = [self resolvedConsentForMappingKey: kMPFIRGA4AnalyticsStorageKey
412
411
defaultKey: kMPFIRGA4DefaultAnalyticsStorageKey
413
412
gdprConsents: gdprConsents
414
- mapping: mappingsConfig];
413
+ mapping: mappingsConfig];
415
414
416
415
NSNumber *adPersonalization = [self resolvedConsentForMappingKey: kMPFIRGA4AdPersonalizationKey
417
416
defaultKey: kMPFIRGA4DefaultAdPersonalizationKey
418
417
gdprConsents: gdprConsents
419
- mapping: mappingsConfig];
418
+ mapping: mappingsConfig];
420
419
421
420
NSMutableDictionary *uploadDict = [NSMutableDictionary dictionary ];
422
421
@@ -432,12 +431,16 @@ - (void)updateConsent {
432
431
if (adPersonalization != nil ) {
433
432
uploadDict[FIRConsentTypeAdPersonalization] = adPersonalization.boolValue ? FIRConsentStatusGranted : FIRConsentStatusDenied;
434
433
}
435
-
436
-
437
- // Update consent state with FIRAnalytics
438
- [FIRAnalytics setConsent: uploadDict];
434
+
435
+ return uploadDict;
439
436
}
440
437
438
+ - (void )updateConsent {
439
+ NSDictionary *consentDict = [self consentDictionaryForCurrentUser ];
440
+ [FIRAnalytics setConsent: consentDict];
441
+ }
442
+
443
+
441
444
- (NSString *)getEventNameForCommerceEvent : (MPCommerceEvent *)commerceEvent parameters : (NSDictionary <NSString *, id> *)parameters {
442
445
switch (commerceEvent.action ) {
443
446
case MPCommerceEventActionAddToCart:
@@ -673,16 +676,24 @@ - (NSNumber * _Nullable)resolvedConsentForMappingKey:(NSString *)mappingKey
673
676
gdprConsents : (NSDictionary <NSString *, MPGDPRConsent *> *)gdprConsents
674
677
mapping : (NSDictionary <NSString *, NSString*> *) mapping {
675
678
676
- // Prefer mParticle Consent if available
677
679
NSString *purpose = mapping[mappingKey];
678
- if (purpose) {
679
- MPGDPRConsent *consent = gdprConsents[purpose];
680
- if (consent) {
681
- return @(consent.consented );
682
- }
680
+ NSNumber *consent = [self resolvedConsentForPurpose: purpose gdprConsents: gdprConsents];
681
+ if (consent) {
682
+ return consent;
683
683
}
684
+ return [self resolvedConsentFromDefault: defaultKey];
685
+ }
686
+
687
+ - (NSNumber * _Nullable)resolvedConsentForPurpose : (NSString *)purpose
688
+ gdprConsents : (NSDictionary <NSString *, MPGDPRConsent *> *)gdprConsents {
689
+ MPGDPRConsent *consent = gdprConsents[purpose];
690
+ if (consent) {
691
+ return @(consent.consented );
692
+ }
693
+ return nil ;
694
+ }
684
695
685
- // Fallback to configuration defaults
696
+ - ( NSNumber * _Nullable) resolvedConsentFromDefault : ( NSString *) defaultKey {
686
697
NSString *value = self->_configuration [defaultKey];
687
698
if ([value isEqualToString: @" Granted" ]) {
688
699
return @(YES );
0 commit comments