Skip to content

Commit 79260fd

Browse files
authored
Merge pull request #1104 from BranchMetrics/CORE-1768-ATT-opt-in-dialog-event
CORE-1768 att opt in dialog event
2 parents 18fb258 + 22ade21 commit 79260fd

File tree

5 files changed

+81
-0
lines changed

5 files changed

+81
-0
lines changed

Branch-SDK/Branch.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,17 @@ typedef NS_ENUM(NSUInteger, BranchCreditHistoryOrder) {
683683
*/
684684
- (void)setAppClipAppGroup:(NSString *)appGroup;
685685

686+
/**
687+
Pass the AppTrackingTransparency authorization status to Branch to measure ATT prompt performance.
688+
This method should be called from the callback of ATTrackingManager.requestTrackingAuthorization.
689+
690+
Note:
691+
Before prompting the user, check that ATTrackingManager.trackingAuthorizationStatus is notDetermined.
692+
Otherwise the prompt will not display and the completion will be called with current status.
693+
This will inflate the number of OPT_IN and OPT_OUT events tracked by Branch.
694+
*/
695+
- (void)handleOptInStatus:(NSUInteger)status;
696+
686697
/**
687698
Set time window for SKAdNetwork callouts. By default, Branch limits calls to SKAdNetwork to within 24 hours after first install.
688699

Branch-SDK/Branch.m

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#import "BNCSKAdNetwork.h"
4545
#import "BNCAppGroupsData.h"
4646
#import "BNCPartnerParameters.h"
47+
#import "BranchEvent.h"
4748

4849
#if !TARGET_OS_TV
4950
#import "BNCUserAgentCollector.h"
@@ -969,6 +970,25 @@ - (void)setAppClipAppGroup:(NSString *)appGroup {
969970
[BNCAppGroupsData shared].appGroup = appGroup;
970971
}
971972

973+
- (void)handleOptInStatus:(NSUInteger)status {
974+
BranchEvent *event;
975+
switch (status) {
976+
case 2:
977+
// denied
978+
event = [BranchEvent standardEvent:BranchStandardEventOptOut];
979+
break;
980+
case 3:
981+
// authorized
982+
event = [BranchEvent standardEvent:BranchStandardEventOptIn];
983+
break;
984+
default:
985+
break;
986+
}
987+
if (event) {
988+
[event logEvent];
989+
}
990+
}
991+
972992
- (void)setSKAdNetworkCalloutMaxTimeSinceInstall:(NSTimeInterval)maxTimeInterval {
973993
[BNCSKAdNetwork sharedInstance].maxTimeSinceInstall = maxTimeInterval;
974994
}

Branch-SDK/BranchEvent.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ FOUNDATION_EXPORT BranchStandardEvent _Nonnull BranchStandardEventUnlockAchievem
4545
FOUNDATION_EXPORT BranchStandardEvent _Nonnull BranchStandardEventInvite;
4646
FOUNDATION_EXPORT BranchStandardEvent _Nonnull BranchStandardEventLogin;
4747
FOUNDATION_EXPORT BranchStandardEvent _Nonnull BranchStandardEventReserve;
48+
FOUNDATION_EXPORT BranchStandardEvent _Nonnull BranchStandardEventOptIn;
49+
FOUNDATION_EXPORT BranchStandardEvent _Nonnull BranchStandardEventOptOut;
4850

4951
typedef NS_ENUM(NSInteger, BranchEventAdType) {
5052
BranchEventAdTypeNone,

Branch-SDK/BranchEvent.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
BranchStandardEvent BranchStandardEventInvite = @"INVITE";
4747
BranchStandardEvent BranchStandardEventLogin = @"LOGIN";
4848
BranchStandardEvent BranchStandardEventReserve = @"RESERVE";
49+
BranchStandardEvent BranchStandardEventOptIn = @"OPT_IN";
50+
BranchStandardEvent BranchStandardEventOptOut = @"OPT_OUT";
4951

5052
@implementation BranchEventRequest
5153

@@ -226,6 +228,8 @@ - (NSDictionary*) dictionary {
226228
BranchStandardEventStartTrial,
227229
BranchStandardEventClickAd,
228230
BranchStandardEventViewAd,
231+
BranchStandardEventOptOut,
232+
BranchStandardEventOptIn,
229233
];
230234
}
231235

Branch-TestBed/Branch-SDK-Tests/BranchEvent.Test.m

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,50 @@ - (void)testCustomViewAdEvent {
641641
XCTAssert([request.serverURL.absoluteString containsString:@"branch.io/v2/event/standard"]);
642642
}
643643

644+
- (void)testStandardOptInEvent {
645+
BranchEvent *event = [BranchEvent standardEvent:BranchStandardEventOptIn];
646+
647+
NSDictionary *eventDictionary = [event buildEventDictionary];
648+
XCTAssertNotNil(eventDictionary);
649+
XCTAssert([eventDictionary[@"name"] isEqualToString:@"OPT_IN"]);
650+
651+
BranchEventRequest *request = [event buildRequestWithEventDictionary:eventDictionary];
652+
XCTAssert([request.serverURL.absoluteString containsString:@"branch.io/v2/event/standard"]);
653+
}
654+
655+
- (void)testCustomOptInEvent {
656+
BranchEvent *event = [BranchEvent customEventWithName:@"OPT_IN"];
657+
658+
NSDictionary *eventDictionary = [event buildEventDictionary];
659+
XCTAssertNotNil(eventDictionary);
660+
XCTAssert([eventDictionary[@"name"] isEqualToString:@"OPT_IN"]);
661+
662+
BranchEventRequest *request = [event buildRequestWithEventDictionary:eventDictionary];
663+
XCTAssert([request.serverURL.absoluteString containsString:@"branch.io/v2/event/standard"]);
664+
}
665+
666+
- (void)testStandardOptOutEvent {
667+
BranchEvent *event = [BranchEvent standardEvent:BranchStandardEventOptOut];
668+
669+
NSDictionary *eventDictionary = [event buildEventDictionary];
670+
XCTAssertNotNil(eventDictionary);
671+
XCTAssert([eventDictionary[@"name"] isEqualToString:@"OPT_OUT"]);
672+
673+
BranchEventRequest *request = [event buildRequestWithEventDictionary:eventDictionary];
674+
XCTAssert([request.serverURL.absoluteString containsString:@"branch.io/v2/event/standard"]);
675+
}
676+
677+
- (void)testCustomOptOutEvent {
678+
BranchEvent *event = [BranchEvent customEventWithName:@"OPT_OUT"];
679+
680+
NSDictionary *eventDictionary = [event buildEventDictionary];
681+
XCTAssertNotNil(eventDictionary);
682+
XCTAssert([eventDictionary[@"name"] isEqualToString:@"OPT_OUT"]);
683+
684+
BranchEventRequest *request = [event buildRequestWithEventDictionary:eventDictionary];
685+
XCTAssert([request.serverURL.absoluteString containsString:@"branch.io/v2/event/standard"]);
686+
}
687+
644688
- (void)testJsonStringForAdTypeNone {
645689
BranchEvent *event = [BranchEvent standardEvent:BranchStandardEventViewAd];
646690
XCTAssertNil([event jsonStringForAdType:BranchEventAdTypeNone]);

0 commit comments

Comments
 (0)