2727NSString *const kMPAFAdPersonalizationKey = @" ad_personalization" ;
2828
2929// Default Consent Keys (from mParticle UI)
30- NSString *const kMPAFDefaultAdStorageKey = @" defaultAdStorageConsentSDK " ;
31- NSString *const kMPAFDefaultAdUserDataKey = @" defaultAdUserDataConsentSDK " ;
32- NSString *const kMPAFDefaultAdPersonalizationKey = @" defaultAdPersonalizationConsentSDK " ;
30+ NSString *const kMPAFDefaultAdStorageKey = @" defaultAdStorageConsent " ;
31+ NSString *const kMPAFDefaultAdUserDataKey = @" defaultAdUserDataConsent " ;
32+ NSString *const kMPAFDefaultAdPersonalizationKey = @" defaultAdPersonalizationConsent " ;
3333
3434static AppsFlyerLib *appsFlyerTracker = nil ;
3535static id <AppsFlyerLibDelegate> temporaryDelegate = nil ;
@@ -457,40 +457,55 @@ - (MPKitExecStatus *)setConsentState:(nullable MPConsentState *)state {
457457
458458- (void )updateConsent {
459459 BOOL isUserSubjectToGDPR = NO ;
460+
461+ NSString *gdprValue = _configuration[@" gdprApplies" ];
462+ if ([gdprValue isKindOfClass: [NSString class ]]) {
463+ isUserSubjectToGDPR = [gdprValue boolValue ];
464+ }
465+
460466 MParticleUser *currentUser = [[[MParticle sharedInstance ] identity ] currentUser ];
461467 NSDictionary <NSString *, MPGDPRConsent *> *gdprConsents = currentUser.consentState .gdprConsentState ;
462468
463469 if (gdprConsents.count > 0 ) {
464470 isUserSubjectToGDPR = YES ;
465471 }
466472
467- NSNumber *dataUsage = [self resolvedConsentForKey :kMPAFAdUserDataKey gdprConsents: gdprConsents];
468- NSNumber *personalization = [ self resolvedConsentForKey: kMPAFAdPersonalizationKey gdprConsents: gdprConsents];
469- NSNumber *storage = [ self resolvedConsentForKey: kMPAFAdStorageKey gdprConsents: gdprConsents];
470-
471- AppsFlyerConsent *consentObj = nil ;
472- if (isUserSubjectToGDPR) {
473- consentObj = [[AppsFlyerConsent alloc ]
474- initWithIsUserSubjectToGDPR: @( YES )
475- hasConsentForDataUsage: dataUsage
476- hasConsentForAdsPersonalization: personalization
477- hasConsentForAdStorage: storage ];
478- } else {
479- consentObj = [[AppsFlyerConsent alloc ]
480- initWithIsUserSubjectToGDPR: @( NO )
481- hasConsentForDataUsage: nil
482- hasConsentForAdsPersonalization: nil
483- hasConsentForAdStorage: nil ];
484- }
473+ NSNumber *dataUsage = [self resolvedConsentForMappingKey :kMPAFAdUserDataKey
474+ defaultKey: kMPAFDefaultAdUserDataKey
475+ gdprConsents: gdprConsents];
476+
477+ NSNumber *personalization = [ self resolvedConsentForMappingKey: kMPAFAdPersonalizationKey
478+ defaultKey: kMPAFDefaultAdPersonalizationKey
479+ gdprConsents: gdprConsents];
480+
481+ NSNumber *storage = [ self resolvedConsentForMappingKey: kMPAFAdStorageKey
482+ defaultKey: kMPAFDefaultAdStorageKey
483+ gdprConsents: gdprConsents ];
484+
485+
486+ AppsFlyerConsent *consentObj = [[AppsFlyerConsent alloc ]
487+ initWithIsUserSubjectToGDPR: @(isUserSubjectToGDPR)
488+ hasConsentForDataUsage: isUserSubjectToGDPR ? dataUsage : nil
489+ hasConsentForAdsPersonalization: isUserSubjectToGDPR ? personalization : nil
490+ hasConsentForAdStorage: isUserSubjectToGDPR ? storage : nil ];
485491
486492 // Update consent state with AppsFlyer
487493 [appsFlyerTracker setConsentData: consentObj];
488494}
489495
490496#pragma helper methods
491497
492- - (NSNumber * _Nullable)valueForConsentKey : (NSString *)key {
493- NSString *value = self->_configuration [key];
498+ - (NSNumber * _Nullable)resolvedConsentForMappingKey : (NSString *)mappingKey
499+ defaultKey : (NSString *)defaultKey
500+ gdprConsents : (NSDictionary <NSString *, MPGDPRConsent *> *)gdprConsents {
501+ // Prefer mParticle Consent if available
502+ MPGDPRConsent *consent = gdprConsents[mappingKey];
503+ if (consent) {
504+ return consent.consented ? @(YES ) : @(NO );
505+ }
506+
507+ // Fallback to configuration defaults
508+ NSString *value = self->_configuration [defaultKey];
494509 if ([value isEqualToString: @" Granted" ]) {
495510 return @(YES );
496511 } else if ([value isEqualToString: @" Denied" ]) {
@@ -499,18 +514,6 @@ - (NSNumber * _Nullable)valueForConsentKey:(NSString *)key {
499514 return nil ;
500515}
501516
502- - (NSNumber * _Nullable)resolvedConsentForKey : (NSString *)key
503- gdprConsents : (NSDictionary <NSString *, MPGDPRConsent *> *)gdprConsents {
504- // Defaults Consent States
505- NSNumber *value = [self valueForConsentKey: key];
506-
507- // Update from mParticle Consent
508- if (self->_configuration [key] && gdprConsents[self ->_configuration[key]]) {
509- MPGDPRConsent *consent = gdprConsents[self ->_configuration[key]];
510- value = consent.consented ? @(YES ) : @(NO );
511- }
512- return value;
513- }
514517
515518- (FilteredMParticleUser *)currentUser {
516519 return [[self kitApi ] getCurrentUserWithKit: self ];
0 commit comments