From 84de80f3e4f1459a14bfc17b1d702f41f724bfa6 Mon Sep 17 00:00:00 2001 From: nsingh-branch Date: Tue, 30 Jul 2024 10:46:39 -0700 Subject: [PATCH] Updated enum and request fields --- Sources/BranchSDK/BNCPreferenceHelper.m | 16 +++- Sources/BranchSDK/BNCRequestFactory.m | 17 ++-- Sources/BranchSDK/Branch.m | 9 +- Sources/BranchSDK/BranchConstants.m | 1 + Sources/BranchSDK/Private/BranchConstants.h | 2 + .../BranchSDK/Public/BNCPreferenceHelper.h | 3 +- Sources/BranchSDK/Public/Branch.h | 84 +++++++++---------- 7 files changed, 78 insertions(+), 54 deletions(-) diff --git a/Sources/BranchSDK/BNCPreferenceHelper.m b/Sources/BranchSDK/BNCPreferenceHelper.m index f9c9ca018..8f8b91496 100644 --- a/Sources/BranchSDK/BNCPreferenceHelper.m +++ b/Sources/BranchSDK/BNCPreferenceHelper.m @@ -823,12 +823,20 @@ - (void) setAdUserDataUsageConsent:(BOOL)hasConsent { } } -- (NSInteger)attributionLevel { - return [self readIntegerFromDefaults:BRANCH_PREFS_KEY_ATTRIBUTION_LEVEL]; +- (BOOL) attributionLevelInitialized { + @synchronized(self) { + if([self readObjectFromDefaults:BRANCH_PREFS_KEY_ATTRIBUTION_LEVEL]) + return YES; + return NO; + } +} + +- (BranchAttributionLevel)attributionLevel { + return [self readStringFromDefaults:BRANCH_PREFS_KEY_ATTRIBUTION_LEVEL]; } -- (void)setAttributionLevel:(NSInteger)level { - [self writeIntegerToDefaults:BRANCH_PREFS_KEY_ATTRIBUTION_LEVEL value:level]; +- (void)setAttributionLevel:(BranchAttributionLevel)level { + [self writeObjectToDefaults:BRANCH_PREFS_KEY_ATTRIBUTION_LEVEL value:level]; } - (void) clearTrackingInformation { diff --git a/Sources/BranchSDK/BNCRequestFactory.m b/Sources/BranchSDK/BNCRequestFactory.m index 41daf8144..a22be9972 100644 --- a/Sources/BranchSDK/BNCRequestFactory.m +++ b/Sources/BranchSDK/BNCRequestFactory.m @@ -117,6 +117,8 @@ - (NSDictionary *)dataForInstallWithURLString:(NSString *)urlString { // Add DMA Compliance Params for Google [self addDMAConsentParamsToJSON:json]; + [self addConsumerProtectionAttributionLevel:json]; + return json; } @@ -164,6 +166,8 @@ - (NSDictionary *)dataForOpenWithURLString:(NSString *)urlString { // Add DMA Compliance Params for Google [self addDMAConsentParamsToJSON:json]; + [self addConsumerProtectionAttributionLevel:json]; + return json; } @@ -342,7 +346,6 @@ - (void)addDMAConsentParamsToJSON:(NSMutableDictionary *)json { } } - - (void)addLocalURLToInstallJSON:(NSMutableDictionary *)json { if ([BNCPasteboard sharedInstance].checkOnInstall) { NSURL *pasteboardURL = nil; @@ -414,10 +417,6 @@ - (void)addAppClipDataToJSON:(NSMutableDictionary *)json { - (void)addDefaultRequestDataToJSON:(NSMutableDictionary *)json { json[@"branch_key"] = self.branchKey; - if (self.preferenceHelper.attributionLevel != NSNotFound) { - [json bnc_safeSetObject:@(self.preferenceHelper.attributionLevel) forKey:@"consumer_protection_attribution_level"]; - } - // omit field if value is NO if ([self isTrackingDisabled]) { json[@"tracking_disabled"] = @(1); @@ -491,6 +490,12 @@ - (void)addDeveloperUserIDToJSON:(NSMutableDictionary *)json { [json bnc_safeSetObject:self.preferenceHelper.userIdentity forKey:@"identity"]; } +- (void)addConsumerProtectionAttributionLevel:(NSMutableDictionary *)json { + if([self.preferenceHelper attributionLevelInitialized]){ + [self safeSetValue:[self.preferenceHelper attributionLevel] forKey:BRANCH_REQUEST_KEY_CPP_LEVEL onDict:json]; + } +} + // event - (void)addV2DictionaryToJSON:(NSMutableDictionary *)json { NSDictionary *tmp = [self v2dictionary]; @@ -554,6 +559,8 @@ - (NSDictionary *)v2dictionary { // Add DMA Compliance Params for Google [self addDMAConsentParamsToJSON:dictionary]; + [self addConsumerProtectionAttributionLevel:dictionary]; + return dictionary; } diff --git a/Sources/BranchSDK/Branch.m b/Sources/BranchSDK/Branch.m index a536398a9..c318ffcb5 100644 --- a/Sources/BranchSDK/Branch.m +++ b/Sources/BranchSDK/Branch.m @@ -84,6 +84,11 @@ NSString * const BNCSpotlightFeature = @"spotlight"; +BranchAttributionLevel const BranchAttributionLevelFull = @"FULL"; +BranchAttributionLevel const BranchAttributionLevelReduced = @"REDUCED"; +BranchAttributionLevel const BranchAttributionLevelMinimal = @"MINIMAL"; +BranchAttributionLevel const BranchAttributionLevelNone = @"NONE"; + #ifndef CSSearchableItemActivityIdentifier #define CSSearchableItemActivityIdentifier @"kCSSearchableItemActivityIdentifier" #endif @@ -542,7 +547,7 @@ + (void) setDMAParamsForEEA:(BOOL)eeaRegion AdPersonalizationConsent:(BOOL)adPer - (void)setConsumerProtectionAttributionLevel:(BranchAttributionLevel)level { self.preferenceHelper.attributionLevel = level; - [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Setting Consumer Protection Attribution Level to %lu", (unsigned long)level] error:nil]; + [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Setting Consumer Protection Attribution Level to %@", level] error:nil]; //Set tracking to disabled if consumer protection attribution level is changed to BranchAttributionLevelNone. Otherwise, keep tracking enabled. if (level == BranchAttributionLevelNone) { @@ -565,7 +570,7 @@ - (void)setConsumerProtectionAttributionLevel:(BranchAttributionLevel)level { } else { if ([Branch trackingDisabled]) { //Enable Tracking - [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Enabling attribution events due to Consumer Protection Attribution Level being %lu.", (unsigned long)level] error:nil]; + [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Enabling attribution events due to Consumer Protection Attribution Level being %@.", level] error:nil]; // Set the flag: [BNCPreferenceHelper sharedInstance].trackingDisabled = NO; diff --git a/Sources/BranchSDK/BranchConstants.m b/Sources/BranchSDK/BranchConstants.m index 96749379b..e87819e98 100644 --- a/Sources/BranchSDK/BranchConstants.m +++ b/Sources/BranchSDK/BranchConstants.m @@ -166,3 +166,4 @@ NSString * const BRANCH_REQUEST_KEY_DMA_AD_PEROSALIZATION = @"dma_ad_personalization"; NSString * const BRANCH_REQUEST_KEY_DMA_AD_USER_DATA = @"dma_ad_user_data"; +NSString * const BRANCH_REQUEST_KEY_CPP_LEVEL = @"cpp_level"; diff --git a/Sources/BranchSDK/Private/BranchConstants.h b/Sources/BranchSDK/Private/BranchConstants.h index da64586c4..9a13399ca 100644 --- a/Sources/BranchSDK/Private/BranchConstants.h +++ b/Sources/BranchSDK/Private/BranchConstants.h @@ -167,3 +167,5 @@ 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; + +extern NSString * const BRANCH_REQUEST_KEY_CPP_LEVEL; diff --git a/Sources/BranchSDK/Public/BNCPreferenceHelper.h b/Sources/BranchSDK/Public/BNCPreferenceHelper.h index a5faa8236..464d5508a 100644 --- a/Sources/BranchSDK/Public/BNCPreferenceHelper.h +++ b/Sources/BranchSDK/Public/BNCPreferenceHelper.h @@ -76,7 +76,7 @@ NSURL* /* _Nonnull */ BNCURLForBranchDirectory(void); @property (assign, nonatomic) BOOL adPersonalizationConsent; @property (assign, nonatomic) BOOL adUserDataUsageConsent; -@property (nonatomic, assign) NSInteger attributionLevel; +@property (nonatomic, assign) NSString *attributionLevel; - (void) clearTrackingInformation; @@ -103,5 +103,6 @@ NSURL* /* _Nonnull */ BNCURLForBranchDirectory(void); - (void) synchronize; // Flushes preference queue to persistence. + (void) clearAll; - (BOOL) eeaRegionInitialized; +- (BOOL) attributionLevelInitialized; @end diff --git a/Sources/BranchSDK/Public/Branch.h b/Sources/BranchSDK/Public/Branch.h index ce3a1f031..6f0cc0572 100644 --- a/Sources/BranchSDK/Public/Branch.h +++ b/Sources/BranchSDK/Public/Branch.h @@ -816,48 +816,48 @@ Sets a custom base URL for all calls to the Branch API. /** * Enumeration representing different levels of consumer protection attribution levels */ -typedef NS_ENUM(NSUInteger, BranchAttributionLevel) { - /** - * Full: - * - Advertising Ids - * - Device Ids - * - Local IP - * - Persisted Non-Aggregate Ids - * - Persisted Aggregate Ids - * - Ads Postbacks / Webhooks - * - Data Integrations Webhooks - * - SAN Callouts - * - Privacy Frameworks - * - Deep Linking - */ - BranchAttributionLevelFull = 0, - - /** - * Reduced: - * - Device Ids - * - Local IP - * - Data Integrations Webhooks - * - Privacy Frameworks - * - Deep Linking - */ - BranchAttributionLevelReduced = 1, - - /** - * Minimal: - * - Device Ids - * - Local IP - * - Data Integrations Webhooks - * - Deep Linking - */ - BranchAttributionLevelMinimal = 2, - - /** - * None: - * - Only Deterministic Deep Linking - * - Disables all other Branch requests - */ - BranchAttributionLevelNone = 3 -}; +typedef NSString * BranchAttributionLevel NS_STRING_ENUM; + +/** + * Full: + * - Advertising Ids + * - Device Ids + * - Local IP + * - Persisted Non-Aggregate Ids + * - Persisted Aggregate Ids + * - Ads Postbacks / Webhooks + * - Data Integrations Webhooks + * - SAN Callouts + * - Privacy Frameworks + * - Deep Linking + */ +extern BranchAttributionLevel const BranchAttributionLevelFull; + +/** + * Reduced: + * - Device Ids + * - Local IP + * - Data Integrations Webhooks + * - Privacy Frameworks + * - Deep Linking + */ +extern BranchAttributionLevel const BranchAttributionLevelReduced; + +/** + * Minimal: + * - Device Ids + * - Local IP + * - Data Integrations Webhooks + * - Deep Linking + */ +extern BranchAttributionLevel const BranchAttributionLevelMinimal; + +/** + * None: + * - Only Deterministic Deep Linking + * - Disables all other Branch requests + */ +extern BranchAttributionLevel const BranchAttributionLevelNone; /**