|
5 | 5 | #if __has_include(<FirebaseCore/FirebaseCore.h>)
|
6 | 6 | #import <FirebaseCore/FirebaseCore.h>
|
7 | 7 | #import <FirebaseAnalytics/FIRAnalytics.h>
|
| 8 | + #import <FirebaseAnalytics/FIRAnalytics+Consent.h> |
8 | 9 | #else
|
9 | 10 | #import "FirebaseCore/FirebaseCore.h"
|
10 | 11 | #import "FirebaseAnalytics/FIRAnalytics.h"
|
| 12 | + #import "FirebaseAnalytics/FIRAnalytics+Consent.h" |
11 | 13 | #endif
|
12 | 14 | #endif
|
13 | 15 |
|
@@ -40,6 +42,15 @@ @implementation MPKitFirebaseAnalytics
|
40 | 42 | static NSString *const aToZCharacters = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
41 | 43 | static NSString *const instanceIdIntegrationKey = @"app_instance_id";
|
42 | 44 |
|
| 45 | +static NSString *const kMPFIRGA4AdStorageKey = @"ad_storage"; |
| 46 | +static NSString *const kMPFIRGA4AdUserDataKey = @"ad_user_data"; |
| 47 | +static NSString *const kMPFIRGA4AdPersonalizationKey = @"ad_personalization"; |
| 48 | +static NSString *const kMPFIRGA4AnalyticsStorageKey = @"analytics_storage"; |
| 49 | +static NSString *const kMPFIRGA4DefaultAdStorageKey = @"defaultAdStorageConsentSDK"; |
| 50 | +static NSString *const kMPFIRGA4DefaultAdUserDataKey = @"defaultAdUserDataConsentSDK"; |
| 51 | +static NSString *const kMPFIRGA4DefaultAdPersonalizationKey = @"defaultAdPersonalizationConsentSDK"; |
| 52 | +static NSString *const kMPFIRGA4DefaultAnalyticsStorageKey = @"defaultAnalyticsStorageConsentSDK"; |
| 53 | + |
43 | 54 | const NSInteger FIR_MAX_CHARACTERS_EVENT_NAME_INDEX = 39;
|
44 | 55 | const NSInteger FIR_MAX_CHARACTERS_IDENTITY_NAME_INDEX = 23;
|
45 | 56 | const NSInteger FIR_MAX_CHARACTERS_EVENT_ATTR_VALUE_INDEX = 99;
|
@@ -74,6 +85,8 @@ - (MPKitExecStatus *)didFinishLaunchingWithConfiguration:(NSDictionary *)configu
|
74 | 85 | [self updateInstanceIDIntegration];
|
75 | 86 | }
|
76 | 87 |
|
| 88 | + [self updateConsent]; |
| 89 | + |
77 | 90 | _started = YES;
|
78 | 91 |
|
79 | 92 | dispatch_async(dispatch_get_main_queue(), ^{
|
@@ -332,6 +345,88 @@ - (void)logUserAttributes:(NSDictionary<NSString *, id> *)userAttributes {
|
332 | 345 | }
|
333 | 346 | }
|
334 | 347 |
|
| 348 | +- (MPKitExecStatus *)setConsentState:(nullable MPConsentState *)state { |
| 349 | + [self updateConsent]; |
| 350 | + |
| 351 | + return [self execStatus:MPKitReturnCodeSuccess]; |
| 352 | +} |
| 353 | + |
| 354 | +- (void)updateConsent { |
| 355 | + FIRConsentStatus adStorageStatus; |
| 356 | + FIRConsentStatus adUserDataStatus; |
| 357 | + FIRConsentStatus analyticsStorageStatus; |
| 358 | + FIRConsentStatus adPersonalizationStatus; |
| 359 | + |
| 360 | + // Default Consent States |
| 361 | + if (self.configuration[kMPFIRGA4DefaultAdStorageKey]) { |
| 362 | + if ([self.configuration[kMPFIRGA4DefaultAdStorageKey] isEqual: @"Granted"]) { |
| 363 | + adStorageStatus = FIRConsentStatusGranted; |
| 364 | + } else if ([self.configuration[kMPFIRGA4DefaultAdStorageKey] isEqual: @"Denied"]) { |
| 365 | + adStorageStatus = FIRConsentStatusDenied; |
| 366 | + } |
| 367 | + } |
| 368 | + if (self.configuration[kMPFIRGA4DefaultAdUserDataKey]) { |
| 369 | + if ([self.configuration[kMPFIRGA4DefaultAdUserDataKey] isEqual: @"Granted"]) { |
| 370 | + adUserDataStatus = FIRConsentStatusGranted; |
| 371 | + } else if ([self.configuration[kMPFIRGA4DefaultAdUserDataKey] isEqual: @"Denied"]) { |
| 372 | + adUserDataStatus = FIRConsentStatusDenied; |
| 373 | + } |
| 374 | + } |
| 375 | + if (self.configuration[kMPFIRGA4DefaultAnalyticsStorageKey]) { |
| 376 | + if ([self.configuration[kMPFIRGA4DefaultAnalyticsStorageKey] isEqual: @"Granted"]) { |
| 377 | + analyticsStorageStatus = FIRConsentStatusGranted; |
| 378 | + } else if ([self.configuration[kMPFIRGA4DefaultAnalyticsStorageKey] isEqual: @"Denied"]) { |
| 379 | + analyticsStorageStatus = FIRConsentStatusDenied; |
| 380 | + } |
| 381 | + } |
| 382 | + if (self.configuration[kMPFIRGA4DefaultAdPersonalizationKey]) { |
| 383 | + if ([self.configuration[kMPFIRGA4DefaultAdPersonalizationKey] isEqual: @"Granted"]) { |
| 384 | + adPersonalizationStatus = FIRConsentStatusGranted; |
| 385 | + } else if ([self.configuration[kMPFIRGA4DefaultAdPersonalizationKey] isEqual: @"Denied"]) { |
| 386 | + adPersonalizationStatus = FIRConsentStatusDenied; |
| 387 | + } |
| 388 | + } |
| 389 | + |
| 390 | + MParticleUser *currentUser = [[[MParticle sharedInstance] identity] currentUser]; |
| 391 | + NSDictionary<NSString *, MPGDPRConsent *> *userConsentMap = currentUser.consentState.gdprConsentState; |
| 392 | + |
| 393 | + // Update from mParticle consent |
| 394 | + if (self.configuration[kMPFIRGA4AdStorageKey] && userConsentMap[self.configuration[kMPFIRGA4AdStorageKey]]) { |
| 395 | + MPGDPRConsent *consent = userConsentMap[self.configuration[kMPFIRGA4AdStorageKey]]; |
| 396 | + adStorageStatus = consent.consented ? FIRConsentStatusGranted : FIRConsentStatusDenied; |
| 397 | + } |
| 398 | + if (self.configuration[kMPFIRGA4AdUserDataKey] && userConsentMap[self.configuration[kMPFIRGA4AdUserDataKey]]) { |
| 399 | + MPGDPRConsent *consent = userConsentMap[self.configuration[kMPFIRGA4AdUserDataKey]]; |
| 400 | + adUserDataStatus = consent.consented ? FIRConsentStatusGranted : FIRConsentStatusDenied; |
| 401 | + } |
| 402 | + if (self.configuration[kMPFIRGA4AnalyticsStorageKey] && userConsentMap[self.configuration[kMPFIRGA4AnalyticsStorageKey]]) { |
| 403 | + MPGDPRConsent *consent = userConsentMap[self.configuration[kMPFIRGA4AnalyticsStorageKey]]; |
| 404 | + analyticsStorageStatus = consent.consented ? FIRConsentStatusGranted : FIRConsentStatusDenied; |
| 405 | + } |
| 406 | + if (self.configuration[kMPFIRGA4AdPersonalizationKey] && userConsentMap[self.configuration[kMPFIRGA4AdPersonalizationKey]]) { |
| 407 | + MPGDPRConsent *consent = userConsentMap[self.configuration[kMPFIRGA4AdPersonalizationKey]]; |
| 408 | + adPersonalizationStatus = consent.consented ? FIRConsentStatusGranted : FIRConsentStatusDenied; |
| 409 | + } |
| 410 | + |
| 411 | + // Construct a dictionary of consents |
| 412 | + NSMutableDictionary *uploadDict = [[NSMutableDictionary alloc] init]; |
| 413 | + if (adStorageStatus) { |
| 414 | + uploadDict[FIRConsentTypeAdStorage] = adStorageStatus; |
| 415 | + } |
| 416 | + if (adUserDataStatus) { |
| 417 | + uploadDict[FIRConsentTypeAdUserData] = adUserDataStatus; |
| 418 | + } |
| 419 | + if (analyticsStorageStatus) { |
| 420 | + uploadDict[FIRConsentTypeAnalyticsStorage] = analyticsStorageStatus; |
| 421 | + } |
| 422 | + if (adPersonalizationStatus) { |
| 423 | + uploadDict[FIRConsentTypeAdPersonalization] = adPersonalizationStatus; |
| 424 | + } |
| 425 | + |
| 426 | + // Update consent state with FIRAnalytics |
| 427 | + [FIRAnalytics setConsent:uploadDict]; |
| 428 | +} |
| 429 | + |
335 | 430 | - (NSString *)getEventNameForCommerceEvent:(MPCommerceEvent *)commerceEvent parameters:(NSDictionary<NSString *, id> *)parameters {
|
336 | 431 | switch (commerceEvent.action) {
|
337 | 432 | case MPCommerceEventActionAddToCart:
|
|
0 commit comments