Skip to content

Commit 47212de

Browse files
committed
SDK - 1758 - Added gbraid_timestamp on v1/open and v2/event. Updated Unit test cases to include gbraid params.
1 parent 94657d5 commit 47212de

File tree

5 files changed

+44
-3
lines changed

5 files changed

+44
-3
lines changed

Branch-SDK/BNCServerInterface.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ - (NSMutableDictionary *)prepareParamDict:(NSDictionary *)params
457457
}
458458
}
459459
// For DOWNSTREAM EVENTS v2/events, include referrer_gbraid in request if available
460-
if([self.requestEndpoint containsString:@"/v2/event"]){
460+
if([self.requestEndpoint containsString:@"/v2/event"] || [self.requestEndpoint containsString:@"/v1/open"]){
461461
NSString *ref_gbraid = self.preferenceHelper.referrerGBRAID;
462462
if ((ref_gbraid != nil) && (ref_gbraid.length > 0)) {
463463
// Check if its valid or expired
@@ -468,6 +468,8 @@ - (NSMutableDictionary *)prepareParamDict:(NSDictionary *)params
468468
NSDate *now = [NSDate date];
469469
if ([now compare:expirationDate] == NSOrderedAscending) {
470470
fullParamDict[BRANCH_REQUEST_KEY_REFERRER_GBRAID] = ref_gbraid;
471+
long long timestampInMilliSec = (long long)([initDate timeIntervalSince1970] * 1000.0);
472+
fullParamDict[BRANCH_REQUEST_KEY_REFERRER_GBRAID_TIMESTAMP] = [NSString stringWithFormat:@"%lld", timestampInMilliSec];
471473
}
472474
}
473475
}

Branch-SDK/BranchConstants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ extern NSString * const BRANCH_REQUEST_KEY_PARTNER_PARAMETERS;
8181

8282
extern NSString * const BRANCH_REQUEST_METADATA_KEY_SCANTIME_WINDOW;
8383
extern NSString * const BRANCH_REQUEST_KEY_REFERRER_GBRAID;
84+
extern NSString * const BRANCH_REQUEST_KEY_REFERRER_GBRAID_TIMESTAMP;
8485

8586
extern NSString * const BRANCH_REQUEST_ENDPOINT_SET_IDENTITY;
8687
extern NSString * const BRANCH_REQUEST_ENDPOINT_APP_LINK_SETTINGS;

Branch-SDK/BranchConstants.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676

7777
NSString * const BRANCH_REQUEST_METADATA_KEY_SCANTIME_WINDOW = @"skan_time_window";
7878
NSString * const BRANCH_REQUEST_KEY_REFERRER_GBRAID = @"gbraid";
79+
NSString * const BRANCH_REQUEST_KEY_REFERRER_GBRAID_TIMESTAMP = @"gbraid_timestamp";
7980

8081
NSString * const BRANCH_REQUEST_ENDPOINT_SET_IDENTITY = @"profile";
8182
NSString * const BRANCH_REQUEST_ENDPOINT_APP_LINK_SETTINGS = @"app-link-settings";

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,10 +445,15 @@ - (void) testServerInterfaceDictionaryPrepForGbraid {
445445
XCTAssertNotNil([result objectForKey:BRANCH_REQUEST_KEY_REFERRER_GBRAID]);
446446
XCTAssertTrue([[result objectForKey:BRANCH_REQUEST_KEY_REFERRER_GBRAID] isEqualToString:gbraidValue]);
447447

448-
//Check - gbraid should not be present - endpoint is open
448+
// Check for gbraid timestamp
449+
XCTAssertNotNil([result objectForKey:BRANCH_REQUEST_KEY_REFERRER_GBRAID_TIMESTAMP]);
450+
NSString *tsInMs = [NSString stringWithFormat:@"%lld", (long long)[now timeIntervalSince1970]*1000];
451+
XCTAssertTrue([[result objectForKey:BRANCH_REQUEST_KEY_REFERRER_GBRAID] isEqualToString:tsInMs]);
452+
453+
//Check - gbraid should be present - endpoint is open
449454
serverInterface.requestEndpoint = @"/v1/open";
450455
result = [serverInterface prepareParamDict:NULL key:@"1234567890" retryNumber:3 requestType:@"POST"];
451-
XCTAssertNil([result objectForKey:BRANCH_REQUEST_KEY_REFERRER_GBRAID]);
456+
XCTAssertNotNil([result objectForKey:BRANCH_REQUEST_KEY_REFERRER_GBRAID]);
452457

453458
//Check - gbraid should not be present - validity is expired
454459
NSDate *pastDate = [[NSDate date] dateByAddingTimeInterval:-2592001];

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,22 @@ - (void) testEvent {
130130
[self mutableDictionaryFromBundleJSONWithKey:@"V2EventJSON"];
131131
expectedRequest[@"branch_key"] = Branch.branchKey;
132132
expectedRequest[@"user_data"] = [[BNCDeviceInfo getInstance] v2dictionary];
133+
134+
// Add params for Gbraid
135+
BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance];
136+
if(preferenceHelper.referrerGBRAID){
137+
NSTimeInterval validityWindow = preferenceHelper.referrerGBRAIDValidityWindow;
138+
if (validityWindow) {
139+
NSDate *initDate = preferenceHelper.referrerGBRAIDInitDate ;
140+
NSDate *expirationDate = [initDate dateByAddingTimeInterval:validityWindow];
141+
NSDate *now = [NSDate date];
142+
if ([now compare:expirationDate] == NSOrderedAscending) {
143+
expectedRequest[BRANCH_REQUEST_KEY_REFERRER_GBRAID] = preferenceHelper.referrerGBRAID;
144+
long long timestampInMilliSec = (long long)([initDate timeIntervalSince1970] * 1000.0);
145+
expectedRequest[BRANCH_REQUEST_KEY_REFERRER_GBRAID_TIMESTAMP] = [NSString stringWithFormat:@"%lld", timestampInMilliSec];
146+
}
147+
}
148+
}
133149

134150
Branch *branch = [Branch getInstance:@"key_live_foo"];
135151
XCTestExpectation *expectation = [self expectationWithDescription:@"v2-event"];
@@ -180,6 +196,22 @@ - (void) testUserCompletedAction {
180196
expectedRequest[@"event_data"] = nil;
181197
expectedRequest[@"custom_data"] = nil;
182198
expectedRequest[@"customer_event_alias"] = nil;
199+
200+
// Add params for Gbraid
201+
BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance];
202+
if(preferenceHelper.referrerGBRAID){
203+
NSTimeInterval validityWindow = preferenceHelper.referrerGBRAIDValidityWindow;
204+
if (validityWindow) {
205+
NSDate *initDate = preferenceHelper.referrerGBRAIDInitDate ;
206+
NSDate *expirationDate = [initDate dateByAddingTimeInterval:validityWindow];
207+
NSDate *now = [NSDate date];
208+
if ([now compare:expirationDate] == NSOrderedAscending) {
209+
expectedRequest[BRANCH_REQUEST_KEY_REFERRER_GBRAID] = preferenceHelper.referrerGBRAID;
210+
long long timestampInMilliSec = (long long)([initDate timeIntervalSince1970] * 1000.0);
211+
expectedRequest[BRANCH_REQUEST_KEY_REFERRER_GBRAID_TIMESTAMP] = [NSString stringWithFormat:@"%lld", timestampInMilliSec];
212+
}
213+
}
214+
}
183215

184216
Branch *branch = [Branch getInstance:@"key_live_foo"];
185217
XCTestExpectation *expectation = [self expectationWithDescription:@"v2-event-user-action"];

0 commit comments

Comments
 (0)