diff --git a/Branch-TestBed/Branch-SDK-Tests/BranchClassTests.m b/Branch-TestBed/Branch-SDK-Tests/BranchClassTests.m index e695e5afb..f66ed3e53 100644 --- a/Branch-TestBed/Branch-SDK-Tests/BranchClassTests.m +++ b/Branch-TestBed/Branch-SDK-Tests/BranchClassTests.m @@ -220,4 +220,15 @@ - (void)testGetLongURLWithParamsAndChannelAndTagsAndFeatureAndStageAndAlias { XCTAssertEqualObjects(generatedURL, expectedURL, @"URL should match the expected format"); } +- (void)testSetDMAParamsForEEA { + + XCTAssertFalse([[BNCPreferenceHelper sharedInstance] eeaRegionInitialized]); + [Branch setDMAParamsForEEA:FALSE AdPersonalizationConsent:TRUE AdUserDataUsageConsent:TRUE]; + XCTAssertTrue([[BNCPreferenceHelper sharedInstance] eeaRegionInitialized]); + XCTAssertFalse([BNCPreferenceHelper sharedInstance].eeaRegion); + XCTAssertTrue([BNCPreferenceHelper sharedInstance].adPersonalizationConsent); + XCTAssertTrue([BNCPreferenceHelper sharedInstance].adUserDataUsageConsent); + +} + @end diff --git a/BranchSDK/BNCPreferenceHelper.h b/BranchSDK/BNCPreferenceHelper.h index d7f56047b..bc53c3e26 100644 --- a/BranchSDK/BNCPreferenceHelper.h +++ b/BranchSDK/BNCPreferenceHelper.h @@ -73,6 +73,10 @@ NSURL* /* _Nonnull */ BNCURLForBranchDirectory(void); @property (strong, nonatomic) NSDate *firstAppLaunchTime; @property (assign, nonatomic) BOOL invokeRegisterApp; +@property (assign, nonatomic) BOOL eeaRegion; +@property (assign, nonatomic) BOOL adPersonalizationConsent; +@property (assign, nonatomic) BOOL adUserDataUsageConsent; + - (void) clearTrackingInformation; + (BNCPreferenceHelper *)sharedInstance; @@ -97,5 +101,6 @@ NSURL* /* _Nonnull */ BNCURLForBranchDirectory(void); - (NSMutableString*) sanitizedMutableBaseURL:(NSString*)baseUrl; - (void) synchronize; // Flushes preference queue to persistence. + (void) clearAll; +- (BOOL) eeaRegionInitialized; @end diff --git a/BranchSDK/BNCPreferenceHelper.m b/BranchSDK/BNCPreferenceHelper.m index fb7a3ca58..ab9e2bd74 100644 --- a/BranchSDK/BNCPreferenceHelper.m +++ b/BranchSDK/BNCPreferenceHelper.m @@ -61,6 +61,10 @@ static NSString * const BRANCH_PREFS_KEY_LOG_IAP_AS_EVENTS = @"bnc_log_iap_as_events"; +static NSString * const BRANCH_PREFS_KEY_DMA_EEA = @"bnc_dma_eea"; +static NSString * const BRANCH_PREFS_KEY_DMA_AD_PERSONALIZATION = @"bnc_dma_ad_personalization"; +static NSString * const BRANCH_PREFS_KEY_DMA_AD_USER_DATA = @"bnc_dma_ad_user_data"; + NSURL* /* _Nonnull */ BNCURLForBranchDirectory_Unthreaded(void); @@ -114,7 +118,10 @@ @implementation BNCPreferenceHelper highestConversionValueSent = _highestConversionValueSent, referringURLQueryParameters = _referringURLQueryParameters, anonID = _anonID, - patternListURL = _patternListURL; + patternListURL = _patternListURL, + eeaRegion = _eeaRegion, + adPersonalizationConsent = _adPersonalizationConsent, + adUserDataUsageConsent = _adUserDataUsageConsent; + (BNCPreferenceHelper *)sharedInstance { static BNCPreferenceHelper *preferenceHelper; @@ -791,6 +798,60 @@ - (void) setInvokeRegisterApp:(BOOL)invoke { } } +- (BOOL) eeaRegionInitialized { + @synchronized(self) { + if([self readObjectFromDefaults:BRANCH_PREFS_KEY_DMA_EEA]) + return YES; + return NO; + } +} + +- (BOOL) eeaRegion { + @synchronized(self) { + NSNumber *b = (id) [self readObjectFromDefaults:BRANCH_PREFS_KEY_DMA_EEA]; + if ([b isKindOfClass:NSNumber.class]) return [b boolValue]; + return NO; + } +} + +- (void) setEeaRegion:(BOOL)isEEARegion { + @synchronized(self) { + NSNumber *b = [NSNumber numberWithBool:isEEARegion]; + [self writeObjectToDefaults:BRANCH_PREFS_KEY_DMA_EEA value:b]; + } +} + +- (BOOL) adPersonalizationConsent { + @synchronized(self) { + NSNumber *b = (id) [self readObjectFromDefaults:BRANCH_PREFS_KEY_DMA_AD_PERSONALIZATION]; + if ([b isKindOfClass:NSNumber.class]) return [b boolValue]; + return NO; + } +} + +- (void) setAdPersonalizationConsent:(BOOL)hasConsent { + @synchronized(self) { + NSNumber *b = [NSNumber numberWithBool:hasConsent]; + [self writeObjectToDefaults:BRANCH_PREFS_KEY_DMA_AD_PERSONALIZATION value:b]; + } +} + +- (BOOL) adUserDataUsageConsent { + @synchronized(self) { + NSNumber *b = (id) [self readObjectFromDefaults:BRANCH_PREFS_KEY_DMA_AD_USER_DATA]; + if ([b isKindOfClass:NSNumber.class]) return [b boolValue]; + return NO; + } +} + +- (void) setAdUserDataUsageConsent:(BOOL)hasConsent { + @synchronized(self) { + NSNumber *b = [NSNumber numberWithBool:hasConsent]; + [self writeObjectToDefaults:BRANCH_PREFS_KEY_DMA_AD_USER_DATA value:b]; + } +} + + - (void) clearTrackingInformation { @synchronized(self) { /* diff --git a/BranchSDK/BNCRequestFactory.m b/BranchSDK/BNCRequestFactory.m index 7386e9641..c9ca42c18 100644 --- a/BranchSDK/BNCRequestFactory.m +++ b/BranchSDK/BNCRequestFactory.m @@ -110,6 +110,9 @@ - (NSDictionary *)dataForInstall { // TODO: refactor to simply request values for install [self addReferringURLsToJSON:json forEndpoint:@"/v1/install"]; + // Add DMA Compliance Params for Google + [self addDMAConsentParamsToJSON:json]; + return json; } @@ -150,6 +153,9 @@ - (NSDictionary *)dataForOpen { // TODO: refactor to simply request values for open [self addReferringURLsToJSON:json forEndpoint:@"/v1/open"]; + // Add DMA Compliance Params for Google + [self addDMAConsentParamsToJSON:json]; + return json; } @@ -181,6 +187,7 @@ - (NSDictionary *)dataForEventWithEventDictionary:(NSMutableDictionary *)diction // TODO: refactor to simply request values for event [self addReferringURLsToJSON:json forEndpoint:@"/v2/event"]; + return json; } @@ -319,6 +326,16 @@ - (void)addPartnerParametersToJSON:(NSMutableDictionary *)json { } } +- (void)addDMAConsentParamsToJSON:(NSMutableDictionary *)json { + + if([self.preferenceHelper eeaRegionInitialized]){ + [self safeSetValue:@([self.preferenceHelper eeaRegion]) forKey:BRANCH_REQUEST_KEY_DMA_EEA onDict:json]; + [self safeSetValue:@([self.preferenceHelper adPersonalizationConsent]) forKey:BRANCH_REQUEST_KEY_DMA_AD_PEROSALIZATION onDict:json]; + [self safeSetValue:@([self.preferenceHelper adUserDataUsageConsent]) forKey:BRANCH_REQUEST_KEY_DMA_AD_USER_DATA onDict:json]; + } +} + + - (void)addLocalURLToInstallJSON:(NSMutableDictionary *)json { if ([BNCPasteboard sharedInstance].checkOnInstall) { NSURL *pasteboardURL = nil; @@ -523,6 +540,9 @@ - (NSDictionary *)v2dictionary { dictionary[@"sdk"] = @"ios"; } + // Add DMA Compliance Params for Google + [self addDMAConsentParamsToJSON:dictionary]; + return dictionary; } diff --git a/BranchSDK/Branch.h b/BranchSDK/Branch.h index d4ab71e10..0a1057684 100644 --- a/BranchSDK/Branch.h +++ b/BranchSDK/Branch.h @@ -834,6 +834,16 @@ extern NSString * __nonnull const BNCSpotlightFeature; */ + (void) setReferrerGbraidValidityWindow:(NSTimeInterval) validityWindow; +/* + + Sets the value of parameters required by Google Conversion APIs for DMA Compliance in EEA region. + + @param eeaRegion -(BOOL) If European regulations, including the DMA, apply to this user and conversion. + @param adPersonalizationConsent - (BOOL) If End user has granted/denied ads personalization consent. + @param adUserDataUsageConsent - (BOOL) If User has granted/denied consent for 3P transmission of user level data for ads + */ ++ (void) setDMAParamsForEEA:(BOOL) eeaRegion AdPersonalizationConsent:(BOOL) adPersonalizationConsent AdUserDataUsageConsent:(BOOL) adUserDataUsageConsent; + #pragma mark - Session Item methods ///-------------------- diff --git a/BranchSDK/Branch.m b/BranchSDK/Branch.m index da80d47ee..c4bdd5b04 100644 --- a/BranchSDK/Branch.m +++ b/BranchSDK/Branch.m @@ -540,6 +540,12 @@ + (void)setReferrerGbraidValidityWindow:(NSTimeInterval)validityWindow{ } } ++ (void) setDMAParamsForEEA:(BOOL)eeaRegion AdPersonalizationConsent:(BOOL)adPersonalizationConsent AdUserDataUsageConsent:(BOOL)adUserDataUsageConsent{ + [BNCPreferenceHelper sharedInstance].eeaRegion = eeaRegion; + [BNCPreferenceHelper sharedInstance].adPersonalizationConsent = adPersonalizationConsent; + [BNCPreferenceHelper sharedInstance].adUserDataUsageConsent = adUserDataUsageConsent; +} + #pragma mark - InitSession Permutation methods - (void)initSessionWithLaunchOptions:(NSDictionary *)options { diff --git a/BranchSDK/BranchConstants.h b/BranchSDK/BranchConstants.h index 013622446..da64586c4 100644 --- a/BranchSDK/BranchConstants.h +++ b/BranchSDK/BranchConstants.h @@ -163,3 +163,7 @@ extern NSString * const BRANCH_REQUEST_KEY_SKAN_POSTBACK_INDEX; extern NSString * const BRANCH_REQUEST_KEY_VALUE_POSTBACK_SEQUENCE_INDEX_0; extern NSString * const BRANCH_REQUEST_KEY_VALUE_POSTBACK_SEQUENCE_INDEX_1; extern NSString * const BRANCH_REQUEST_KEY_VALUE_POSTBACK_SEQUENCE_INDEX_2; + +extern NSString * const BRANCH_REQUEST_KEY_DMA_EEA; +extern NSString * const BRANCH_REQUEST_KEY_DMA_AD_PEROSALIZATION; +extern NSString * const BRANCH_REQUEST_KEY_DMA_AD_USER_DATA; diff --git a/BranchSDK/BranchConstants.m b/BranchSDK/BranchConstants.m index f4d12989d..96749379b 100644 --- a/BranchSDK/BranchConstants.m +++ b/BranchSDK/BranchConstants.m @@ -161,3 +161,8 @@ NSString * const BRANCH_REQUEST_KEY_VALUE_POSTBACK_SEQUENCE_INDEX_0 = @"postback-sequence-index-0"; NSString * const BRANCH_REQUEST_KEY_VALUE_POSTBACK_SEQUENCE_INDEX_1 = @"postback-sequence-index-1"; NSString * const BRANCH_REQUEST_KEY_VALUE_POSTBACK_SEQUENCE_INDEX_2 = @"postback-sequence-index-2"; + +NSString * const BRANCH_REQUEST_KEY_DMA_EEA = @"dma_eea"; +NSString * const BRANCH_REQUEST_KEY_DMA_AD_PEROSALIZATION = @"dma_ad_personalization"; +NSString * const BRANCH_REQUEST_KEY_DMA_AD_USER_DATA = @"dma_ad_user_data"; +