Skip to content

Commit

Permalink
Address Mansis Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
BrandonStalnaker committed Mar 28, 2024
1 parent 9f97e44 commit 6b9524d
Showing 1 changed file with 32 additions and 14 deletions.
46 changes: 32 additions & 14 deletions mParticle-Google-Analytics-Firebase-GA4/MPKitFirebaseGA4Analytics.m
Original file line number Diff line number Diff line change
Expand Up @@ -378,16 +378,24 @@ - (MPKitExecStatus *)setConsentState:(nullable MPConsentState *)state {
}

- (void)updateConsent {
// If Defaults are not set do not send FIRAnalytics Consent
if (!self.configuration[kMPFIRGA4DefaultAdStorageKey] ) {
return;
}
FIRConsentStatus adStorageStatus;
FIRConsentStatus adUserDataStatus;
FIRConsentStatus analyticsStorageStatus;
FIRConsentStatus adPersonalizationStatus;

// Default Consent States
FIRConsentStatus adStorageStatus = [self.configuration[kMPFIRGA4DefaultAdStorageKey] isEqual: @"Granted"] ? FIRConsentStatusGranted : FIRConsentStatusDenied;
FIRConsentStatus adUserDataStatus = [self.configuration[kMPFIRGA4DefaultAdUserDataKey] isEqual: @"Granted"] ? FIRConsentStatusGranted : FIRConsentStatusDenied;
FIRConsentStatus analyticsStorageStatus = [self.configuration[kMPFIRGA4DefaultAnalyticsStorageKey] isEqual: @"Granted"] ? FIRConsentStatusGranted : FIRConsentStatusDenied;
FIRConsentStatus adPersonalizationStatus = [self.configuration[kMPFIRGA4DefaultAdPersonalizationKey] isEqual: @"Granted"] ? FIRConsentStatusGranted : FIRConsentStatusDenied;
if (self.configuration[kMPFIRGA4DefaultAdStorageKey]) {
adStorageStatus = [self.configuration[kMPFIRGA4DefaultAdStorageKey] isEqual: @"Granted"] ? FIRConsentStatusGranted : FIRConsentStatusDenied;
}
if (self.configuration[kMPFIRGA4DefaultAdUserDataKey]) {
adUserDataStatus = [self.configuration[kMPFIRGA4DefaultAdUserDataKey] isEqual: @"Granted"] ? FIRConsentStatusGranted : FIRConsentStatusDenied;
}
if (self.configuration[kMPFIRGA4DefaultAnalyticsStorageKey]) {
analyticsStorageStatus = [self.configuration[kMPFIRGA4DefaultAnalyticsStorageKey] isEqual: @"Granted"] ? FIRConsentStatusGranted : FIRConsentStatusDenied;
}
if (self.configuration[kMPFIRGA4DefaultAdPersonalizationKey]) {
adPersonalizationStatus = [self.configuration[kMPFIRGA4DefaultAdPersonalizationKey] isEqual: @"Granted"] ? FIRConsentStatusGranted : FIRConsentStatusDenied;
}

MParticleUser *currentUser = [[[MParticle sharedInstance] identity] currentUser];
NSDictionary<NSString *, MPGDPRConsent *> *userConsentMap = currentUser.consentState.gdprConsentState;
Expand All @@ -410,13 +418,23 @@ - (void)updateConsent {
adPersonalizationStatus = consent.consented ? FIRConsentStatusGranted : FIRConsentStatusDenied;
}

// Construct a dicitonary of consents
NSMutableDictionary *uploadDict = [[NSMutableDictionary alloc] init];
if (adStorageStatus) {
uploadDict[FIRConsentTypeAdStorage] = adStorageStatus;
}
if (adUserDataStatus) {
uploadDict[FIRConsentTypeAdUserData] = adUserDataStatus;
}
if (analyticsStorageStatus) {
uploadDict[FIRConsentTypeAnalyticsStorage] = analyticsStorageStatus;
}
if (adPersonalizationStatus) {
uploadDict[FIRConsentTypeAdPersonalization] = adPersonalizationStatus;
}

// Update Consent State with FIRAnalytics
[FIRAnalytics setConsent:@{
FIRConsentTypeAnalyticsStorage : analyticsStorageStatus,
FIRConsentTypeAdStorage : adStorageStatus,
FIRConsentTypeAdUserData : adUserDataStatus,
FIRConsentTypeAdPersonalization : adPersonalizationStatus,
}];
[FIRAnalytics setConsent:uploadDict];
}

- (NSString *)getEventNameForCommerceEvent:(MPCommerceEvent *)commerceEvent parameters:(NSDictionary<NSString *, id> *)parameters {
Expand Down

0 comments on commit 6b9524d

Please sign in to comment.