Skip to content

Commit

Permalink
(WIP) - SDK 2223 DMA Consent Params Implementation (#1345)
Browse files Browse the repository at this point in the history
 SDK-2223 Added API for setting DMA Compliance Params on Server Requests.
  • Loading branch information
NidhiDixit09 authored Feb 15, 2024
1 parent 18cc5aa commit 8eb3280
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 1 deletion.
11 changes: 11 additions & 0 deletions Branch-TestBed/Branch-SDK-Tests/BranchClassTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions BranchSDK/BNCPreferenceHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -97,5 +101,6 @@ NSURL* /* _Nonnull */ BNCURLForBranchDirectory(void);
- (NSMutableString*) sanitizedMutableBaseURL:(NSString*)baseUrl;
- (void) synchronize; // Flushes preference queue to persistence.
+ (void) clearAll;
- (BOOL) eeaRegionInitialized;

@end
63 changes: 62 additions & 1 deletion BranchSDK/BNCPreferenceHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
/*
Expand Down
20 changes: 20 additions & 0 deletions BranchSDK/BNCRequestFactory.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -181,6 +187,7 @@ - (NSDictionary *)dataForEventWithEventDictionary:(NSMutableDictionary *)diction
// TODO: refactor to simply request values for event
[self addReferringURLsToJSON:json forEndpoint:@"/v2/event"];


return json;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -523,6 +540,9 @@ - (NSDictionary *)v2dictionary {
dictionary[@"sdk"] = @"ios";
}

// Add DMA Compliance Params for Google
[self addDMAConsentParamsToJSON:dictionary];

return dictionary;
}

Expand Down
10 changes: 10 additions & 0 deletions BranchSDK/Branch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

///--------------------
Expand Down
6 changes: 6 additions & 0 deletions BranchSDK/Branch.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions BranchSDK/BranchConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
5 changes: 5 additions & 0 deletions BranchSDK/BranchConstants.m
Original file line number Diff line number Diff line change
Expand Up @@ -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";

0 comments on commit 8eb3280

Please sign in to comment.