Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDK-2458] Implement Consumer Protection Preferences #1407

Merged
merged 20 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Branch-TestBed/Branch-SDK-Tests/BranchClassTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
62 changes: 46 additions & 16 deletions Branch-TestBed/Branch-TestBed/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21225" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES" initialViewController="rgL-wI-yV3">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="22505" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES" initialViewController="rgL-wI-yV3">
<device id="retina4_7" orientation="portrait" appearance="dark"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21207"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22504"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand All @@ -21,7 +21,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="BRw-ws-ocH">
<rect key="frame" x="16" y="209" width="343" height="70"/>
<rect key="frame" x="16" y="229" width="343" height="70"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="BranchPasteControl" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="AHy-Uo-zAF">
<rect key="frame" x="20" y="25" width="156.5" height="20.5"/>
Expand Down Expand Up @@ -52,7 +52,7 @@
</userDefinedRuntimeAttributes>
</view>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="g5q-Nq-dCK">
<rect key="frame" x="16" y="314" width="343" height="50"/>
<rect key="frame" x="16" y="334" width="343" height="50"/>
<color key="backgroundColor" systemColor="secondarySystemBackgroundColor"/>
<constraints>
<constraint firstAttribute="height" constant="50" id="THd-Hg-6zt"/>
Expand All @@ -72,7 +72,7 @@
</connections>
</button>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="YUK-Md-9s5">
<rect key="frame" x="16" y="104" width="343" height="70"/>
<rect key="frame" x="16" y="124" width="343" height="70"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="nX6-RK-9an">
<rect key="frame" x="183" y="17.5" width="140" height="35"/>
Expand Down Expand Up @@ -139,7 +139,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" editable="NO" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="MTE-X3-ym1" userLabel="logOutputTextView">
<rect key="frame" x="26" y="96" width="323" height="561"/>
<rect key="frame" x="26" y="116" width="323" height="541"/>
<color key="backgroundColor" systemColor="secondarySystemBackgroundColor"/>
<accessibility key="accessibilityConfiguration" label="DeepLinkData"/>
<color key="textColor" systemColor="labelColor"/>
Expand Down Expand Up @@ -804,6 +804,35 @@
</constraints>
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" id="4YV-Fs-BuA">
<rect key="frame" x="16" y="1174" width="343" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="4YV-Fs-BuA" id="93g-I9-9tZ">
<rect key="frame" x="0.0" y="0.0" width="343" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="leading" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="oFC-oS-hU2">
<rect key="frame" x="0.0" y="0.0" width="343" height="44"/>
<accessibility key="accessibilityConfiguration" identifier="tracking"/>
<inset key="titleEdgeInsets" minX="30" minY="0.0" maxX="0.0" maxY="0.0"/>
<inset key="imageEdgeInsets" minX="20" minY="0.0" maxX="0.0" maxY="0.0"/>
<state key="normal" title="Consumer Protection Preference" image="checkmark.shield" catalog="system">
<color key="titleColor" systemColor="linkColor"/>
</state>
<connections>
<action selector="changeConsumerProtectionPreference:" destination="i3m-ex-Bu1" eventType="touchUpInside" id="eif-fe-3JM"/>
<action selector="goToPasteControlPressed:" destination="i3m-ex-Bu1" eventType="touchUpInside" id="oct-dQ-HLq"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstAttribute="trailing" secondItem="oFC-oS-hU2" secondAttribute="trailing" id="0NH-TC-sgu"/>
<constraint firstAttribute="bottom" secondItem="oFC-oS-hU2" secondAttribute="bottom" id="CKb-dX-4SM"/>
<constraint firstItem="oFC-oS-hU2" firstAttribute="top" secondItem="93g-I9-9tZ" secondAttribute="top" id="e2p-AN-GfI"/>
<constraint firstItem="oFC-oS-hU2" firstAttribute="leading" secondItem="93g-I9-9tZ" secondAttribute="leading" id="pTf-ET-lY1"/>
</constraints>
</tableViewCellContentView>
</tableViewCell>
</cells>
</tableViewSection>
</sections>
Expand Down Expand Up @@ -832,7 +861,7 @@
<toolbarItems/>
<navigationItem key="navigationItem" title="Branch-TestBed" largeTitleDisplayMode="always" id="jbD-iI-XzT"/>
<navigationBar key="navigationBar" contentMode="scaleToFill" largeTitles="YES" id="6au-j1-SUM">
<rect key="frame" x="0.0" y="0.0" width="375" height="96"/>
<rect key="frame" x="0.0" y="20" width="375" height="96"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
Expand All @@ -848,36 +877,37 @@
<resources>
<image name="arrow.up.right.square" catalog="system" width="128" height="114"/>
<image name="bag" catalog="system" width="128" height="128"/>
<image name="checkmark.shield" catalog="system" width="128" height="119"/>
<image name="doc.text" catalog="system" width="115" height="128"/>
<image name="doc.viewfinder.fill" catalog="system" width="128" height="115"/>
<image name="eye" catalog="system" width="128" height="79"/>
<image name="folder.badge.plus" catalog="system" width="128" height="92"/>
<image name="folder.badge.plus" catalog="system" width="128" height="93"/>
<image name="light.beacon.max" catalog="system" width="128" height="102"/>
<image name="link" catalog="system" width="128" height="124"/>
<image name="moonphase.first.quarter" catalog="system" width="128" height="123"/>
<image name="moonphase.first.quarter.inverse" catalog="system" width="128" height="123"/>
<image name="person" catalog="system" width="128" height="121"/>
<image name="photo.artframe" catalog="system" width="128" height="93"/>
<image name="qrcode" catalog="system" width="128" height="114"/>
<image name="rectangle.and.paperclip" catalog="system" width="128" height="98"/>
<image name="rectangle.portrait.and.arrow.right" catalog="system" width="128" height="109"/>
<image name="square.and.arrow.up" catalog="system" width="115" height="128"/>
<image name="square.and.arrow.up.on.square" catalog="system" width="119" height="128"/>
<image name="rectangle.and.paperclip" catalog="system" width="128" height="108"/>
<image name="rectangle.portrait.and.arrow.right" catalog="system" width="128" height="108"/>
<image name="square.and.arrow.up" catalog="system" width="108" height="128"/>
<image name="square.and.arrow.up.on.square" catalog="system" width="113" height="128"/>
<image name="trophy" catalog="system" width="128" height="128"/>
<systemColor name="labelColor">
<color red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
<systemColor name="linkColor">
<color red="0.0" green="0.47843137254901963" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color red="0.0" green="0.47843137250000001" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
<systemColor name="secondarySystemBackgroundColor">
<color red="0.94901960784313721" green="0.94901960784313721" blue="0.96862745098039216" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color red="0.94901960780000005" green="0.94901960780000005" blue="0.96862745100000003" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
<systemColor name="systemGray6Color">
<color red="0.94901960784313721" green="0.94901960784313721" blue="0.96862745098039216" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color red="0.94901960780000005" green="0.94901960780000005" blue="0.96862745100000003" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
</resources>
</document>
30 changes: 30 additions & 0 deletions Branch-TestBed/Branch-TestBed/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 Attribution" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
[Branch setConsumerProtectionPreference:BranchConsumerProtectionPreferenceFullAttribution];
}];

