From 513ae49e85c8fc3da4e6c360f4ea821541f29b75 Mon Sep 17 00:00:00 2001 From: nsingh-branch Date: Fri, 14 Jun 2024 09:20:01 -0700 Subject: [PATCH 01/19] Updates --- Sources/BranchSDK/BNCPreferenceHelper.m | 13 +++++++++++-- Sources/BranchSDK/BNCRequestFactory.m | 6 ++++++ Sources/BranchSDK/Branch.m | 4 ++++ Sources/BranchSDK/Public/BNCPreferenceHelper.h | 3 +++ Sources/BranchSDK/Public/Branch.h | 17 +++++++++++++++++ 5 files changed, 41 insertions(+), 2 deletions(-) diff --git a/Sources/BranchSDK/BNCPreferenceHelper.m b/Sources/BranchSDK/BNCPreferenceHelper.m index ff4eacafa..fd3e33b91 100644 --- a/Sources/BranchSDK/BNCPreferenceHelper.m +++ b/Sources/BranchSDK/BNCPreferenceHelper.m @@ -64,6 +64,8 @@ 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"; +static NSString * const BRANCH_PREFS_KEY_TRACKING_LEVEL = @"bnc_tracking_level"; + NSURL* /* _Nonnull */ BNCURLForBranchDirectory_Unthreaded(void); @@ -119,7 +121,8 @@ @implementation BNCPreferenceHelper patternListURL = _patternListURL, eeaRegion = _eeaRegion, adPersonalizationConsent = _adPersonalizationConsent, - adUserDataUsageConsent = _adUserDataUsageConsent; + adUserDataUsageConsent = _adUserDataUsageConsent, + trackingLevel = _trackingLevel; + (BNCPreferenceHelper *)sharedInstance { static BNCPreferenceHelper *preferenceHelper = nil; @@ -625,7 +628,6 @@ - (void) setDropURLOpen:(BOOL)value { } } - - (BOOL) trackingDisabled { @synchronized(self) { NSNumber *b = (id) [self readObjectFromDefaults:@"trackingDisabled"]; @@ -821,6 +823,13 @@ - (void) setAdUserDataUsageConsent:(BOOL)hasConsent { } } +- (NSInteger)trackingLevel { + return [self readIntegerFromDefaults:BRANCH_PREFS_KEY_TRACKING_LEVEL]; +} + +- (void)setTrackingLevel:(NSInteger)trackingLevel { + [self writeIntegerToDefaults:BRANCH_PREFS_KEY_TRACKING_LEVEL value:trackingLevel]; +} - (void) clearTrackingInformation { @synchronized(self) { diff --git a/Sources/BranchSDK/BNCRequestFactory.m b/Sources/BranchSDK/BNCRequestFactory.m index 570659964..7ce5c62bc 100644 --- a/Sources/BranchSDK/BNCRequestFactory.m +++ b/Sources/BranchSDK/BNCRequestFactory.m @@ -414,6 +414,12 @@ - (void)addAppClipDataToJSON:(NSMutableDictionary *)json { - (void)addDefaultRequestDataToJSON:(NSMutableDictionary *)json { json[@"branch_key"] = self.branchKey; + if (self.preferenceHelper.trackingLevel) { + json[@"tracking_level"] = @(self.preferenceHelper.trackingLevel); + } else { + json[@"tracking_level"] = @(0); + } + // omit field if value is NO if ([self isTrackingDisabled]) { json[@"tracking_disabled"] = @(1); diff --git a/Sources/BranchSDK/Branch.m b/Sources/BranchSDK/Branch.m index 97a7383b9..25221b47a 100644 --- a/Sources/BranchSDK/Branch.m +++ b/Sources/BranchSDK/Branch.m @@ -539,6 +539,10 @@ + (void) setDMAParamsForEEA:(BOOL)eeaRegion AdPersonalizationConsent:(BOOL)adPer [BNCPreferenceHelper sharedInstance].adUserDataUsageConsent = adUserDataUsageConsent; } ++ (void)setTrackingLevel:(BranchTrackingLevel)level { + [BNCPreferenceHelper sharedInstance].trackingLevel = level; +} + #pragma mark - InitSession Permutation methods - (void)initSessionWithLaunchOptions:(NSDictionary *)options { diff --git a/Sources/BranchSDK/Public/BNCPreferenceHelper.h b/Sources/BranchSDK/Public/BNCPreferenceHelper.h index 8c0fba2d0..3fa385a33 100644 --- a/Sources/BranchSDK/Public/BNCPreferenceHelper.h +++ b/Sources/BranchSDK/Public/BNCPreferenceHelper.h @@ -76,6 +76,9 @@ NSURL* /* _Nonnull */ BNCURLForBranchDirectory(void); @property (assign, nonatomic) BOOL adPersonalizationConsent; @property (assign, nonatomic) BOOL adUserDataUsageConsent; +@property (assign, nonatomic) NSInteger trackingLevel; + + - (void) clearTrackingInformation; + (BNCPreferenceHelper *)sharedInstance; diff --git a/Sources/BranchSDK/Public/Branch.h b/Sources/BranchSDK/Public/Branch.h index 64afdaa30..5277c0b8a 100644 --- a/Sources/BranchSDK/Public/Branch.h +++ b/Sources/BranchSDK/Public/Branch.h @@ -812,6 +812,23 @@ Sets a custom base URL for all calls to the Branch API. */ + (void) setDMAParamsForEEA:(BOOL) eeaRegion AdPersonalizationConsent:(BOOL) adPersonalizationConsent AdUserDataUsageConsent:(BOOL) adUserDataUsageConsent; +typedef NS_ENUM(NSUInteger, BranchTrackingLevel) { + BranchTrackingLevelFull, + BranchTrackingLevelPrivacy, + BranchTrackingLevelAnalytics, + BranchTrackingLevelNone +}; + +/** + Sets the tracking level for data collection. + + @param level The desired tracking level, represented by the BranchTrackingLevel enum (Full, Privacy, Analytics, None). + @discussion This method allows you to control the amount and type of data collected and transmitted by the SDK. + Adjusting the tracking level can help you comply with privacy regulations and meet your data collection needs. + */ ++ (void)setTrackingLevel:(BranchTrackingLevel)level; + + #pragma mark - Session Item methods ///-------------------- From 3a5c66bc20ab1781e929141472c05f0a9409f3be Mon Sep 17 00:00:00 2001 From: nsingh-branch Date: Fri, 21 Jun 2024 16:07:40 -0700 Subject: [PATCH 02/19] Updated naming --- Branch-TestBed/Branch-TestBed/AppDelegate.m | 2 ++ Sources/BranchSDK/BNCPreferenceHelper.m | 12 ++++---- Sources/BranchSDK/BNCRequestFactory.m | 6 ++-- Sources/BranchSDK/Branch.m | 4 +-- .../BranchSDK/Public/BNCPreferenceHelper.h | 2 +- Sources/BranchSDK/Public/Branch.h | 29 +++++++++++++------ 6 files changed, 33 insertions(+), 22 deletions(-) diff --git a/Branch-TestBed/Branch-TestBed/AppDelegate.m b/Branch-TestBed/Branch-TestBed/AppDelegate.m index a8c160cea..cc15ed19c 100644 --- a/Branch-TestBed/Branch-TestBed/AppDelegate.m +++ b/Branch-TestBed/Branch-TestBed/AppDelegate.m @@ -32,6 +32,8 @@ - (BOOL)application:(UIApplication *)application // Branch.useTestBranchKey = YES; // Make sure to comment this line out for production apps!!! Branch *branch = [Branch getInstance]; + [branch setConsumerProtectionPreference:BranchConsumerProtectionPreferenceNoAttribution]; + // Change the Branch base API URL //[Branch setAPIUrl:@"https://api3.branch.io"]; diff --git a/Sources/BranchSDK/BNCPreferenceHelper.m b/Sources/BranchSDK/BNCPreferenceHelper.m index fd3e33b91..ce707aafe 100644 --- a/Sources/BranchSDK/BNCPreferenceHelper.m +++ b/Sources/BranchSDK/BNCPreferenceHelper.m @@ -64,7 +64,7 @@ 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"; -static NSString * const BRANCH_PREFS_KEY_TRACKING_LEVEL = @"bnc_tracking_level"; +static NSString * const BRANCH_PREFS_KEY_CONSUMER_PROTECTION_PREFERENCE = @"bnc_consumer_protection_preference"; NSURL* /* _Nonnull */ BNCURLForBranchDirectory_Unthreaded(void); @@ -122,7 +122,7 @@ @implementation BNCPreferenceHelper eeaRegion = _eeaRegion, adPersonalizationConsent = _adPersonalizationConsent, adUserDataUsageConsent = _adUserDataUsageConsent, - trackingLevel = _trackingLevel; + consumerProtectionPreference = _consumerProtectionPreference; + (BNCPreferenceHelper *)sharedInstance { static BNCPreferenceHelper *preferenceHelper = nil; @@ -823,12 +823,12 @@ - (void) setAdUserDataUsageConsent:(BOOL)hasConsent { } } -- (NSInteger)trackingLevel { - return [self readIntegerFromDefaults:BRANCH_PREFS_KEY_TRACKING_LEVEL]; +- (NSInteger)consumerProtectionPreference { + return [self readIntegerFromDefaults:BRANCH_PREFS_KEY_CONSUMER_PROTECTION_PREFERENCE]; } -- (void)setTrackingLevel:(NSInteger)trackingLevel { - [self writeIntegerToDefaults:BRANCH_PREFS_KEY_TRACKING_LEVEL value:trackingLevel]; +- (void)setConsumerProtectionPreference:(NSInteger)consumerProtectionPreference { + [self writeIntegerToDefaults:BRANCH_PREFS_KEY_CONSUMER_PROTECTION_PREFERENCE value:consumerProtectionPreference]; } - (void) clearTrackingInformation { diff --git a/Sources/BranchSDK/BNCRequestFactory.m b/Sources/BranchSDK/BNCRequestFactory.m index 7ce5c62bc..34a19653b 100644 --- a/Sources/BranchSDK/BNCRequestFactory.m +++ b/Sources/BranchSDK/BNCRequestFactory.m @@ -414,10 +414,8 @@ - (void)addAppClipDataToJSON:(NSMutableDictionary *)json { - (void)addDefaultRequestDataToJSON:(NSMutableDictionary *)json { json[@"branch_key"] = self.branchKey; - if (self.preferenceHelper.trackingLevel) { - json[@"tracking_level"] = @(self.preferenceHelper.trackingLevel); - } else { - json[@"tracking_level"] = @(0); + if (self.preferenceHelper.consumerProtectionPreference) { + json[@"consumer_protection_preference"] = @(self.preferenceHelper.consumerProtectionPreference); } // omit field if value is NO diff --git a/Sources/BranchSDK/Branch.m b/Sources/BranchSDK/Branch.m index 25221b47a..7046d3a43 100644 --- a/Sources/BranchSDK/Branch.m +++ b/Sources/BranchSDK/Branch.m @@ -539,8 +539,8 @@ + (void) setDMAParamsForEEA:(BOOL)eeaRegion AdPersonalizationConsent:(BOOL)adPer [BNCPreferenceHelper sharedInstance].adUserDataUsageConsent = adUserDataUsageConsent; } -+ (void)setTrackingLevel:(BranchTrackingLevel)level { - [BNCPreferenceHelper sharedInstance].trackingLevel = level; +- (void)setConsumerProtectionPreference:(BranchConsumerProtectionPreference)consumerProtectionPreference { + self.preferenceHelper.consumerProtectionPreference = consumerProtectionPreference; } #pragma mark - InitSession Permutation methods diff --git a/Sources/BranchSDK/Public/BNCPreferenceHelper.h b/Sources/BranchSDK/Public/BNCPreferenceHelper.h index 3fa385a33..aa8ea9972 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 (assign, nonatomic) NSInteger trackingLevel; +@property (assign, nonatomic) NSInteger consumerProtectionPreference; - (void) clearTrackingInformation; diff --git a/Sources/BranchSDK/Public/Branch.h b/Sources/BranchSDK/Public/Branch.h index 5277c0b8a..1b750e888 100644 --- a/Sources/BranchSDK/Public/Branch.h +++ b/Sources/BranchSDK/Public/Branch.h @@ -812,21 +812,32 @@ Sets a custom base URL for all calls to the Branch API. */ + (void) setDMAParamsForEEA:(BOOL) eeaRegion AdPersonalizationConsent:(BOOL) adPersonalizationConsent AdUserDataUsageConsent:(BOOL) adUserDataUsageConsent; -typedef NS_ENUM(NSUInteger, BranchTrackingLevel) { - BranchTrackingLevelFull, - BranchTrackingLevelPrivacy, - BranchTrackingLevelAnalytics, - BranchTrackingLevelNone + +/** + * Enumeration representing different levels of consumer protection preferences + * for tracking and attribution. + * + * Full: + * Privacy Only: + * Attribution Only: + * No Attribution: + * + */ +typedef NS_ENUM(NSUInteger, BranchConsumerProtectionPreference) { + BranchConsumerProtectionPreferenceFull, + BranchConsumerProtectionPreferencePrivacyOnly, + BranchConsumerProtectionPreferenceAttributionOnly, + BranchConsumerProtectionPreferenceNoAttribution }; /** - Sets the tracking level for data collection. + Sets the consumer protection preference for tracking and attribution. - @param level The desired tracking level, represented by the BranchTrackingLevel enum (Full, Privacy, Analytics, None). + @param level The desired consumer protection preference, represented by the BranchConsumerProtectionPreference enum (Full, Privacy Only, Attribution Only, No Attribution). @discussion This method allows you to control the amount and type of data collected and transmitted by the SDK. - Adjusting the tracking level can help you comply with privacy regulations and meet your data collection needs. + Adjusting the consumer protection preference can help you comply with privacy regulations and meet your data collection needs. */ -+ (void)setTrackingLevel:(BranchTrackingLevel)level; +- (void)setConsumerProtectionPreference:(BranchConsumerProtectionPreference)level; #pragma mark - Session Item methods From d63978835c57c07a96573c18cd776aa1e89b901e Mon Sep 17 00:00:00 2001 From: nsingh-branch Date: Mon, 24 Jun 2024 17:28:56 -0700 Subject: [PATCH 03/19] Added tracking disabled ability --- Branch-TestBed/Branch-TestBed/AppDelegate.m | 2 - Branch-TestBed/Branch-TestBed/Main.storyboard | 62 ++++++++++++++----- .../Branch-TestBed/ViewController.m | 30 +++++++++ Sources/BranchSDK/BNCPreferenceHelper.m | 8 ++- Sources/BranchSDK/Branch.m | 36 ++++++++++- Sources/BranchSDK/Public/Branch.h | 4 +- 6 files changed, 118 insertions(+), 24 deletions(-) diff --git a/Branch-TestBed/Branch-TestBed/AppDelegate.m b/Branch-TestBed/Branch-TestBed/AppDelegate.m index cc15ed19c..a8c160cea 100644 --- a/Branch-TestBed/Branch-TestBed/AppDelegate.m +++ b/Branch-TestBed/Branch-TestBed/AppDelegate.m @@ -32,8 +32,6 @@ - (BOOL)application:(UIApplication *)application // Branch.useTestBranchKey = YES; // Make sure to comment this line out for production apps!!! Branch *branch = [Branch getInstance]; - [branch setConsumerProtectionPreference:BranchConsumerProtectionPreferenceNoAttribution]; - // Change the Branch base API URL //[Branch setAPIUrl:@"https://api3.branch.io"]; diff --git a/Branch-TestBed/Branch-TestBed/Main.storyboard b/Branch-TestBed/Branch-TestBed/Main.storyboard index 21f81550d..61bc70093 100644 --- a/Branch-TestBed/Branch-TestBed/Main.storyboard +++ b/Branch-TestBed/Branch-TestBed/Main.storyboard @@ -1,9 +1,9 @@ - + - + @@ -21,7 +21,7 @@ - + - + @@ -139,7 +139,7 @@ - + @@ -804,6 +804,35 @@ + + + + + + + + + + + + + + + + + @@ -832,7 +861,7 @@ - + @@ -848,10 +877,11 @@ + - + @@ -859,25 +889,25 @@ - - - - + + + + - + - + - + - + diff --git a/Branch-TestBed/Branch-TestBed/ViewController.m b/Branch-TestBed/Branch-TestBed/ViewController.m index da170e6d2..470c090fa 100644 --- a/Branch-TestBed/Branch-TestBed/ViewController.m +++ b/Branch-TestBed/Branch-TestBed/ViewController.m @@ -156,6 +156,36 @@ - (IBAction)goToPasteControlPressed:(id)sender { sender:self]; } +- (IBAction)changeConsumerProtectionPreference:(id)sender { + UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"Select Consumer Protection Preference" message:nil preferredStyle:UIAlertControllerStyleActionSheet]; + + UIAlertAction *fullAction = [UIAlertAction actionWithTitle:@"Full" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { + [Branch setConsumerProtectionPreference:BranchConsumerProtectionPreferenceFull]; + }]; + + UIAlertAction *privacyOnlyAction = [UIAlertAction actionWithTitle:@"Privacy Only" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { + [Branch setConsumerProtectionPreference:BranchConsumerProtectionPreferencePrivacyOnly]; + }]; + + UIAlertAction *attributionOnlyAction = [UIAlertAction actionWithTitle:@"Attribution Only" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { + [Branch setConsumerProtectionPreference:BranchConsumerProtectionPreferenceAttributionOnly]; + }]; + + UIAlertAction *noAttributionAction = [UIAlertAction actionWithTitle:@"No Attribution" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { + [Branch setConsumerProtectionPreference:BranchConsumerProtectionPreferenceNoAttribution]; + }]; + + UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]; + + [actionSheet addAction:fullAction]; + [actionSheet addAction:privacyOnlyAction]; + [actionSheet addAction:attributionOnlyAction]; + [actionSheet addAction:noAttributionAction]; + [actionSheet addAction:cancelAction]; + + [self presentViewController:actionSheet animated:YES completion:nil]; +} + -(IBAction)showVersionAlert:(id)sender { NSString *versionString = [NSString stringWithFormat:@"Branch SDK v%@\nBundle Version %@\niOS %@", BNC_SDK_VERSION, diff --git a/Sources/BranchSDK/BNCPreferenceHelper.m b/Sources/BranchSDK/BNCPreferenceHelper.m index ce707aafe..49b3dd4f8 100644 --- a/Sources/BranchSDK/BNCPreferenceHelper.m +++ b/Sources/BranchSDK/BNCPreferenceHelper.m @@ -824,11 +824,15 @@ - (void) setAdUserDataUsageConsent:(BOOL)hasConsent { } - (NSInteger)consumerProtectionPreference { - return [self readIntegerFromDefaults:BRANCH_PREFS_KEY_CONSUMER_PROTECTION_PREFERENCE]; + @synchronized(self) { + return [self readIntegerFromDefaults:BRANCH_PREFS_KEY_CONSUMER_PROTECTION_PREFERENCE]; + } } - (void)setConsumerProtectionPreference:(NSInteger)consumerProtectionPreference { - [self writeIntegerToDefaults:BRANCH_PREFS_KEY_CONSUMER_PROTECTION_PREFERENCE value:consumerProtectionPreference]; + @synchronized(self) { + [self writeIntegerToDefaults:BRANCH_PREFS_KEY_CONSUMER_PROTECTION_PREFERENCE value:consumerProtectionPreference]; + } } - (void) clearTrackingInformation { diff --git a/Sources/BranchSDK/Branch.m b/Sources/BranchSDK/Branch.m index 7046d3a43..c77341796 100644 --- a/Sources/BranchSDK/Branch.m +++ b/Sources/BranchSDK/Branch.m @@ -539,8 +539,40 @@ + (void) setDMAParamsForEEA:(BOOL)eeaRegion AdPersonalizationConsent:(BOOL)adPer [BNCPreferenceHelper sharedInstance].adUserDataUsageConsent = adUserDataUsageConsent; } -- (void)setConsumerProtectionPreference:(BranchConsumerProtectionPreference)consumerProtectionPreference { - self.preferenceHelper.consumerProtectionPreference = consumerProtectionPreference; ++ (void)setConsumerProtectionPreference:(BranchConsumerProtectionPreference)preference { + [BNCPreferenceHelper sharedInstance].consumerProtectionPreference = preference; + + [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Setting Branch Consumer Protection Preference to %lu", (unsigned long)preference] error:nil]; + + //Set tracking to disabled if consumer protection preference is changed to "No Attribution". Otherwise, keep tracking enabled. + if (preference == BranchConsumerProtectionPreferenceNoAttribution) { + if ([Branch trackingDisabled] == false) { + //Disable Tracking + [[BranchLogger shared] logVerbose:@"Disabling tracking due to No Attribution consumer protection preference." error:nil]; + + // Clear partner parameters + [[BNCPartnerParameters shared] clearAllParameters]; + + // Set the flag (which also clears the settings): + [BNCPreferenceHelper sharedInstance].trackingDisabled = YES; + Branch *branch = Branch.getInstance; + [branch clearNetworkQueue]; + branch.initializationStatus = BNCInitStatusUninitialized; + [branch.linkCache clear]; + // Release the lock in case it's locked: + [BranchOpenRequest releaseOpenResponseLock]; + } + } else { + if ([Branch trackingDisabled]) { + //Enable Tracking + [[BranchLogger shared] logVerbose:@"Enabling tracking due to change in consumer protection preference." error:nil]; + + // Set the flag: + [BNCPreferenceHelper sharedInstance].trackingDisabled = NO; + // Initialize a Branch session: + [Branch.getInstance initUserSessionAndCallCallback:NO sceneIdentifier:nil urlString:nil]; + } + } } #pragma mark - InitSession Permutation methods diff --git a/Sources/BranchSDK/Public/Branch.h b/Sources/BranchSDK/Public/Branch.h index 1b750e888..622fe6cde 100644 --- a/Sources/BranchSDK/Public/Branch.h +++ b/Sources/BranchSDK/Public/Branch.h @@ -785,7 +785,7 @@ Sets a custom base URL for all calls to the Branch API. @param disabled If set to `true` then tracking will be disabled. @warning This will prevent most of the Branch SDK functionality. */ -+ (void) setTrackingDisabled:(BOOL)disabled; ++ (void)setTrackingDisabled:(BOOL)disabled __attribute__((deprecated("This method has been deprecated. Use `setConsumerProtectionPreference:` instead."))); ///Returns the current tracking state. + (BOOL) trackingDisabled; @@ -837,7 +837,7 @@ typedef NS_ENUM(NSUInteger, BranchConsumerProtectionPreference) { @discussion This method allows you to control the amount and type of data collected and transmitted by the SDK. Adjusting the consumer protection preference can help you comply with privacy regulations and meet your data collection needs. */ -- (void)setConsumerProtectionPreference:(BranchConsumerProtectionPreference)level; ++ (void)setConsumerProtectionPreference:(BranchConsumerProtectionPreference)level; #pragma mark - Session Item methods From 716ffa76298e5570157f396d0ea5aafb9083fffb Mon Sep 17 00:00:00 2001 From: nsingh-branch Date: Tue, 25 Jun 2024 15:33:17 -0700 Subject: [PATCH 04/19] Updated naming and added test --- .../Branch-SDK-Tests/BranchClassTests.m | 20 ++++++++ .../Branch-TestBed/ViewController.m | 16 +++--- Sources/BranchSDK/BNCRequestFactory.m | 2 +- Sources/BranchSDK/Branch.m | 2 +- Sources/BranchSDK/Public/Branch.h | 51 +++++++++++++++---- 5 files changed, 71 insertions(+), 20 deletions(-) diff --git a/Branch-TestBed/Branch-SDK-Tests/BranchClassTests.m b/Branch-TestBed/Branch-SDK-Tests/BranchClassTests.m index 9d337a14e..7e754a129 100644 --- a/Branch-TestBed/Branch-SDK-Tests/BranchClassTests.m +++ b/Branch-TestBed/Branch-SDK-Tests/BranchClassTests.m @@ -241,4 +241,24 @@ - (void)testSetDMAParamsForEEA { [[BNCPreferenceHelper sharedInstance] writeObjectToDefaults:@"bnc_dma_ad_user_data" value:nil]; } +- (void)testSetConsumerProtectionPreference { + // Set to Privacy Attribution and check + [Branch setConsumerProtectionPreference:BranchConsumerProtectionPreferencePrivacyAttribution]; + XCTAssertEqual([BNCPreferenceHelper sharedInstance].consumerProtectionPreference, BranchConsumerProtectionPreferencePrivacyAttribution); + + // Set to Analytics Only and check + [Branch setConsumerProtectionPreference:BranchConsumerProtectionPreferenceAnalyticsOnly]; + XCTAssertEqual([BNCPreferenceHelper sharedInstance].consumerProtectionPreference, BranchConsumerProtectionPreferenceAnalyticsOnly); + + // Set to Tracking Disabled and check + [Branch setConsumerProtectionPreference:BranchConsumerProtectionPreferenceTrackingDisabled]; + XCTAssertEqual([BNCPreferenceHelper sharedInstance].consumerProtectionPreference, BranchConsumerProtectionPreferenceTrackingDisabled); + + // Set to Full Attribution and check + [Branch setConsumerProtectionPreference:BranchConsumerProtectionPreferenceFullAttribution]; + XCTAssertEqual([BNCPreferenceHelper sharedInstance].consumerProtectionPreference, BranchConsumerProtectionPreferenceFullAttribution); + +} + + @end diff --git a/Branch-TestBed/Branch-TestBed/ViewController.m b/Branch-TestBed/Branch-TestBed/ViewController.m index 470c090fa..3d6a50c91 100644 --- a/Branch-TestBed/Branch-TestBed/ViewController.m +++ b/Branch-TestBed/Branch-TestBed/ViewController.m @@ -159,20 +159,20 @@ - (IBAction)goToPasteControlPressed:(id)sender { - (IBAction)changeConsumerProtectionPreference:(id)sender { UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"Select Consumer Protection Preference" message:nil preferredStyle:UIAlertControllerStyleActionSheet]; - UIAlertAction *fullAction = [UIAlertAction actionWithTitle:@"Full" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { - [Branch setConsumerProtectionPreference:BranchConsumerProtectionPreferenceFull]; + UIAlertAction *fullAction = [UIAlertAction actionWithTitle:@"Full Attribution" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { + [Branch setConsumerProtectionPreference:BranchConsumerProtectionPreferenceFullAttribution]; }]; - UIAlertAction *privacyOnlyAction = [UIAlertAction actionWithTitle:@"Privacy Only" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { - [Branch setConsumerProtectionPreference:BranchConsumerProtectionPreferencePrivacyOnly]; + UIAlertAction *privacyOnlyAction = [UIAlertAction actionWithTitle:@"Privacy Attribution" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { + [Branch setConsumerProtectionPreference:BranchConsumerProtectionPreferencePrivacyAttribution]; }]; - UIAlertAction *attributionOnlyAction = [UIAlertAction actionWithTitle:@"Attribution Only" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { - [Branch setConsumerProtectionPreference:BranchConsumerProtectionPreferenceAttributionOnly]; + UIAlertAction *attributionOnlyAction = [UIAlertAction actionWithTitle:@"Analytics Only" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { + [Branch setConsumerProtectionPreference:BranchConsumerProtectionPreferenceAnalyticsOnly]; }]; - UIAlertAction *noAttributionAction = [UIAlertAction actionWithTitle:@"No Attribution" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { - [Branch setConsumerProtectionPreference:BranchConsumerProtectionPreferenceNoAttribution]; + UIAlertAction *noAttributionAction = [UIAlertAction actionWithTitle:@"Tracking Disabled" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { + [Branch setConsumerProtectionPreference:BranchConsumerProtectionPreferenceTrackingDisabled]; }]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]; diff --git a/Sources/BranchSDK/BNCRequestFactory.m b/Sources/BranchSDK/BNCRequestFactory.m index 34a19653b..46b6a7cbd 100644 --- a/Sources/BranchSDK/BNCRequestFactory.m +++ b/Sources/BranchSDK/BNCRequestFactory.m @@ -415,7 +415,7 @@ - (void)addDefaultRequestDataToJSON:(NSMutableDictionary *)json { json[@"branch_key"] = self.branchKey; if (self.preferenceHelper.consumerProtectionPreference) { - json[@"consumer_protection_preference"] = @(self.preferenceHelper.consumerProtectionPreference); + json[@"protection_preference"] = @(self.preferenceHelper.consumerProtectionPreference); } // omit field if value is NO diff --git a/Sources/BranchSDK/Branch.m b/Sources/BranchSDK/Branch.m index c77341796..e81dc374a 100644 --- a/Sources/BranchSDK/Branch.m +++ b/Sources/BranchSDK/Branch.m @@ -545,7 +545,7 @@ + (void)setConsumerProtectionPreference:(BranchConsumerProtectionPreference)pref [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Setting Branch Consumer Protection Preference to %lu", (unsigned long)preference] error:nil]; //Set tracking to disabled if consumer protection preference is changed to "No Attribution". Otherwise, keep tracking enabled. - if (preference == BranchConsumerProtectionPreferenceNoAttribution) { + if (preference == BranchConsumerProtectionPreferenceTrackingDisabled) { if ([Branch trackingDisabled] == false) { //Disable Tracking [[BranchLogger shared] logVerbose:@"Disabling tracking due to No Attribution consumer protection preference." error:nil]; diff --git a/Sources/BranchSDK/Public/Branch.h b/Sources/BranchSDK/Public/Branch.h index 622fe6cde..b062a95fc 100644 --- a/Sources/BranchSDK/Public/Branch.h +++ b/Sources/BranchSDK/Public/Branch.h @@ -816,20 +816,51 @@ Sets a custom base URL for all calls to the Branch API. /** * Enumeration representing different levels of consumer protection preferences * for tracking and attribution. - * - * Full: - * Privacy Only: - * Attribution Only: - * No Attribution: - * */ typedef NS_ENUM(NSUInteger, BranchConsumerProtectionPreference) { - BranchConsumerProtectionPreferenceFull, - BranchConsumerProtectionPreferencePrivacyOnly, - BranchConsumerProtectionPreferenceAttributionOnly, - BranchConsumerProtectionPreferenceNoAttribution + /** + * Full Attribution: + * - 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 + */ + BranchConsumerProtectionPreferenceFullAttribution, + + /** + * Privacy Attribution: + * - Device Ids + * - Local IP + * - Data Integrations Webhooks + * - Privacy Frameworks + * - Deep Linking + */ + BranchConsumerProtectionPreferencePrivacyAttribution, + + /** + * Analytics Only: + * - Device Ids + * - Local IP + * - Data Integrations Webhooks + * - Deep Linking + */ + BranchConsumerProtectionPreferenceAnalyticsOnly, + + /** + * Tracking Disabled: + * - Only Deterministic Deep Linking + * - Disables all other Branch requests + */ + BranchConsumerProtectionPreferenceTrackingDisabled }; + /** Sets the consumer protection preference for tracking and attribution. From cd43452693f3e436656fdd9f41646ac365ef2caa Mon Sep 17 00:00:00 2001 From: nsingh-branch Date: Wed, 26 Jun 2024 13:14:15 -0700 Subject: [PATCH 05/19] Updated naming --- .../Branch-SDK-Tests/BranchClassTests.m | 26 +++++++-------- Branch-TestBed/Branch-TestBed/Main.storyboard | 2 +- .../Branch-TestBed/ViewController.m | 20 +++++------ Sources/BranchSDK/BNCPreferenceHelper.m | 12 +++---- Sources/BranchSDK/BNCRequestFactory.m | 4 +-- Sources/BranchSDK/Branch.m | 14 ++++---- .../BranchSDK/Public/BNCPreferenceHelper.h | 2 +- Sources/BranchSDK/Public/Branch.h | 33 +++++++++---------- 8 files changed, 56 insertions(+), 57 deletions(-) diff --git a/Branch-TestBed/Branch-SDK-Tests/BranchClassTests.m b/Branch-TestBed/Branch-SDK-Tests/BranchClassTests.m index 7e754a129..447034fa6 100644 --- a/Branch-TestBed/Branch-SDK-Tests/BranchClassTests.m +++ b/Branch-TestBed/Branch-SDK-Tests/BranchClassTests.m @@ -241,22 +241,22 @@ - (void)testSetDMAParamsForEEA { [[BNCPreferenceHelper sharedInstance] writeObjectToDefaults:@"bnc_dma_ad_user_data" value:nil]; } -- (void)testSetConsumerProtectionPreference { - // Set to Privacy Attribution and check - [Branch setConsumerProtectionPreference:BranchConsumerProtectionPreferencePrivacyAttribution]; - XCTAssertEqual([BNCPreferenceHelper sharedInstance].consumerProtectionPreference, BranchConsumerProtectionPreferencePrivacyAttribution); +- (void)testSetConsumerProtectionAttributionLevel { + // Set to Reduced and check + [Branch setConsumerProtectionAttributionLevel:BranchAttributionLevelReduced]; + XCTAssertEqual([BNCPreferenceHelper sharedInstance].attributionLevel, BranchAttributionLevelReduced); - // Set to Analytics Only and check - [Branch setConsumerProtectionPreference:BranchConsumerProtectionPreferenceAnalyticsOnly]; - XCTAssertEqual([BNCPreferenceHelper sharedInstance].consumerProtectionPreference, BranchConsumerProtectionPreferenceAnalyticsOnly); + // Set to Minimal and check + [Branch setConsumerProtectionAttributionLevel:BranchAttributionLevelMinimal]; + XCTAssertEqual([BNCPreferenceHelper sharedInstance].attributionLevel, BranchAttributionLevelMinimal); - // Set to Tracking Disabled and check - [Branch setConsumerProtectionPreference:BranchConsumerProtectionPreferenceTrackingDisabled]; - XCTAssertEqual([BNCPreferenceHelper sharedInstance].consumerProtectionPreference, BranchConsumerProtectionPreferenceTrackingDisabled); + // Set to None and check + [Branch setConsumerProtectionAttributionLevel:BranchAttributionLevelNone]; + XCTAssertEqual([BNCPreferenceHelper sharedInstance].attributionLevel, BranchAttributionLevelNone); - // Set to Full Attribution and check - [Branch setConsumerProtectionPreference:BranchConsumerProtectionPreferenceFullAttribution]; - XCTAssertEqual([BNCPreferenceHelper sharedInstance].consumerProtectionPreference, BranchConsumerProtectionPreferenceFullAttribution); + // Set to Full and check + [Branch setConsumerProtectionAttributionLevel:BranchAttributionLevelFull]; + XCTAssertEqual([BNCPreferenceHelper sharedInstance].attributionLevel, BranchAttributionLevelFull); } diff --git a/Branch-TestBed/Branch-TestBed/Main.storyboard b/Branch-TestBed/Branch-TestBed/Main.storyboard index 61bc70093..d107e52fa 100644 --- a/Branch-TestBed/Branch-TestBed/Main.storyboard +++ b/Branch-TestBed/Branch-TestBed/Main.storyboard @@ -820,7 +820,7 @@ - + diff --git a/Branch-TestBed/Branch-TestBed/ViewController.m b/Branch-TestBed/Branch-TestBed/ViewController.m index 3d6a50c91..71f295b0e 100644 --- a/Branch-TestBed/Branch-TestBed/ViewController.m +++ b/Branch-TestBed/Branch-TestBed/ViewController.m @@ -156,23 +156,23 @@ - (IBAction)goToPasteControlPressed:(id)sender { sender:self]; } -- (IBAction)changeConsumerProtectionPreference:(id)sender { - UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"Select Consumer Protection Preference" message:nil preferredStyle:UIAlertControllerStyleActionSheet]; +- (IBAction)changeConsumerProtectionAttributionLevel:(id)sender { + UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"Select Consumer Protection Attribution Level" message:nil preferredStyle:UIAlertControllerStyleActionSheet]; - UIAlertAction *fullAction = [UIAlertAction actionWithTitle:@"Full Attribution" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { - [Branch setConsumerProtectionPreference:BranchConsumerProtectionPreferenceFullAttribution]; + UIAlertAction *fullAction = [UIAlertAction actionWithTitle:@"Full" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { + [Branch setConsumerProtectionAttributionLevel:BranchAttributionLevelFull]; }]; - UIAlertAction *privacyOnlyAction = [UIAlertAction actionWithTitle:@"Privacy Attribution" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { - [Branch setConsumerProtectionPreference:BranchConsumerProtectionPreferencePrivacyAttribution]; + UIAlertAction *privacyOnlyAction = [UIAlertAction actionWithTitle:@"Reduced" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { + [Branch setConsumerProtectionAttributionLevel:BranchAttributionLevelReduced]; }]; - UIAlertAction *attributionOnlyAction = [UIAlertAction actionWithTitle:@"Analytics Only" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { - [Branch setConsumerProtectionPreference:BranchConsumerProtectionPreferenceAnalyticsOnly]; + UIAlertAction *attributionOnlyAction = [UIAlertAction actionWithTitle:@"Minimal" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { + [Branch setConsumerProtectionAttributionLevel:BranchAttributionLevelMinimal]; }]; - UIAlertAction *noAttributionAction = [UIAlertAction actionWithTitle:@"Tracking Disabled" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { - [Branch setConsumerProtectionPreference:BranchConsumerProtectionPreferenceTrackingDisabled]; + UIAlertAction *noAttributionAction = [UIAlertAction actionWithTitle:@"None" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { + [Branch setConsumerProtectionAttributionLevel:BranchAttributionLevelNone]; }]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]; diff --git a/Sources/BranchSDK/BNCPreferenceHelper.m b/Sources/BranchSDK/BNCPreferenceHelper.m index 49b3dd4f8..ae80cc5b8 100644 --- a/Sources/BranchSDK/BNCPreferenceHelper.m +++ b/Sources/BranchSDK/BNCPreferenceHelper.m @@ -64,7 +64,7 @@ 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"; -static NSString * const BRANCH_PREFS_KEY_CONSUMER_PROTECTION_PREFERENCE = @"bnc_consumer_protection_preference"; +static NSString * const BRANCH_PREFS_KEY_ATTRIBUTION_LEVEL = @"bnc_attribution_level"; NSURL* /* _Nonnull */ BNCURLForBranchDirectory_Unthreaded(void); @@ -122,7 +122,7 @@ @implementation BNCPreferenceHelper eeaRegion = _eeaRegion, adPersonalizationConsent = _adPersonalizationConsent, adUserDataUsageConsent = _adUserDataUsageConsent, - consumerProtectionPreference = _consumerProtectionPreference; + attributionLevel = _attributionLevel; + (BNCPreferenceHelper *)sharedInstance { static BNCPreferenceHelper *preferenceHelper = nil; @@ -823,15 +823,15 @@ - (void) setAdUserDataUsageConsent:(BOOL)hasConsent { } } -- (NSInteger)consumerProtectionPreference { +- (NSInteger)attributionLevel { @synchronized(self) { - return [self readIntegerFromDefaults:BRANCH_PREFS_KEY_CONSUMER_PROTECTION_PREFERENCE]; + return [self readIntegerFromDefaults:BRANCH_PREFS_KEY_ATTRIBUTION_LEVEL]; } } -- (void)setConsumerProtectionPreference:(NSInteger)consumerProtectionPreference { +- (void)attributionLevel:(NSInteger)level { @synchronized(self) { - [self writeIntegerToDefaults:BRANCH_PREFS_KEY_CONSUMER_PROTECTION_PREFERENCE value:consumerProtectionPreference]; + [self writeIntegerToDefaults:BRANCH_PREFS_KEY_ATTRIBUTION_LEVEL value:level]; } } diff --git a/Sources/BranchSDK/BNCRequestFactory.m b/Sources/BranchSDK/BNCRequestFactory.m index 46b6a7cbd..d74e279a1 100644 --- a/Sources/BranchSDK/BNCRequestFactory.m +++ b/Sources/BranchSDK/BNCRequestFactory.m @@ -414,8 +414,8 @@ - (void)addAppClipDataToJSON:(NSMutableDictionary *)json { - (void)addDefaultRequestDataToJSON:(NSMutableDictionary *)json { json[@"branch_key"] = self.branchKey; - if (self.preferenceHelper.consumerProtectionPreference) { - json[@"protection_preference"] = @(self.preferenceHelper.consumerProtectionPreference); + if (self.preferenceHelper.attributionLevel) { + json[@"consumer_protection_attribution_level"] = @(self.preferenceHelper.attributionLevel); } // omit field if value is NO diff --git a/Sources/BranchSDK/Branch.m b/Sources/BranchSDK/Branch.m index e81dc374a..8c25b63b5 100644 --- a/Sources/BranchSDK/Branch.m +++ b/Sources/BranchSDK/Branch.m @@ -539,16 +539,16 @@ + (void) setDMAParamsForEEA:(BOOL)eeaRegion AdPersonalizationConsent:(BOOL)adPer [BNCPreferenceHelper sharedInstance].adUserDataUsageConsent = adUserDataUsageConsent; } -+ (void)setConsumerProtectionPreference:(BranchConsumerProtectionPreference)preference { - [BNCPreferenceHelper sharedInstance].consumerProtectionPreference = preference; ++ (void)setConsumerProtectionAttributionLevel:(BranchAttributionLevel)level { + [BNCPreferenceHelper sharedInstance].attributionLevel = level; - [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Setting Branch Consumer Protection Preference to %lu", (unsigned long)preference] error:nil]; + [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Setting Consumer Protection Attribution Level to %lu", (unsigned long)level] error:nil]; - //Set tracking to disabled if consumer protection preference is changed to "No Attribution". Otherwise, keep tracking enabled. - if (preference == BranchConsumerProtectionPreferenceTrackingDisabled) { + //Set tracking to disabled if consumer protection attribution level is changed to BranchAttributionLevelNone. Otherwise, keep tracking enabled. + if (level == BranchAttributionLevelNone) { if ([Branch trackingDisabled] == false) { //Disable Tracking - [[BranchLogger shared] logVerbose:@"Disabling tracking due to No Attribution consumer protection preference." error:nil]; + [[BranchLogger shared] logVerbose:@"Disabling tracking due to Consumer Protection Attribution Level being BranchAttributionLevelNone." error:nil]; // Clear partner parameters [[BNCPartnerParameters shared] clearAllParameters]; @@ -565,7 +565,7 @@ + (void)setConsumerProtectionPreference:(BranchConsumerProtectionPreference)pref } else { if ([Branch trackingDisabled]) { //Enable Tracking - [[BranchLogger shared] logVerbose:@"Enabling tracking due to change in consumer protection preference." error:nil]; + [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Enabling tracking due to Consumer Protection Attribution Level being %lu.", (unsigned long)level] error:nil]; // Set the flag: [BNCPreferenceHelper sharedInstance].trackingDisabled = NO; diff --git a/Sources/BranchSDK/Public/BNCPreferenceHelper.h b/Sources/BranchSDK/Public/BNCPreferenceHelper.h index aa8ea9972..a84cdc0a8 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 (assign, nonatomic) NSInteger consumerProtectionPreference; +@property (assign, nonatomic) NSInteger attributionLevel; - (void) clearTrackingInformation; diff --git a/Sources/BranchSDK/Public/Branch.h b/Sources/BranchSDK/Public/Branch.h index b062a95fc..9eecc9df5 100644 --- a/Sources/BranchSDK/Public/Branch.h +++ b/Sources/BranchSDK/Public/Branch.h @@ -785,7 +785,7 @@ Sets a custom base URL for all calls to the Branch API. @param disabled If set to `true` then tracking will be disabled. @warning This will prevent most of the Branch SDK functionality. */ -+ (void)setTrackingDisabled:(BOOL)disabled __attribute__((deprecated("This method has been deprecated. Use `setConsumerProtectionPreference:` instead."))); ++ (void)setTrackingDisabled:(BOOL)disabled __attribute__((deprecated("This method has been deprecated. Use `setConsumerProtectionAttributionLevel:` instead."))); ///Returns the current tracking state. + (BOOL) trackingDisabled; @@ -814,12 +814,11 @@ Sets a custom base URL for all calls to the Branch API. /** - * Enumeration representing different levels of consumer protection preferences - * for tracking and attribution. + * Enumeration representing different levels of consumer protection attribution levels */ -typedef NS_ENUM(NSUInteger, BranchConsumerProtectionPreference) { +typedef NS_ENUM(NSUInteger, BranchAttributionLevel) { /** - * Full Attribution: + * Full: * - Advertising Ids * - Device Ids * - Local IP @@ -831,44 +830,44 @@ typedef NS_ENUM(NSUInteger, BranchConsumerProtectionPreference) { * - Privacy Frameworks * - Deep Linking */ - BranchConsumerProtectionPreferenceFullAttribution, + BranchAttributionLevelFull, /** - * Privacy Attribution: + * Reuced: * - Device Ids * - Local IP * - Data Integrations Webhooks * - Privacy Frameworks * - Deep Linking */ - BranchConsumerProtectionPreferencePrivacyAttribution, + BranchAttributionLevelReduced, /** - * Analytics Only: + * Minimal: * - Device Ids * - Local IP * - Data Integrations Webhooks * - Deep Linking */ - BranchConsumerProtectionPreferenceAnalyticsOnly, + BranchAttributionLevelMinimal, /** - * Tracking Disabled: + * None: * - Only Deterministic Deep Linking * - Disables all other Branch requests */ - BranchConsumerProtectionPreferenceTrackingDisabled + BranchAttributionLevelNone }; /** - Sets the consumer protection preference for tracking and attribution. + Sets the consumer protection attribution level. - @param level The desired consumer protection preference, represented by the BranchConsumerProtectionPreference enum (Full, Privacy Only, Attribution Only, No Attribution). - @discussion This method allows you to control the amount and type of data collected and transmitted by the SDK. - Adjusting the consumer protection preference can help you comply with privacy regulations and meet your data collection needs. + @param level The desired consumer protection attribution level, represented by the BranchAttributionLevel enum (Full, Reduced, Minimal, None). + @discussion This method allows you to control the amount and type of data collected and transmitted by Branch. + Adjusting the consumer protection attribution level can help you comply with privacy regulations and meet your data collection needs. */ -+ (void)setConsumerProtectionPreference:(BranchConsumerProtectionPreference)level; ++ (void)setConsumerProtectionAttributionLevel:(BranchAttributionLevel)level; #pragma mark - Session Item methods From a7fa56956fb16b47c0fe51cfc1ac84b725477d42 Mon Sep 17 00:00:00 2001 From: nsingh-branch Date: Wed, 26 Jun 2024 13:15:14 -0700 Subject: [PATCH 06/19] Updated logs --- Sources/BranchSDK/Branch.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/BranchSDK/Branch.m b/Sources/BranchSDK/Branch.m index 8c25b63b5..b1a5f0b26 100644 --- a/Sources/BranchSDK/Branch.m +++ b/Sources/BranchSDK/Branch.m @@ -548,7 +548,7 @@ + (void)setConsumerProtectionAttributionLevel:(BranchAttributionLevel)level { if (level == BranchAttributionLevelNone) { if ([Branch trackingDisabled] == false) { //Disable Tracking - [[BranchLogger shared] logVerbose:@"Disabling tracking due to Consumer Protection Attribution Level being BranchAttributionLevelNone." error:nil]; + [[BranchLogger shared] logVerbose:@"Disabling attribution events due to Consumer Protection Attribution Level being BranchAttributionLevelNone." error:nil]; // Clear partner parameters [[BNCPartnerParameters shared] clearAllParameters]; @@ -565,7 +565,7 @@ + (void)setConsumerProtectionAttributionLevel:(BranchAttributionLevel)level { } else { if ([Branch trackingDisabled]) { //Enable Tracking - [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Enabling tracking 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 %lu.", (unsigned long)level] error:nil]; // Set the flag: [BNCPreferenceHelper sharedInstance].trackingDisabled = NO; From ea7a764195102df62d588bb11a0404f6f69907b8 Mon Sep 17 00:00:00 2001 From: nsingh-branch Date: Wed, 26 Jun 2024 16:56:12 -0700 Subject: [PATCH 07/19] Fixed bug and updated automation testbed --- .gitignore | 1 + Branch-TestBed/Branch-TestBed/AppDelegate.m | 8 +- .../Branch-TestBed/ViewController.m | 9 ++- .../DeepLinkDemo.xcodeproj/project.pbxproj | 2 - .../DeepLinkDemo/Base.lproj/Main.storyboard | 73 +++++++++++------- .../Controllers/HomeViewController.swift | 77 ++++++++++++++++++- .../Controllers/TextViewController.swift | 5 +- DeepLinkDemo/Podfile.lock | 15 +++- Sources/BranchSDK/BNCPreferenceHelper.m | 10 +-- Sources/BranchSDK/BNCRequestFactory.m | 4 +- Sources/BranchSDK/Branch.m | 11 +-- .../BranchSDK/Public/BNCPreferenceHelper.h | 2 +- Sources/BranchSDK/Public/Branch.h | 12 +-- 13 files changed, 166 insertions(+), 63 deletions(-) diff --git a/.gitignore b/.gitignore index 7ae2cfc57..041577f4e 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,4 @@ fastlane/test_output # Ruby stuff vendor .bundle +DeepLinkDemo/DeepLinkDemo.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings diff --git a/Branch-TestBed/Branch-TestBed/AppDelegate.m b/Branch-TestBed/Branch-TestBed/AppDelegate.m index a8c160cea..9fe650773 100644 --- a/Branch-TestBed/Branch-TestBed/AppDelegate.m +++ b/Branch-TestBed/Branch-TestBed/AppDelegate.m @@ -32,12 +32,15 @@ - (BOOL)application:(UIApplication *)application // Branch.useTestBranchKey = YES; // Make sure to comment this line out for production apps!!! Branch *branch = [Branch getInstance]; + // Change the Branch base API URL //[Branch setAPIUrl:@"https://api3.branch.io"]; // test pre init support //[self testDispatchToIsolationQueue:branch] - [branch enableLoggingAtLevel:BranchLogLevelVerbose withCallback:^(NSString * _Nonnull message, BranchLogLevel logLevel, NSError * _Nullable error) { + + + [Branch enableLoggingAtLevel:BranchLogLevelVerbose withCallback:^(NSString * _Nonnull message, BranchLogLevel logLevel, NSError * _Nullable error) { // Handle the log message and error here. For example, printing to the console: if (error) { NSLog(@"[BranchLog] Level: %lu, Message: %@, Error: %@", (unsigned long)logLevel, message, error.localizedDescription); @@ -46,6 +49,7 @@ - (BOOL)application:(UIApplication *)application } }]; + // Comment out in production. Un-comment to test your Branch SDK Integration: //[branch validateSDKIntegration]; @@ -62,6 +66,8 @@ - (BOOL)application:(UIApplication *)application [branch setIdentity:@"Bobby Branch"]; + //[branch setConsumerProtectionAttributionLevel:BranchAttributionLevelReduced]; + [branch initSessionWithLaunchOptions:launchOptions andRegisterDeepLinkHandlerUsingBranchUniversalObject: ^ (BranchUniversalObject * _Nullable universalObject, BranchLinkProperties * _Nullable linkProperties, NSError * _Nullable error) { diff --git a/Branch-TestBed/Branch-TestBed/ViewController.m b/Branch-TestBed/Branch-TestBed/ViewController.m index 71f295b0e..a78b7f7a3 100644 --- a/Branch-TestBed/Branch-TestBed/ViewController.m +++ b/Branch-TestBed/Branch-TestBed/ViewController.m @@ -157,22 +157,23 @@ - (IBAction)goToPasteControlPressed:(id)sender { } - (IBAction)changeConsumerProtectionAttributionLevel:(id)sender { + Branch *branch = [Branch getInstance]; UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"Select Consumer Protection Attribution Level" message:nil preferredStyle:UIAlertControllerStyleActionSheet]; UIAlertAction *fullAction = [UIAlertAction actionWithTitle:@"Full" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { - [Branch setConsumerProtectionAttributionLevel:BranchAttributionLevelFull]; + [branch setConsumerProtectionAttributionLevel:BranchAttributionLevelFull]; }]; UIAlertAction *privacyOnlyAction = [UIAlertAction actionWithTitle:@"Reduced" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { - [Branch setConsumerProtectionAttributionLevel:BranchAttributionLevelReduced]; + [branch setConsumerProtectionAttributionLevel:BranchAttributionLevelReduced]; }]; UIAlertAction *attributionOnlyAction = [UIAlertAction actionWithTitle:@"Minimal" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { - [Branch setConsumerProtectionAttributionLevel:BranchAttributionLevelMinimal]; + [branch setConsumerProtectionAttributionLevel:BranchAttributionLevelMinimal]; }]; UIAlertAction *noAttributionAction = [UIAlertAction actionWithTitle:@"None" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { - [Branch setConsumerProtectionAttributionLevel:BranchAttributionLevelNone]; + [branch setConsumerProtectionAttributionLevel:BranchAttributionLevelNone]; }]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]; diff --git a/DeepLinkDemo/DeepLinkDemo.xcodeproj/project.pbxproj b/DeepLinkDemo/DeepLinkDemo.xcodeproj/project.pbxproj index 5820cf513..6117713fe 100644 --- a/DeepLinkDemo/DeepLinkDemo.xcodeproj/project.pbxproj +++ b/DeepLinkDemo/DeepLinkDemo.xcodeproj/project.pbxproj @@ -73,7 +73,6 @@ B7B7DC292859974E00D45FC5 /* TextViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextViewController.swift; sourceTree = ""; }; C06885D21868B25319262FC1 /* Pods-DeepLinkDemo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DeepLinkDemo.debug.xcconfig"; path = "Target Support Files/Pods-DeepLinkDemo/Pods-DeepLinkDemo.debug.xcconfig"; sourceTree = ""; }; DDBB5A837B0C008CA5BEC1EF /* Pods_DeepLinkDemo.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_DeepLinkDemo.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - E70E80C12A0E22C1008007B6 /* BranchSDK.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = BranchSDK.xcframework; path = Framework/BranchSDK.xcframework; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -101,7 +100,6 @@ 29D53CAAE9E9EF2F96296086 /* Frameworks */ = { isa = PBXGroup; children = ( - E70E80C12A0E22C1008007B6 /* BranchSDK.xcframework */, DDBB5A837B0C008CA5BEC1EF /* Pods_DeepLinkDemo.framework */, ); name = Frameworks; diff --git a/DeepLinkDemo/DeepLinkDemo/Base.lproj/Main.storyboard b/DeepLinkDemo/DeepLinkDemo/Base.lproj/Main.storyboard index 0e799346b..7c5844536 100644 --- a/DeepLinkDemo/DeepLinkDemo/Base.lproj/Main.storyboard +++ b/DeepLinkDemo/DeepLinkDemo/Base.lproj/Main.storyboard @@ -1,9 +1,9 @@ - + - + @@ -882,20 +882,20 @@ - + - - + + - + @@ -1126,6 +1142,7 @@ + @@ -1134,6 +1151,7 @@ + @@ -1142,13 +1160,14 @@ + - + @@ -1158,6 +1177,7 @@ + @@ -1168,7 +1188,7 @@ - + @@ -1182,7 +1202,7 @@ - + @@ -1193,6 +1213,7 @@ + @@ -2649,16 +2670,16 @@ - + - + - + diff --git a/DeepLinkDemo/DeepLinkDemo/Controllers/HomeViewController.swift b/DeepLinkDemo/DeepLinkDemo/Controllers/HomeViewController.swift index ba4fadea3..ca6ce160b 100644 --- a/DeepLinkDemo/DeepLinkDemo/Controllers/HomeViewController.swift +++ b/DeepLinkDemo/DeepLinkDemo/Controllers/HomeViewController.swift @@ -21,6 +21,7 @@ class HomeViewController: UITableViewController { @IBOutlet weak var btnReadLog: UIButton! @IBOutlet weak var btnSetDMAParams: UIButton! @IBOutlet weak var btnSendV2Event: UIButton! + @IBOutlet weak var btnSetAttributionLevel: UIButton! @IBOutlet weak var switchControl: UISwitch! @@ -47,6 +48,7 @@ class HomeViewController: UITableViewController { btnLoadWebView.layer.cornerRadius = 8.0 btnSetDMAParams.layer.cornerRadius = 8.0 btnSendV2Event.layer.cornerRadius = 8.0 + btnSetAttributionLevel.layer.cornerRadius = 8.0 NotificationCenter.default.addObserver(self, selector: #selector(self.methodOfReceivedNotification(notification:)), name: Notification.Name("NotificationIdentifier"), object: nil) @@ -131,7 +133,9 @@ class HomeViewController: UITableViewController { self.setDMAParamsWrapper() } else if textValue == "sendV2Event" { self.sendV2EventWrapper() - } + } else if textValue == "setAttributionLevel" { + self.setAttributionLevelWrapper() + } } } @@ -159,10 +163,9 @@ class HomeViewController: UITableViewController { } func enableBranchLogging(callback: @escaping BranchLogCallback){ - BranchLogger.shared().loggingEnabled = true - BranchLogger.shared().logLevelThreshold = .verbose - BranchLogger.shared().logCallback = callback + Branch.enableLogging(at: .verbose, withCallback: callback) } + func initBranch(){ if branchSDKInitialized { return @@ -195,6 +198,68 @@ class HomeViewController: UITableViewController { event.logEvent() } + func setAttributionLevelWrapper() { + self.logData = "Error: Missing testData.\n" + + let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil) + let vc = storyBoard.instantiateViewController(withIdentifier: "TextViewController") as? TextViewController + vc?.isSetAttributionLevel = true + + do { + let argCount = ProcessInfo.processInfo.arguments.count + if argCount >= 2 { + + for i in (1 ..< argCount) { + let data = ProcessInfo.processInfo.arguments[i].data(using: .utf8)! + + if let jsonObject = try JSONSerialization.jsonObject(with: data, options : .allowFragments) as? [String:AnyObject] + { + if jsonObject["consumer_protection_attribution_level"] != nil { + let attribution_level = jsonObject["consumer_protection_attribution_level"] as! Int + self.logData = "" + self.enableBranchLogging(){(msg:String,msg2:BranchLogLevel,msg3:Error?)->() in + if (msg.contains("BranchSDK")){ + self.logData = self.logData + msg + "\n" + } + vc?.updateText(msg: self.logData) + } + if(self.branchSDKInitialized){ + Branch.getInstance().resetUserSession() + } + + switch attribution_level { + case 0: + Branch.getInstance().setConsumerProtectionAttributionLevel(.full) + case 1: + Branch.getInstance().setConsumerProtectionAttributionLevel(.reduced) + case 2: + Branch.getInstance().setConsumerProtectionAttributionLevel(.minimal) + case 3: + Branch.getInstance().setConsumerProtectionAttributionLevel(.none) + default: + Branch.getInstance().setConsumerProtectionAttributionLevel(.full) + } + + AppDelegate.shared.getBranchData(AppDelegate.shared.launchOption) + self.branchSDKInitialized = true + } else { + self.logData = "Missing params from JSON Object: \n" + jsonObject.description + } + } else { + self.logData = "Bad JSON : \n" + ProcessInfo.processInfo.arguments[i] + } + } + + + } + } catch let error as NSError { + print(error) + self.logData += error.localizedDescription + } + vc?.updateText(msg: self.logData) + self.navigationController?.pushViewController(vc!, animated: true) + } + func setDMAParamsWrapper() { self.logData = "Error: Missing testData.\n" @@ -367,6 +432,10 @@ class HomeViewController: UITableViewController { @IBAction func sendV2Event(){ reachabilityCheck(textValue: "sendV2Event") } + + @IBAction func setAttributionLevel(){ + reachabilityCheck(textValue: "setAttributionLevel") + } } extension UITextField { diff --git a/DeepLinkDemo/DeepLinkDemo/Controllers/TextViewController.swift b/DeepLinkDemo/DeepLinkDemo/Controllers/TextViewController.swift index 375a29036..b55b15c90 100644 --- a/DeepLinkDemo/DeepLinkDemo/Controllers/TextViewController.swift +++ b/DeepLinkDemo/DeepLinkDemo/Controllers/TextViewController.swift @@ -23,7 +23,8 @@ class TextViewController: UIViewController { var isTrackUser = false var isSetDMAParams = false var isSendV2Event = false - + var isSetAttributionLevel = false + var url = "" var responseStatus = "" var dictData = [String:Any]() @@ -68,6 +69,8 @@ class TextViewController: UIViewController { self.navigationController?.popToRootViewController(animated: true) } else if self.isSendV2Event == true { self.navigationController?.popToRootViewController(animated: true) + } else if self.isSetAttributionLevel == true { + self.navigationController?.popToRootViewController(animated: true) } else { launchReadVC() diff --git a/DeepLinkDemo/Podfile.lock b/DeepLinkDemo/Podfile.lock index 41cac458e..e5b283e13 100644 --- a/DeepLinkDemo/Podfile.lock +++ b/DeepLinkDemo/Podfile.lock @@ -1,16 +1,23 @@ PODS: - - IQKeyboardManager (6.5.15) + - BranchSDK (3.4.4) + - IQKeyboardManager (6.5.19) DEPENDENCIES: + - BranchSDK (from `./../`) - IQKeyboardManager SPEC REPOS: trunk: - IQKeyboardManager +EXTERNAL SOURCES: + BranchSDK: + :path: "./../" + SPEC CHECKSUMS: - IQKeyboardManager: 22ffab9bd300ad493485a390a095f5db0c841776 + BranchSDK: 28bec34fb99c53ab8e86b7bf69cc55a4505fe0b3 + IQKeyboardManager: c8665b3396bd0b79402b4c573eac345a31c7d485 -PODFILE CHECKSUM: 5d77f506f7fd530dd480a25e957b270a906b4207 +PODFILE CHECKSUM: 8c4b32f5c4a14defd62bc8a2d1e49cee9e7c2173 -COCOAPODS: 1.12.1 +COCOAPODS: 1.15.2 diff --git a/Sources/BranchSDK/BNCPreferenceHelper.m b/Sources/BranchSDK/BNCPreferenceHelper.m index ae80cc5b8..f9c9ca018 100644 --- a/Sources/BranchSDK/BNCPreferenceHelper.m +++ b/Sources/BranchSDK/BNCPreferenceHelper.m @@ -824,15 +824,11 @@ - (void) setAdUserDataUsageConsent:(BOOL)hasConsent { } - (NSInteger)attributionLevel { - @synchronized(self) { - return [self readIntegerFromDefaults:BRANCH_PREFS_KEY_ATTRIBUTION_LEVEL]; - } + return [self readIntegerFromDefaults:BRANCH_PREFS_KEY_ATTRIBUTION_LEVEL]; } -- (void)attributionLevel:(NSInteger)level { - @synchronized(self) { - [self writeIntegerToDefaults:BRANCH_PREFS_KEY_ATTRIBUTION_LEVEL value:level]; - } +- (void)setAttributionLevel:(NSInteger)level { + [self writeIntegerToDefaults:BRANCH_PREFS_KEY_ATTRIBUTION_LEVEL value:level]; } - (void) clearTrackingInformation { diff --git a/Sources/BranchSDK/BNCRequestFactory.m b/Sources/BranchSDK/BNCRequestFactory.m index d74e279a1..41daf8144 100644 --- a/Sources/BranchSDK/BNCRequestFactory.m +++ b/Sources/BranchSDK/BNCRequestFactory.m @@ -414,8 +414,8 @@ - (void)addAppClipDataToJSON:(NSMutableDictionary *)json { - (void)addDefaultRequestDataToJSON:(NSMutableDictionary *)json { json[@"branch_key"] = self.branchKey; - if (self.preferenceHelper.attributionLevel) { - json[@"consumer_protection_attribution_level"] = @(self.preferenceHelper.attributionLevel); + if (self.preferenceHelper.attributionLevel != NSNotFound) { + [json bnc_safeSetObject:@(self.preferenceHelper.attributionLevel) forKey:@"consumer_protection_attribution_level"]; } // omit field if value is NO diff --git a/Sources/BranchSDK/Branch.m b/Sources/BranchSDK/Branch.m index b1a5f0b26..a536398a9 100644 --- a/Sources/BranchSDK/Branch.m +++ b/Sources/BranchSDK/Branch.m @@ -539,17 +539,17 @@ + (void) setDMAParamsForEEA:(BOOL)eeaRegion AdPersonalizationConsent:(BOOL)adPer [BNCPreferenceHelper sharedInstance].adUserDataUsageConsent = adUserDataUsageConsent; } -+ (void)setConsumerProtectionAttributionLevel:(BranchAttributionLevel)level { - [BNCPreferenceHelper sharedInstance].attributionLevel = level; +- (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]; - + //Set tracking to disabled if consumer protection attribution level is changed to BranchAttributionLevelNone. Otherwise, keep tracking enabled. if (level == BranchAttributionLevelNone) { if ([Branch trackingDisabled] == false) { //Disable Tracking [[BranchLogger shared] logVerbose:@"Disabling attribution events due to Consumer Protection Attribution Level being BranchAttributionLevelNone." error:nil]; - + // Clear partner parameters [[BNCPartnerParameters shared] clearAllParameters]; @@ -566,13 +566,14 @@ + (void)setConsumerProtectionAttributionLevel:(BranchAttributionLevel)level { 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]; - + // Set the flag: [BNCPreferenceHelper sharedInstance].trackingDisabled = NO; // Initialize a Branch session: [Branch.getInstance initUserSessionAndCallCallback:NO sceneIdentifier:nil urlString:nil]; } } + } #pragma mark - InitSession Permutation methods diff --git a/Sources/BranchSDK/Public/BNCPreferenceHelper.h b/Sources/BranchSDK/Public/BNCPreferenceHelper.h index a84cdc0a8..a5faa8236 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 (assign, nonatomic) NSInteger attributionLevel; +@property (nonatomic, assign) NSInteger attributionLevel; - (void) clearTrackingInformation; diff --git a/Sources/BranchSDK/Public/Branch.h b/Sources/BranchSDK/Public/Branch.h index 9eecc9df5..ce3a1f031 100644 --- a/Sources/BranchSDK/Public/Branch.h +++ b/Sources/BranchSDK/Public/Branch.h @@ -830,17 +830,17 @@ typedef NS_ENUM(NSUInteger, BranchAttributionLevel) { * - Privacy Frameworks * - Deep Linking */ - BranchAttributionLevelFull, + BranchAttributionLevelFull = 0, /** - * Reuced: + * Reduced: * - Device Ids * - Local IP * - Data Integrations Webhooks * - Privacy Frameworks * - Deep Linking */ - BranchAttributionLevelReduced, + BranchAttributionLevelReduced = 1, /** * Minimal: @@ -849,14 +849,14 @@ typedef NS_ENUM(NSUInteger, BranchAttributionLevel) { * - Data Integrations Webhooks * - Deep Linking */ - BranchAttributionLevelMinimal, + BranchAttributionLevelMinimal = 2, /** * None: * - Only Deterministic Deep Linking * - Disables all other Branch requests */ - BranchAttributionLevelNone + BranchAttributionLevelNone = 3 }; @@ -867,7 +867,7 @@ typedef NS_ENUM(NSUInteger, BranchAttributionLevel) { @discussion This method allows you to control the amount and type of data collected and transmitted by Branch. Adjusting the consumer protection attribution level can help you comply with privacy regulations and meet your data collection needs. */ -+ (void)setConsumerProtectionAttributionLevel:(BranchAttributionLevel)level; +- (void)setConsumerProtectionAttributionLevel:(BranchAttributionLevel)level; #pragma mark - Session Item methods From be4a9a44c9aecc803736f6797a59ad13a729dbd9 Mon Sep 17 00:00:00 2001 From: nsingh-branch Date: Thu, 27 Jun 2024 14:59:54 -0700 Subject: [PATCH 08/19] Updated to point to automation branch --- .github/workflows/automation-trigger-test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/automation-trigger-test.yml b/.github/workflows/automation-trigger-test.yml index 212c30e18..eb77a8987 100644 --- a/.github/workflows/automation-trigger-test.yml +++ b/.github/workflows/automation-trigger-test.yml @@ -69,6 +69,7 @@ jobs: uses: actions/checkout@v4 with: repository: BranchMetrics/qentelli-saas-sdk-testing-automation + ref: SDK-2465 token: ${{ secrets.BRANCHLET_ACCESS_TOKEN_PUBLIC }} - name: Set up JDK 11 uses: actions/setup-java@v4 From 6545298cef8e87f1270ae72454990fb907fa0003 Mon Sep 17 00:00:00 2001 From: nsingh-branch Date: Thu, 27 Jun 2024 17:18:53 -0700 Subject: [PATCH 09/19] Updated automation testbed method --- .../DeepLinkDemo/Controllers/HomeViewController.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/DeepLinkDemo/DeepLinkDemo/Controllers/HomeViewController.swift b/DeepLinkDemo/DeepLinkDemo/Controllers/HomeViewController.swift index ca6ce160b..b4880dce9 100644 --- a/DeepLinkDemo/DeepLinkDemo/Controllers/HomeViewController.swift +++ b/DeepLinkDemo/DeepLinkDemo/Controllers/HomeViewController.swift @@ -215,7 +215,7 @@ class HomeViewController: UITableViewController { if let jsonObject = try JSONSerialization.jsonObject(with: data, options : .allowFragments) as? [String:AnyObject] { if jsonObject["consumer_protection_attribution_level"] != nil { - let attribution_level = jsonObject["consumer_protection_attribution_level"] as! Int + let attribution_level = jsonObject["consumer_protection_attribution_level"] as! String self.logData = "" self.enableBranchLogging(){(msg:String,msg2:BranchLogLevel,msg3:Error?)->() in if (msg.contains("BranchSDK")){ @@ -228,13 +228,13 @@ class HomeViewController: UITableViewController { } switch attribution_level { - case 0: + case "0": Branch.getInstance().setConsumerProtectionAttributionLevel(.full) - case 1: + case "1": Branch.getInstance().setConsumerProtectionAttributionLevel(.reduced) - case 2: + case "2": Branch.getInstance().setConsumerProtectionAttributionLevel(.minimal) - case 3: + case "3": Branch.getInstance().setConsumerProtectionAttributionLevel(.none) default: Branch.getInstance().setConsumerProtectionAttributionLevel(.full) From cb78ae80ddceb008a5866c9d37e1fd9895cba2ec Mon Sep 17 00:00:00 2001 From: nsingh-branch Date: Thu, 27 Jun 2024 17:36:03 -0700 Subject: [PATCH 10/19] Fixed old test --- Branch-TestBed/Branch-SDK-Tests/BranchClassTests.m | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Branch-TestBed/Branch-SDK-Tests/BranchClassTests.m b/Branch-TestBed/Branch-SDK-Tests/BranchClassTests.m index 447034fa6..d1e7713f1 100644 --- a/Branch-TestBed/Branch-SDK-Tests/BranchClassTests.m +++ b/Branch-TestBed/Branch-SDK-Tests/BranchClassTests.m @@ -243,19 +243,20 @@ - (void)testSetDMAParamsForEEA { - (void)testSetConsumerProtectionAttributionLevel { // Set to Reduced and check - [Branch setConsumerProtectionAttributionLevel:BranchAttributionLevelReduced]; + Branch *branch = [Branch getInstance]; + [branch setConsumerProtectionAttributionLevel:BranchAttributionLevelReduced]; XCTAssertEqual([BNCPreferenceHelper sharedInstance].attributionLevel, BranchAttributionLevelReduced); // Set to Minimal and check - [Branch setConsumerProtectionAttributionLevel:BranchAttributionLevelMinimal]; + [branch setConsumerProtectionAttributionLevel:BranchAttributionLevelMinimal]; XCTAssertEqual([BNCPreferenceHelper sharedInstance].attributionLevel, BranchAttributionLevelMinimal); // Set to None and check - [Branch setConsumerProtectionAttributionLevel:BranchAttributionLevelNone]; + [branch setConsumerProtectionAttributionLevel:BranchAttributionLevelNone]; XCTAssertEqual([BNCPreferenceHelper sharedInstance].attributionLevel, BranchAttributionLevelNone); // Set to Full and check - [Branch setConsumerProtectionAttributionLevel:BranchAttributionLevelFull]; + [branch setConsumerProtectionAttributionLevel:BranchAttributionLevelFull]; XCTAssertEqual([BNCPreferenceHelper sharedInstance].attributionLevel, BranchAttributionLevelFull); } From 84de80f3e4f1459a14bfc17b1d702f41f724bfa6 Mon Sep 17 00:00:00 2001 From: nsingh-branch Date: Tue, 30 Jul 2024 10:46:39 -0700 Subject: [PATCH 11/19] 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; /** From 1e41bc302a9243943b015a8c1ac5a5e5f2bfb39f Mon Sep 17 00:00:00 2001 From: nsingh-branch Date: Mon, 28 Oct 2024 15:00:23 -0700 Subject: [PATCH 12/19] Update to remove IDs from requests --- Sources/BranchSDK/BNCRequestFactory.m | 57 ++++++++++++++++++--------- Sources/BranchSDK/Branch.m | 1 + 2 files changed, 40 insertions(+), 18 deletions(-) diff --git a/Sources/BranchSDK/BNCRequestFactory.m b/Sources/BranchSDK/BNCRequestFactory.m index a22be9972..dbaf88af7 100644 --- a/Sources/BranchSDK/BNCRequestFactory.m +++ b/Sources/BranchSDK/BNCRequestFactory.m @@ -480,9 +480,12 @@ - (void)addInstrumentationToJSON:(NSMutableDictionary *)json { // BNCReferringURLUtility requires the endpoint string to determine which query params are applied - (void)addReferringURLsToJSON:(NSMutableDictionary *)json forEndpoint:(NSString *)endpoint { // Not a singleton, but BNCReferringURLUtility does pull from storage - BNCReferringURLUtility *utility = [BNCReferringURLUtility new]; - NSDictionary *urlQueryParams = [utility referringURLQueryParamsForEndpoint:endpoint]; - [json bnc_safeAddEntriesFromDictionary:urlQueryParams]; + if ([self.preferenceHelper attributionLevel] == BranchAttributionLevelFull || + [self.preferenceHelper attributionLevelInitialized] == false) { + BNCReferringURLUtility *utility = [BNCReferringURLUtility new]; + NSDictionary *urlQueryParams = [utility referringURLQueryParamsForEndpoint:endpoint]; + [json bnc_safeAddEntriesFromDictionary:urlQueryParams]; + } } // install and open @@ -491,8 +494,9 @@ - (void)addDeveloperUserIDToJSON:(NSMutableDictionary *)json { } - (void)addConsumerProtectionAttributionLevel:(NSMutableDictionary *)json { - if([self.preferenceHelper attributionLevelInitialized]){ - [self safeSetValue:[self.preferenceHelper attributionLevel] forKey:BRANCH_REQUEST_KEY_CPP_LEVEL onDict:json]; + if ([self.preferenceHelper attributionLevelInitialized]) { + BranchAttributionLevel attributionLevel = [self.preferenceHelper attributionLevel]; + [self safeSetValue:attributionLevel forKey:BRANCH_REQUEST_KEY_CPP_LEVEL onDict:json]; } } @@ -508,18 +512,28 @@ - (NSDictionary *)v2dictionary { NSMutableDictionary *dictionary = [NSMutableDictionary new]; @synchronized (self.deviceInfo) { [self.deviceInfo checkAdvertisingIdentifier]; - + BOOL disableAdNetworkCallouts = self.preferenceHelper.disableAdNetworkCallouts; if (disableAdNetworkCallouts) { dictionary[@"disable_ad_network_callouts"] = [NSNumber numberWithBool:disableAdNetworkCallouts]; } - + if (self.preferenceHelper.isDebug) { dictionary[@"unidentified_device"] = @(YES); } else { - [dictionary bnc_safeSetObject:self.deviceInfo.vendorId forKey:@"idfv"]; - [dictionary bnc_safeSetObject:self.deviceInfo.advertiserId forKey:@"idfa"]; + BranchAttributionLevel attributionLevel = [self.preferenceHelper attributionLevel]; + + if (attributionLevel == BranchAttributionLevelFull || + [self.preferenceHelper attributionLevelInitialized] == false) { + [dictionary bnc_safeSetObject:self.deviceInfo.advertiserId forKey:@"idfa"]; + } + + if (attributionLevel != BranchAttributionLevelNone || + [self.preferenceHelper attributionLevelInitialized] == false) { + [dictionary bnc_safeSetObject:self.deviceInfo.vendorId forKey:@"idfv"]; + } } + [dictionary bnc_safeSetObject:self.deviceInfo.anonId forKey:@"anon_id"]; [dictionary bnc_safeSetObject:self.deviceInfo.localIPAddress forKey:@"local_ip"]; @@ -576,20 +590,27 @@ - (void)updateDeviceInfoToMutableDictionary:(NSMutableDictionary *)dict { if (![self isTrackingDisabled]) { [self.deviceInfo checkAdvertisingIdentifier]; + // Only include hardware ID fields for Full Attribution Level + if ([self.preferenceHelper attributionLevel] == BranchAttributionLevelFull) { + // hardware id information. idfa, idfv or random NSString *hardwareId = [self.deviceInfo.hardwareId copy]; NSString *hardwareIdType = [self.deviceInfo.hardwareIdType copy]; NSNumber *isRealHardwareId = @(self.deviceInfo.isRealHardwareId); - if (hardwareId != nil && hardwareIdType != nil && isRealHardwareId != nil) { - dict[BRANCH_REQUEST_KEY_HARDWARE_ID] = hardwareId; - dict[BRANCH_REQUEST_KEY_HARDWARE_ID_TYPE] = hardwareIdType; - dict[BRANCH_REQUEST_KEY_IS_HARDWARE_ID_REAL] = isRealHardwareId; + + if (hardwareId != nil && hardwareIdType != nil && isRealHardwareId != nil) { + dict[BRANCH_REQUEST_KEY_HARDWARE_ID] = hardwareId; + dict[BRANCH_REQUEST_KEY_HARDWARE_ID_TYPE] = hardwareIdType; + dict[BRANCH_REQUEST_KEY_IS_HARDWARE_ID_REAL] = isRealHardwareId; + } + [self safeSetValue:self.deviceInfo.advertiserId forKey:@"idfa" onDict:dict]; } - - // idfv is duplicated in the hardware id field when idfa is unavailable - [self safeSetValue:self.deviceInfo.vendorId forKey:BRANCH_REQUEST_KEY_IOS_VENDOR_ID onDict:dict]; - // idfa is only in the hardware id field - // [self safeSetValue:deviceInfo.advertiserId forKey:@"idfa" onDict:dict]; + + // Only include hardware ID fields for attribution levels greater than None + if ([self.preferenceHelper attributionLevel] != BranchAttributionLevelNone) { + [self safeSetValue:self.deviceInfo.vendorId forKey:BRANCH_REQUEST_KEY_IOS_VENDOR_ID onDict:dict]; + } + [self safeSetValue:self.deviceInfo.anonId forKey:@"anon_id" onDict:dict]; [self safeSetValue:[self.deviceInfo localIPAddress] forKey:@"local_ip" onDict:dict]; diff --git a/Sources/BranchSDK/Branch.m b/Sources/BranchSDK/Branch.m index c318ffcb5..3cae94f25 100644 --- a/Sources/BranchSDK/Branch.m +++ b/Sources/BranchSDK/Branch.m @@ -89,6 +89,7 @@ BranchAttributionLevel const BranchAttributionLevelMinimal = @"MINIMAL"; BranchAttributionLevel const BranchAttributionLevelNone = @"NONE"; + #ifndef CSSearchableItemActivityIdentifier #define CSSearchableItemActivityIdentifier @"kCSSearchableItemActivityIdentifier" #endif From f4b18dd9af9a039b7819fdec8011298beb0844ed Mon Sep 17 00:00:00 2001 From: nsingh-branch Date: Wed, 6 Nov 2024 12:51:15 -0800 Subject: [PATCH 13/19] testbed updates --- Branch-TestBed/Branch-TestBed/AppDelegate.m | 33 +++++++++++++++---- .../Branch-TestBed/LogOutputViewController.m | 25 ++++++++++++++ Branch-TestBed/Branch-TestBed/Main.storyboard | 28 ++++++++-------- .../Branch-TestBed/ViewController.m | 9 +++-- Sources/BranchSDK/Branch.m | 3 +- 5 files changed, 75 insertions(+), 23 deletions(-) diff --git a/Branch-TestBed/Branch-TestBed/AppDelegate.m b/Branch-TestBed/Branch-TestBed/AppDelegate.m index 9fe650773..5166790a6 100644 --- a/Branch-TestBed/Branch-TestBed/AppDelegate.m +++ b/Branch-TestBed/Branch-TestBed/AppDelegate.m @@ -21,6 +21,8 @@ @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + [self setBranchLogFile]; + appDelegate = self; /* @@ -44,9 +46,14 @@ - (BOOL)application:(UIApplication *)application // Handle the log message and error here. For example, printing to the console: if (error) { NSLog(@"[BranchLog] Level: %lu, Message: %@, Error: %@", (unsigned long)logLevel, message, error.localizedDescription); + //Add to file here } else { NSLog(@"[BranchLog] Level: %lu, Message: %@", (unsigned long)logLevel, message); } + + NSString *logEntry = error ? [NSString stringWithFormat:@"Level: %lu, Message: %@, Error: %@", (unsigned long)logLevel, message, error.localizedDescription] + : [NSString stringWithFormat:@"Level: %lu, Message: %@", (unsigned long)logLevel, message]; + APPLogHookFunction([NSDate date], logLevel, logEntry); }]; @@ -62,16 +69,16 @@ - (BOOL)application:(UIApplication *)application * Required: Initialize Branch, passing a deep link handler block: */ - [self setLogFile:@"OpenNInstall"]; + //[self setLogFile:@"OpenNInstall"]; [branch setIdentity:@"Bobby Branch"]; - //[branch setConsumerProtectionAttributionLevel:BranchAttributionLevelReduced]; + //[[Branch getInstance] setConsumerProtectionAttributionLevel:BranchAttributionLevelReduced]; [branch initSessionWithLaunchOptions:launchOptions andRegisterDeepLinkHandlerUsingBranchUniversalObject: ^ (BranchUniversalObject * _Nullable universalObject, BranchLinkProperties * _Nullable linkProperties, NSError * _Nullable error) { - [self setLogFile:nil]; + //[self setLogFile:nil]; [self handleDeepLinkObject:universalObject linkProperties:linkProperties error:error]; }]; @@ -140,7 +147,7 @@ - (void) handleDeepLinkObject:(BranchUniversalObject*)object [storyboard instantiateViewControllerWithIdentifier:@"LogOutputViewController"]; [navigationController pushViewController:logOutputViewController animated:YES]; NSString *logOutput = - [NSString stringWithFormat:@"Successfully Deeplinked:\n\n%@\nSession Details:\n\n%@", + [NSString stringWithFormat:@"Successfully Deeplinked!\n\nCustom Metadata Deeplink Text: %@\n\nSession Details:\n\n%@", deeplinkText, [[[Branch getInstance] getLatestReferringParams] description]]; logOutputViewController.logOutput = logOutput; } @@ -181,6 +188,19 @@ - (BOOL)application:(UIApplication *)application return YES; } +- (void)setBranchLogFile { + NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]; + NSString *logFilePath = [documentsDirectory stringByAppendingPathComponent:@"branchlogs.txt"]; + + // If the log file already exists, remove it to start fresh + if ([[NSFileManager defaultManager] fileExistsAtPath:logFilePath]) { + [[NSFileManager defaultManager] removeItemAtPath:logFilePath error:nil]; + } + + self.logFileName = logFilePath; +} + + #pragma mark - Push Notifications (Optional) /* // Helper method @@ -219,7 +239,8 @@ -(void)application:(UIApplication *)application // hook Function for SDK - Its for taking control of Logging messages. void APPLogHookFunction(NSDate*_Nonnull timestamp, BranchLogLevel level, NSString*_Nullable message) { - [appDelegate processLogMessage:message]; + NSString *formattedMessage = [NSString stringWithFormat:@"%@ [%lu] %@", timestamp, (unsigned long)level, message]; + [appDelegate processLogMessage:formattedMessage]; } // Writes message to log File. @@ -240,7 +261,7 @@ - (void) processLogMessage:(NSString *)message { encoding:NSStringEncodingConversionAllowLossy error:nil]; } - NSLog(@"%@", message); // Log mmessages to console - remove if required. + NSLog(@"%@", message); // Log messages to console - remove if required. } } diff --git a/Branch-TestBed/Branch-TestBed/LogOutputViewController.m b/Branch-TestBed/Branch-TestBed/LogOutputViewController.m index aee1033ce..76a88af8d 100644 --- a/Branch-TestBed/Branch-TestBed/LogOutputViewController.m +++ b/Branch-TestBed/Branch-TestBed/LogOutputViewController.m @@ -17,6 +17,12 @@ @implementation LogOutputViewController - (void)viewDidLoad { [super viewDidLoad]; self.logOutputTextView.text = _logOutput; + + UIBarButtonItem *clearButton = [[UIBarButtonItem alloc] initWithTitle:@"Clear Logs" + style:UIBarButtonItemStylePlain + target:self + action:@selector(clearLogs)]; + self.navigationItem.rightBarButtonItem = clearButton; } - (void)didReceiveMemoryWarning { @@ -24,4 +30,23 @@ - (void)didReceiveMemoryWarning { // Dispose of any resources that can be recreated. } +- (void)clearLogs { + NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]; + NSString *logFilePath = [documentsDirectory stringByAppendingPathComponent:@"branchlogs.txt"]; + + NSError *error = nil; + [[NSFileManager defaultManager] removeItemAtPath:logFilePath error:&error]; + + if (error) { + NSLog(@"Error clearing log file: %@", error.localizedDescription); + } else { + self.logOutputTextView.text = @"Logs cleared."; + NSLog(@"Log file cleared successfully."); + + [self.navigationController popViewControllerAnimated:YES]; + + } +} + + @end diff --git a/Branch-TestBed/Branch-TestBed/Main.storyboard b/Branch-TestBed/Branch-TestBed/Main.storyboard index d107e52fa..e9ca1da49 100644 --- a/Branch-TestBed/Branch-TestBed/Main.storyboard +++ b/Branch-TestBed/Branch-TestBed/Main.storyboard @@ -1,9 +1,9 @@ - + - + @@ -535,7 +535,7 @@ -