Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement Google EU Consent #94

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions Sources/mParticle-Appboy/MPKitAppboy.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@
static NSString *const promotionKey = @"promotions";
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";
static NSString *const BGoogleAdPersonalizationKey = @"$google_ad_personalization";

#if TARGET_OS_IOS
static id<BrazeInAppMessageUIDelegate> inAppMessageControllerDelegate = nil;
static BOOL shouldDisableNotificationHandling = NO;
Expand Down Expand Up @@ -325,6 +334,9 @@ - (MPKitExecStatus *)didFinishLaunchingWithConfiguration:(NSDictionary *)configu
_started = NO;
}

// Update Consent on launch
[self updateConsent];

execStatus = [[MPKitExecStatus alloc] initWithSDKCode:[[self class] kitCode] returnCode:MPKitReturnCodeSuccess];
return execStatus;
}
Expand Down Expand Up @@ -1037,6 +1049,40 @@ - (MPKitExecStatus *)setATTStatus:(MPATTAuthorizationStatus)status withATTStatus
return [[MPKitExecStatus alloc] initWithSDKCode:@(MPKitInstanceAppboy) returnCode:MPKitReturnCodeSuccess];
}

- (MPKitExecStatus *)setConsentState:(nullable MPConsentState *)state {
[self updateConsent];

return [[MPKitExecStatus alloc] initWithSDKCode:@(MPKitInstanceAppboy) returnCode:MPKitReturnCodeSuccess];
}

- (void)updateConsent {
MParticleUser *currentUser = [[[MParticle sharedInstance] identity] currentUser];
NSDictionary<NSString *, MPGDPRConsent *> *userConsentMap = currentUser.consentState.gdprConsentState;

// Update from mParticle consent
if (self.configuration && self.configuration[MPConsentMappingSDKKey]) {
// Retrieve the array of Consent Map Dictionaries 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];
} else if ([brazeConsentName isEqualToString:MPGoogleAdPersonalizationKey]) {
[appboyInstance.user setCustomAttributeWithKey:BGoogleAdPersonalizationKey boolValue:consent.consented];
}
}
}
}
}

#pragma mark Configuration Dictionary

- (NSMutableDictionary *)simplifiedDictionary:(NSDictionary *)originalDictionary {
Expand Down
10 changes: 5 additions & 5 deletions mParticle-Appboy.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ Pod::Spec.new do |s|
s.ios.source_files = 'Sources/**/*.{h,m,mm}'
s.ios.resource_bundles = { 'mParticle-Appboy-Privacy' => ['Sources/mParticle-Appboy/PrivacyInfo.xcprivacy'] }
s.ios.dependency 'mParticle-Apple-SDK', '~> 8.19'
s.ios.dependency 'BrazeKit', '~> 9.0'
s.ios.dependency 'BrazeKitCompat', '~> 9.0'
s.ios.dependency 'BrazeUI', '~> 9.0'
s.ios.dependency 'BrazeKit', '~> 10.0'
s.ios.dependency 'BrazeKitCompat', '~> 10.0'
s.ios.dependency 'BrazeUI', '~> 10.0'

s.tvos.deployment_target = "12.0"
s.tvos.source_files = 'Sources/**/*.{h,m,mm}'
s.tvos.resource_bundles = { 'mParticle-Appboy-Privacy' => ['Sources/mParticle-Appboy/PrivacyInfo.xcprivacy'] }
s.tvos.dependency 'mParticle-Apple-SDK', '~> 8.19'
s.tvos.dependency 'BrazeKit', '~> 9.0'
s.tvos.dependency 'BrazeKitCompat', '~> 9.0'
s.tvos.dependency 'BrazeKit', '~> 10.0'
s.tvos.dependency 'BrazeKitCompat', '~> 10.0'


end