UIAlertAction *privacyOnlyAction = [UIAlertAction actionWithTitle:@"Privacy Attribution" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
[Branch setConsumerProtectionPreference:BranchConsumerProtectionPreferencePrivacyAttribution];
}];

UIAlertAction *attributionOnlyAction = [UIAlertAction actionWithTitle:@"Analytics Only" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
[Branch setConsumerProtectionPreference:BranchConsumerProtectionPreferenceAnalyticsOnly];
}];

UIAlertAction *noAttributionAction = [UIAlertAction actionWithTitle:@"Tracking Disabled" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
[Branch setConsumerProtectionPreference:BranchConsumerProtectionPreferenceTrackingDisabled];
}];

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,
Expand Down
17 changes: 15 additions & 2 deletions Sources/BranchSDK/BNCPreferenceHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -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_CONSUMER_PROTECTION_PREFERENCE = @"bnc_consumer_protection_preference";


NSURL* /* _Nonnull */ BNCURLForBranchDirectory_Unthreaded(void);

Expand Down Expand Up @@ -119,7 +121,8 @@ @implementation BNCPreferenceHelper
patternListURL = _patternListURL,
eeaRegion = _eeaRegion,
adPersonalizationConsent = _adPersonalizationConsent,
adUserDataUsageConsent = _adUserDataUsageConsent;
adUserDataUsageConsent = _adUserDataUsageConsent,
consumerProtectionPreference = _consumerProtectionPreference;

