Skip to content

Commit

Permalink
update logic
Browse files Browse the repository at this point in the history
  • Loading branch information
BrandonStalnaker committed Sep 6, 2024
1 parent a81c44f commit 195a318
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions Sources/mParticle-Appboy/MPKitAppboy.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
static NSString *const impressionKey = @"impressions";

// Strings used for Google Consent
static NSString *const MPMapKey = @"map";
static NSString *const MPValueKey = @"value";
static NSString *const MPConsentMappingSDKKey = @"consentMappingSDK";
static NSString *const MPGoogleAdUserDataKey = @"google_ad_user_data";
static NSString *const MPGoogleAdPersonalizationKey = @"google_ad_personalization";
static NSString *const BGoogleAdUserDataKey = @"$google_ad_user_data";
Expand Down Expand Up @@ -1055,15 +1058,29 @@ - (MPKitExecStatus *)setConsentState:(nullable MPConsentState *)state {
- (void)updateConsent {
MParticleUser *currentUser = [[[MParticle sharedInstance] identity] currentUser];
NSDictionary<NSString *, MPGDPRConsent *> *userConsentMap = currentUser.consentState.gdprConsentState;

// Update from mParticle consent
if (self.configuration[MPGoogleAdUserDataKey] && userConsentMap[self.configuration[MPGoogleAdUserDataKey]]) {
MPGDPRConsent *consent = userConsentMap[self.configuration[MPGoogleAdUserDataKey]];
[appboyInstance.user setCustomAttributeWithKey:BGoogleAdUserDataKey boolValue:consent.consented];
}
if (self.configuration[MPGoogleAdPersonalizationKey] && userConsentMap[self.configuration[MPGoogleAdPersonalizationKey]]) {
MPGDPRConsent *consent = userConsentMap[self.configuration[MPGoogleAdPersonalizationKey]];
[appboyInstance.user setCustomAttributeWithKey:BGoogleAdPersonalizationKey boolValue:consent.consented];
if (self.configuration && self.configuration[MPConsentMappingSDKKey]) {
// Retrieve the array of Consent Map Dicitonaries from the Config
NSData *objectData = [self.configuration[MPConsentMappingSDKKey] dataUsingEncoding:NSUTF8StringEncoding];
NSArray *consentMappingArray = [NSJSONSerialization JSONObjectWithData:objectData
options:NSJSONReadingMutableContainers
error:nil];

// For each valid Consent Map check if mParticle has a corresponding consent setting and, if so, send to Braze
for (NSDictionary *consentMappingDict in consentMappingArray) {
NSString *consentPurpose = consentMappingDict[MPMapKey];
if (consentMappingDict[MPValueKey] && userConsentMap[consentPurpose.lowercaseString]) {
NSString *brazeConsentName = consentMappingDict[MPValueKey];
MPGDPRConsent *consent = userConsentMap[consentPurpose.lowercaseString];
if ([brazeConsentName isEqualToString:MPGoogleAdUserDataKey]) {
[appboyInstance.user setCustomAttributeWithKey:BGoogleAdUserDataKey boolValue:consent.consented];
}
if ([brazeConsentName isEqualToString:MPGoogleAdPersonalizationKey]) {
[appboyInstance.user setCustomAttributeWithKey:BGoogleAdPersonalizationKey boolValue:consent.consented];
}
}
}
}
}

Expand Down

0 comments on commit 195a318

Please sign in to comment.