Skip to content

Commit fbaf281

Browse files
authored
Merge pull request #962 from BranchMetrics/SDK-614-LATD-correction
SDK-614 LATD correction
2 parents c5909ed + 22dfa6a commit fbaf281

File tree

7 files changed

+72
-16
lines changed

7 files changed

+72
-16
lines changed

Branch-SDK/Branch-SDK/Branch.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -952,9 +952,21 @@ typedef NS_ENUM(NSUInteger, BranchCreditHistoryOrder) {
952952

953953
#pragma mark - Query methods
954954

955+
/**
956+
Branch includes SDK methods to allow retrieval of our Cross Platform ID (CPID) from the client. This results in an asynchronous call being made to Branch’s servers with CPID data returned when possible.
957+
958+
@param completion callback with cross platform id data
959+
*/
955960
- (void)crossPlatformIdDataWithCompletion:(void(^) (BranchCrossPlatformID * _Nullable cpid))completion;
956961

957-
- (void)lastTouchAttributedDataWithCompletion:(void(^) (BranchLastAttributedTouchData * _Nullable ltad))completion;
962+
/**
963+
Branch includes SDK methods to allow retrieval of our last attributed touch data (LATD) from the client. This results in an asynchronous call being made to Branch's servers with LATD data returned when possible.
964+
Last attributed touch data contains the information associated with that user's last viewed impression or clicked link.
965+
966+
@param window attribution window in days. If the window is outside the server supported range, it will default to 30 days.
967+
@param completion callback with attribution data
968+
*/
969+
- (void)lastAttributedTouchDataWithAttributionWindow:(NSInteger)window completion:(void(^) (BranchLastAttributedTouchData * _Nullable latd))completion;
958970

959971
#pragma mark - Short Url Sync methods
960972

Branch-SDK/Branch-SDK/Branch.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,14 +1199,16 @@ - (BranchLinkProperties *)getLatestReferringBranchLinkProperties {
11991199
#pragma mark - Query methods
12001200

12011201
- (void)crossPlatformIdDataWithCompletion:(void(^) (BranchCrossPlatformID * _Nullable cpid))completion {
1202+
[self initSafetyCheck];
12021203
dispatch_async(self.isolationQueue, ^(){
12031204
[BranchCrossPlatformID requestCrossPlatformIdData:self.serverInterface key:self.class.branchKey completion:completion];
12041205
});
12051206
}
12061207

1207-
- (void)lastTouchAttributedDataWithCompletion:(void(^) (BranchLastAttributedTouchData * _Nullable ltad))completion {
1208+
- (void)lastAttributedTouchDataWithAttributionWindow:(NSInteger)window completion:(void(^) (BranchLastAttributedTouchData * _Nullable latd))completion {
1209+
[self initSafetyCheck];
12081210
dispatch_async(self.isolationQueue, ^(){
1209-
[BranchLastAttributedTouchData requestLastTouchAttributedData:self.serverInterface key:self.class.branchKey completion:completion];
1211+
[BranchLastAttributedTouchData requestLastTouchAttributedData:self.serverInterface key:self.class.branchKey attributionWindow:window completion:completion];
12101212
});
12111213
}
12121214

Branch-SDK/Branch-SDK/BranchLastAttributedTouchData.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ NS_ASSUME_NONNULL_BEGIN
2020

2121
+ (BranchLastAttributedTouchData *)buildFromJSON:(NSDictionary *)json;
2222

23-
+ (void)requestLastTouchAttributedData:(BNCServerInterface *)serverInterface key:(NSString *)key completion:(void(^) (BranchLastAttributedTouchData *latd))completion;
23+
+ (void)requestLastTouchAttributedData:(BNCServerInterface *)serverInterface key:(NSString *)key attributionWindow:(NSInteger)window completion:(void(^) (BranchLastAttributedTouchData *latd))completion;
2424

2525
@end
2626

Branch-SDK/Branch-SDK/BranchLastAttributedTouchData.m

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#import "BranchLastAttributedTouchData.h"
1010
#import "BranchLATDRequest.h"
1111
#import "BNCJSONUtility.h"
12+
#import "BNCLog.h"
1213

1314
@implementation BranchLastAttributedTouchData
1415

@@ -25,8 +26,16 @@ + (BranchLastAttributedTouchData *)buildFromJSON:(NSDictionary *)json {
2526
return nil;
2627
}
2728

28-
+ (void)requestLastTouchAttributedData:(BNCServerInterface *)serverInterface key:(NSString *)key completion:(void(^) (BranchLastAttributedTouchData *ltad))completion {
29+
+ (void)requestLastTouchAttributedData:(BNCServerInterface *)serverInterface key:(NSString *)key attributionWindow:(NSInteger)window completion:(void(^) (BranchLastAttributedTouchData *latd))completion {
2930
BranchLATDRequest *request = [BranchLATDRequest new];
31+
32+
// Limit attribution range to about a year. Although the server only supports up to 90 days as of Nov. 2019, it will fail gracefully for higher values.
33+
if (window > -1 && window < 365) {
34+
request.attributionWindow = window;
35+
} else {
36+
BNCLogWarning(@"Attribution window is outside the expected range, using 30 days.");
37+
}
38+
3039
[request makeRequest:serverInterface key:key callback:^(BNCServerResponse *response, NSError *error) {
3140

3241
// error is logged by the network service, skip parsing on error

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

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ - (BOOL)isV2APIURL:(NSString *)urlstring baseURL:(NSString *)baseURL {
495495
return found;
496496
}
497497

498-
// workaround for new V1 APIs that expect V2 API format
498+
// workaround for new V1 APIs that expects different format
499499
- (BOOL)isNewV1API:(NSString *)urlstring {
500500
NSArray<NSString *> *newV1Apis = @[ BRANCH_REQUEST_ENDPOINT_CPID, BRANCH_REQUEST_ENDPOINT_LATD ];
501501
for (NSString *tmp in newV1Apis) {
@@ -508,21 +508,44 @@ - (BOOL)isNewV1API:(NSString *)urlstring {
508508
return NO;
509509
}
510510

511-
- (void)postRequest:(NSDictionary *)post
512-
url:(NSString *)url
513-
retryNumber:(NSInteger)retryNumber
514-
key:(NSString *)key
515-
callback:(BNCServerCallback)callback {
516-
511+
// SDK-635 Follow up ticket to redesign this. The payload format should be the responsibility of the network request class.
512+
- (NSMutableDictionary *)buildExtendedParametersForURL:(NSString *)url withPostDictionary:(NSDictionary *)post {
517513
NSMutableDictionary *extendedParams = nil;
518-
if ([self isV2APIURL:url] || [self isNewV1API:url]) {
514+
515+
// v2 endpoints expect a user data section
516+
if ([self isV2APIURL:url]) {
519517
extendedParams = [NSMutableDictionary new];
520-
if (post) [extendedParams addEntriesFromDictionary:post];
518+
if (post) {
519+
[extendedParams addEntriesFromDictionary:post];
520+
}
521521
NSDictionary *d = [[BNCDeviceInfo getInstance] v2dictionary];
522-
if (d.count) extendedParams[@"user_data"] = d;
522+
if (d.count) {
523+
extendedParams[@"user_data"] = d;
524+
}
525+
526+
// cpid and latd endpoints expect a v2 format, except with possible customization
527+
} else if ([self isNewV1API:url]) {
528+
extendedParams = [NSMutableDictionary new];
529+
530+
NSMutableDictionary *tmp = [NSMutableDictionary dictionaryWithDictionary: [[BNCDeviceInfo getInstance] v2dictionary]];
531+
if (tmp.count) {
532+
extendedParams[@"user_data"] = tmp;
533+
[tmp addEntriesFromDictionary:post];
534+
}
535+
523536
} else {
524537
extendedParams = [self updateDeviceInfoToParams:post];
525538
}
539+
return extendedParams;
540+
}
541+
542+
- (void)postRequest:(NSDictionary *)post
543+
url:(NSString *)url
544+
retryNumber:(NSInteger)retryNumber
545+
key:(NSString *)key
546+
callback:(BNCServerCallback)callback {
547+
548+
NSMutableDictionary *extendedParams = [self buildExtendedParametersForURL:url withPostDictionary:post];
526549
NSURLRequest *request = [self preparePostRequest:extendedParams url:url key:key retryNumber:retryNumber];
527550

528551
// Instrumentation metrics

Branch-SDK/Branch-SDK/Networking/Requests/BranchLATDRequest.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ NS_ASSUME_NONNULL_BEGIN
1313

1414
@interface BranchLATDRequest : BNCServerRequest
1515

16+
@property (nonatomic, assign, readwrite) NSInteger attributionWindow;
17+
1618
@end
1719

1820
NS_ASSUME_NONNULL_END

Branch-SDK/Branch-SDK/Networking/Requests/BranchLATDRequest.m

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,21 @@
1212

1313
@implementation BranchLATDRequest
1414

15+
- (instancetype)init {
16+
self = [super init];
17+
if (self) {
18+
self.attributionWindow = 30;
19+
}
20+
return self;
21+
}
22+
1523
- (NSString *)serverURL {
1624
return [[BNCPreferenceHelper preferenceHelper] getAPIURL:BRANCH_REQUEST_ENDPOINT_LATD];
1725
}
1826

19-
// all required fields for this request is added by BNCServerInterface
2027
- (NSMutableDictionary *)buildRequestParams {
2128
NSMutableDictionary *params = [NSMutableDictionary new];
29+
[params setObject:@(self.attributionWindow) forKey:@"attribution_window"];
2230
return params;
2331
}
2432

0 commit comments

Comments
 (0)