Skip to content

Commit 14f26f1

Browse files
authored
Merge pull request #1007 from BranchMetrics/SDK-842-disable-Ad-network-callout-option-
SDK-842 disable ad network callout option
2 parents e5e5c40 + e7df2c9 commit 14f26f1

File tree

11 files changed

+103
-19
lines changed

11 files changed

+103
-19
lines changed

Branch-SDK-Tests/BNCDeviceInfoTests.m

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,12 @@ - (void)testLocalIPAddress {
136136
- (void)testV2Dictionary {
137137
NSDictionary *dict = [self.deviceInfo v2dictionary];
138138
XCTAssertNotNil(dict);
139-
XCTAssertNotNil([dict objectForKey:@"brand"]);
140-
XCTAssertNotNil([dict objectForKey:@"os"]);
141-
XCTAssertNotNil([dict objectForKey:@"sdk"]);
142-
XCTAssertNotNil([dict objectForKey:@"sdk_version"]);
139+
XCTAssertNotNil(dict[@"brand"]);
140+
XCTAssertNotNil(dict[@"os"]);
141+
XCTAssertNotNil(dict[@"sdk"]);
142+
XCTAssertNotNil(dict[@"sdk_version"]);
143+
144+
XCTAssertNil(dict[@"disable_ad_network_callouts"]);
143145
}
144146

145147
@end
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//
2+
// BNCDisableAdNetworkCalloutsTests.m
3+
// Branch-SDK-Tests
4+
//
5+
// Created by Ernest Cho on 3/2/20.
6+
// Copyright © 2020 Branch, Inc. All rights reserved.
7+
//
8+
9+
#import <XCTest/XCTest.h>
10+
#import "BNCPreferenceHelper.h"
11+
#import "BNCDeviceInfo.h"
12+
#import "BNCServerInterface.h"
13+
14+
@interface BNCServerInterface()
15+
- (void)updateDeviceInfoToMutableDictionary:(NSMutableDictionary *)dict;
16+
@end
17+
18+
@interface BNCDisableAdNetworkCalloutsTests : XCTestCase
19+
20+
@end
21+
22+
// These tests are not parallelizable and therefore disabled by default
23+
// This is due to the tight coupling between BNCPreferenceHelper and BNCDeviceInfo
24+
@implementation BNCDisableAdNetworkCalloutsTests
25+
26+
- (void)setUp {
27+
[BNCPreferenceHelper preferenceHelper].disableAdNetworkCallouts = YES;
28+
}
29+
30+
- (void)tearDown {
31+
[BNCPreferenceHelper preferenceHelper].disableAdNetworkCallouts = NO;
32+
}
33+
34+
// check on the V2 dictionary
35+
- (void)testV2Dictionary {
36+
NSDictionary *dict = [[BNCDeviceInfo getInstance] v2dictionary];
37+
XCTAssertNotNil(dict);
38+
XCTAssertNotNil(dict[@"brand"]);
39+
XCTAssertNotNil(dict[@"os"]);
40+
XCTAssertNotNil(dict[@"sdk"]);
41+
XCTAssertNotNil(dict[@"sdk_version"]);
42+
43+
XCTAssertTrue(dict[@"disable_ad_network_callouts"]);
44+
}
45+
46+
// check on V1 payload
47+
- (void)testV1Payload {
48+
BNCServerInterface *interface = [BNCServerInterface new];
49+
interface.preferenceHelper = [BNCPreferenceHelper preferenceHelper];
50+
51+
NSMutableDictionary *tmp = [NSMutableDictionary new];
52+
[interface updateDeviceInfoToMutableDictionary:tmp];
53+
54+
XCTAssertNotNil(tmp);
55+
XCTAssertTrue(tmp[@"disable_ad_network_callouts"]);
56+
}
57+
58+
@end

Branch-SDK-Tests/BNCPreferenceHelperTests.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ - (void)testPreferenceDefaults {
2929
XCTAssertEqual(self.prefHelper.timeout, 5.5);
3030
XCTAssertEqual(self.prefHelper.retryInterval, 0);
3131
XCTAssertEqual(self.prefHelper.retryCount, 3);
32+
XCTAssertFalse(self.prefHelper.disableAdNetworkCallouts);
3233
}
3334

3435
- (void)testPreferenceSets {

Branch-SDK/Branch-SDK/BNCDeviceInfo.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ - (NSDictionary *)v2dictionary {
149149
@synchronized (self) {
150150
[self checkAdvertisingIdentifier];
151151

152+
BOOL disableAdNetworkCallouts = [BNCPreferenceHelper preferenceHelper].disableAdNetworkCallouts;
153+
if (disableAdNetworkCallouts) {
154+
dictionary[@"disable_ad_network_callouts"] = [NSNumber numberWithBool:disableAdNetworkCallouts];
155+
}
156+
152157
if ([BNCPreferenceHelper preferenceHelper].isDebug) {
153158
dictionary[@"unidentified_device"] = @(YES);
154159
} else {

Branch-SDK/Branch-SDK/BNCPreferenceHelper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ NSURL* /* _Nonnull */ BNCURLForBranchDirectory(void);
4949
@property (nonatomic, strong, readwrite) NSString *branchBlacklistURL;
5050
@property (assign, atomic) BOOL limitFacebookTracking;
5151
@property (strong, atomic) NSDate *previousAppBuildDate;
52+
@property (assign, nonatomic, readwrite) BOOL disableAdNetworkCallouts;
5253

5354
@property (strong, nonatomic, readwrite) NSURL *faceBookAppLink;
5455

Branch-SDK/Branch-SDK/BNCPreferenceHelper.m

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,19 @@ + (BNCPreferenceHelper *)preferenceHelper {
9797
return preferenceHelper;
9898
}
9999

100-
- (id)init {
100+
- (instancetype)init {
101101
self = [super init];
102-
if (!self) return self;
102+
if (self) {
103+
_timeout = DEFAULT_TIMEOUT;
104+
_retryCount = DEFAULT_RETRY_COUNT;
105+
_retryInterval = DEFAULT_RETRY_INTERVAL;
106+
_isDebug = NO;
107+
_persistPrefsQueue = [[NSOperationQueue alloc] init];
108+
_persistPrefsQueue.maxConcurrentOperationCount = 1;
103109

104-
_timeout = DEFAULT_TIMEOUT;
105-
_retryCount = DEFAULT_RETRY_COUNT;
106-
_retryInterval = DEFAULT_RETRY_INTERVAL;
107-
_isDebug = NO;
108-
_persistPrefsQueue = [[NSOperationQueue alloc] init];
109-
_persistPrefsQueue.maxConcurrentOperationCount = 1;
110-
111-
self.branchBlacklistURL = @"https://cdn.branch.io";
112-
110+
self.branchBlacklistURL = @"https://cdn.branch.io";
111+
self.disableAdNetworkCallouts = NO;
112+
}
113113
return self;
114114
}
115115

Branch-SDK/Branch-SDK/Branch.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,15 @@ typedef NS_ENUM(NSUInteger, BranchCreditHistoryOrder) {
678678
*/
679679
- (void)setNetworkTimeout:(NSTimeInterval)timeout;
680680

681+
/**
682+
Set disable_ad_network_callouts server flag. Default value is NO.
683+
684+
By calling this method with YES, the flag disable_ad_network_callouts = true will be set on all events for a user.
685+
Those events will not be sent to ad networks that have been specified by the customer on the dashboard.
686+
Customer is required to select the ad networks that the event should not be sent to on the dashboard in order for the flag to be effective.
687+
*/
688+
- (void)disableAdNetworkCallouts:(BOOL)disableCallouts;
689+
681690
/**
682691
Specify that Branch should NOT use an invisible SFSafariViewController to attempt cookie-based matching upon install.
683692
If you call this method, we will fall back to using our pool of cookie-IDFA pairs for matching.

Branch-SDK/Branch-SDK/Branch.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,10 @@ - (BOOL)isUserIdentified {
464464
return self.preferenceHelper.userIdentity != nil;
465465
}
466466

467+
- (void)disableAdNetworkCallouts:(BOOL)disableCallouts {
468+
self.preferenceHelper.disableAdNetworkCallouts = disableCallouts;
469+
}
470+
467471
- (void)setNetworkTimeout:(NSTimeInterval)timeout {
468472
self.preferenceHelper.timeout = timeout;
469473
}

Branch-SDK/Branch-SDK/Networking/BNCServerInterface.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ - (NSMutableDictionary *)prepareParamDict:(NSDictionary *)params
456456
if (self.preferenceHelper.instrumentationDictionary.count && [reqType isEqualToString:@"POST"]) {
457457
fullParamDict[BRANCH_REQUEST_KEY_INSTRUMENTATION] = self.preferenceHelper.instrumentationDictionary;
458458
}
459-
459+
460460
return fullParamDict;
461461
}
462462

@@ -529,6 +529,11 @@ - (void)updateDeviceInfoToMutableDictionary:(NSMutableDictionary *)dict {
529529
[self safeSetValue:deviceInfo.applicationVersion forKey:@"app_version" onDict:dict];
530530
[self safeSetValue:deviceInfo.pluginName forKey:@"plugin_name" onDict:dict];
531531
[self safeSetValue:deviceInfo.pluginVersion forKey:@"plugin_version" onDict:dict];
532+
533+
BOOL disableAdNetworkCallouts = self.preferenceHelper.disableAdNetworkCallouts;
534+
if (disableAdNetworkCallouts) {
535+
[dict setObject:[NSNumber numberWithBool:disableAdNetworkCallouts] forKey:@"disable_ad_network_callouts"];
536+
}
532537
}
533538
}
534539

Branch-TestBed/Branch-TestBed.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@
445445
54FF1F901BD1DC320004CE2E /* BranchLinkProperties.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BranchLinkProperties.m; sourceTree = "<group>"; };
446446
5F08460F23480008005B17E6 /* BNCTuneUtility.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BNCTuneUtility.h; sourceTree = "<group>"; };
447447
5F08461023480008005B17E6 /* BNCTuneUtility.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BNCTuneUtility.m; sourceTree = "<group>"; };
448+
5F2035CB240DDE90004FDC3E /* BNCDisableAdNetworkCalloutsTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BNCDisableAdNetworkCalloutsTests.m; sourceTree = "<group>"; };
448449
5F205D022318641700C776D1 /* BNCUserAgentCollectorTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BNCUserAgentCollectorTests.m; sourceTree = "<group>"; };
449450
5F205D04231864E800C776D1 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; };
450451
5F3D6712232C589100454FF1 /* BranchLastAttributedTouchData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BranchLastAttributedTouchData.m; sourceTree = "<group>"; };
@@ -763,6 +764,7 @@
763764
4AB16367239E3A2700D42931 /* DispatchToIsolationQueueTests.m */,
764765
5F437E39237DE3480052064B /* BNCTelephonyTests.m */,
765766
5F437E3F237E1A560052064B /* BNCDeviceSystemTests.m */,
767+
5F2035CB240DDE90004FDC3E /* BNCDisableAdNetworkCalloutsTests.m */,
766768
);
767769
name = "Branch-SDK-Tests";
768770
path = "../Branch-SDK-Tests";

0 commit comments

Comments
 (0)