+ (BNCPreferenceHelper *)sharedInstance {
static BNCPreferenceHelper *preferenceHelper = nil;
Expand Down Expand Up @@ -625,7 +628,6 @@ - (void) setDropURLOpen:(BOOL)value {
}
}


- (BOOL) trackingDisabled {
@synchronized(self) {
NSNumber *b = (id) [self readObjectFromDefaults:@"trackingDisabled"];
Expand Down Expand Up @@ -821,6 +823,17 @@ - (void) setAdUserDataUsageConsent:(BOOL)hasConsent {
}
}

- (NSInteger)consumerProtectionPreference {
@synchronized(self) {
return [self readIntegerFromDefaults:BRANCH_PREFS_KEY_CONSUMER_PROTECTION_PREFERENCE];
}
}

- (void)setConsumerProtectionPreference:(NSInteger)consumerProtectionPreference {
@synchronized(self) {
[self writeIntegerToDefaults:BRANCH_PREFS_KEY_CONSUMER_PROTECTION_PREFERENCE value:consumerProtectionPreference];
}
}

- (void) clearTrackingInformation {
@synchronized(self) {
Expand Down
4 changes: 4 additions & 0 deletions Sources/BranchSDK/BNCRequestFactory.m
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,10 @@ - (void)addAppClipDataToJSON:(NSMutableDictionary *)json {
- (void)addDefaultRequestDataToJSON:(NSMutableDictionary *)json {
json[@"branch_key"] = self.branchKey;

if (self.preferenceHelper.consumerProtectionPreference) {
nsingh-branch marked this conversation as resolved.
Show resolved Hide resolved
json[@"protection_preference"] = @(self.preferenceHelper.consumerProtectionPreference);
}

// omit field if value is NO
if ([self isTrackingDisabled]) {
json[@"tracking_disabled"] = @(1);
Expand Down
36 changes: 36 additions & 0 deletions Sources/BranchSDK/Branch.m
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,42 @@ + (void) setDMAParamsForEEA:(BOOL)eeaRegion AdPersonalizationConsent:(BOOL)adPer
[BNCPreferenceHelper sharedInstance].adUserDataUsageConsent = adUserDataUsageConsent;
}

+ (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];
nsingh-branch marked this conversation as resolved.
Show resolved Hide resolved

//Set tracking to disabled if consumer protection preference is changed to "No Attribution". Otherwise, keep tracking enabled.
if (preference == BranchConsumerProtectionPreferenceTrackingDisabled) {
if ([Branch trackingDisabled] == false) {
//Disable Tracking
[[BranchLogger shared] logVerbose:@"Disabling tracking due to No Attribution consumer protection preference." error:nil];
nsingh-branch marked this conversation as resolved.
Show resolved Hide resolved

// 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];
nsingh-branch marked this conversation as resolved.
Show resolved Hide resolved

// Set the flag:
[BNCPreferenceHelper sharedInstance].trackingDisabled = NO;
// Initialize a Branch session:
[Branch.getInstance initUserSessionAndCallCallback:NO sceneIdentifier:nil urlString:nil];
}
}
}

#pragma mark - InitSession Permutation methods

- (void)initSessionWithLaunchOptions:(NSDictionary *)options {
Expand Down
Loading
Loading