Skip to content

Commit cd2d8a0

Browse files
committed
Updated migrateOldGbraid code
1 parent c48365b commit cd2d8a0

File tree

3 files changed

+31
-26
lines changed

3 files changed

+31
-26
lines changed

Branch-TestBed/Branch-SDK-Tests/BNCReferringURLUtilityTests.m

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ - (BNCUrlQueryParameter *)findUrlQueryParam:(NSString *)paramName;
2020
- (NSTimeInterval)defaultValidityWindowForParam:(NSString *)paramName;
2121
- (NSMutableDictionary *)serializeToJson:(NSMutableDictionary<NSString *, BNCUrlQueryParameter *> *)urlQueryParameters;
2222
- (NSMutableDictionary<NSString *, BNCUrlQueryParameter *> *)deserializeFromJson:(NSDictionary *)json;
23+
- (void)checkForAndMigrateOldGbraid;
2324

2425
@end
2526

@@ -82,7 +83,7 @@ - (void)testParseURL {
8283
XCTAssertEqualObjects(savedParams, expectedParams);
8384
}
8485

85-
-(void)testGetEventURLQueryParams {
86+
- (void)testGetEventURLQueryParams {
8687

8788
NSDictionary *params = [utility getURLQueryParamsForRequest:eventEndpoint];
8889
NSDictionary *expectedParams = @{@"gbraid": gbraidValue,
@@ -92,7 +93,7 @@ -(void)testGetEventURLQueryParams {
9293
XCTAssertEqualObjects(params, expectedParams);
9394
}
9495

95-
-(void)testGetOpenURLQueryParams {
96+
- (void)testGetOpenURLQueryParams {
9697

9798
NSDictionary *params = [utility getURLQueryParamsForRequest:openEndpoint];
9899
NSDictionary *expectedParams = @{@"gbraid": gbraidValue,
@@ -103,15 +104,15 @@ -(void)testGetOpenURLQueryParams {
103104
XCTAssertEqualObjects(params, expectedParams);
104105
}
105106

106-
-(void)testAddGclidValueFor {
107+
- (void)testAddGclidValueFor {
107108
NSString *eventGclidValue = [utility addGclidValueFor:eventEndpoint];
108109
XCTAssertEqualObjects(eventGclidValue, gclidValue);
109110

110111
NSString *openGclidValue = [utility addGclidValueFor:openEndpoint];
111112
XCTAssertEqualObjects(openGclidValue, gclidValue);
112113
}
113114

114-
-(void)testAddGbraidValuesFor {
115+
- (void)testAddGbraidValuesFor {
115116
NSDictionary *eventGbraidValue = [utility addGbraidValuesFor:eventEndpoint];
116117

117118
NSDictionary *expectedEventGraidValue = @{
@@ -131,7 +132,7 @@ -(void)testAddGbraidValuesFor {
131132
XCTAssertEqualObjects(openGbraidValue, expectedOpenGraidValue);
132133
}
133134

134-
-(void)testIsSupportedQueryParameter {
135+
- (void)testIsSupportedQueryParameter {
135136
NSArray *validURLQueryParameters = @[@"gbraid", @"gclid"];
136137

137138
for (NSString *param in validURLQueryParameters) {
@@ -140,7 +141,7 @@ -(void)testIsSupportedQueryParameter {
140141

141142
}
142143

143-
-(void)testFindUrlQueryParam {
144+
- (void)testFindUrlQueryParam {
144145
BNCUrlQueryParameter *gbraid = [utility findUrlQueryParam:@"gbraid"];
145146

146147
BNCUrlQueryParameter *expectedGbraid = [BNCUrlQueryParameter new];
@@ -164,13 +165,13 @@ -(void)testFindUrlQueryParam {
164165
XCTAssertEqualObjects(gclid, expectedGclid);
165166
}
166167

167-
-(void)testDefaultValidityWindowForParam {
168+
- (void)testDefaultValidityWindowForParam {
168169

169170
XCTAssertEqual(2592000, [utility defaultValidityWindowForParam:@"gbraid"]);
170171
XCTAssertEqual(0, [utility defaultValidityWindowForParam:@"gclid"]);
171172
}
172173

173-
-(void)testSerializeToJson {
174+
- (void)testSerializeToJson {
174175

175176
NSDate *currentDate = [NSDate date];
176177
NSMutableDictionary<NSString *, BNCUrlQueryParameter *> * params = [NSMutableDictionary new];
@@ -216,7 +217,7 @@ -(void)testSerializeToJson {
216217
XCTAssertEqualObjects(params, deserializedParams);
217218
}
218219

219-
-(void)testDeserializeFromJson {
220+
- (void)testDeserializeFromJson {
220221
NSDate *currentDate = [NSDate date];
221222

222223
NSMutableDictionary<NSString *, BNCUrlQueryParameter *> * params = [NSMutableDictionary new];

Branch-TestBed/Branch-TestBed/AppDelegate.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,10 @@ - (BOOL)application:(UIApplication *)application
3131
Info.plist file. This makes Branch test against your test environment (As shown in the Branch
3232
Dashboard) instead of the live environment.
3333
*/
34-
[Branch setReferrerGbraidValidityWindow: 1000000000];
3534

3635
// Branch.useTestBranchKey = YES; // Make sure to comment this line out for production apps!!!
3736
Branch *branch = [Branch getInstance];
38-
37+
3938
// test pre init support
4039
//[self testDispatchToIsolationQueue:branch]
4140

BranchSDK/BNCReferringURLUtility.m

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ - (instancetype)init {
2525
self = [super init];
2626

2727
if (self) {
28-
[self checkForAndMigrateOldGbraid];
2928
self.urlQueryParameters = [self deserializeFromJson:[BNCPreferenceHelper sharedInstance].referringURLQueryParameters];
29+
[self checkForAndMigrateOldGbraid];
3030
}
3131

3232
return self;
@@ -180,24 +180,29 @@ - (NSMutableDictionary *)serializeToJson:(NSMutableDictionary<NSString *, BNCUrl
180180
return result;
181181
}
182182

183-
//Turns an old gbraid into a new BNCUrlQueryParameter and saves it for use, then clears it.
183+
//Turns an old gbraid into a new BNCUrlQueryParameter and saves it for use, then clears the old gbraid.
184184
-(void)checkForAndMigrateOldGbraid {
185-
if ([BNCPreferenceHelper sharedInstance].referrerGBRAID) {
186-
187-
NSString *existingGbraidValue = [BNCPreferenceHelper sharedInstance].referrerGBRAID;
188-
NSTimeInterval existingGbraidValidityWindow = [BNCPreferenceHelper sharedInstance].referrerGBRAIDValidityWindow;
189-
NSDate *existingGbraidInitDate = [BNCPreferenceHelper sharedInstance].referrerGBRAIDInitDate;
190-
191-
BNCUrlQueryParameter *gbraid = [BNCUrlQueryParameter new];
192-
gbraid.name = BRANCH_REQUEST_KEY_REFERRER_GBRAID;
193-
gbraid.value = existingGbraidValue;
194-
gbraid.timestamp = existingGbraidInitDate;
195-
gbraid.validityWindow = existingGbraidValidityWindow;
196-
gbraid.isDeepLink = NO;
197185

198-
if (self.urlQueryParameters[BRANCH_REQUEST_KEY_REFERRER_GBRAID].value == nil) {
186+
if (self.urlQueryParameters[BRANCH_REQUEST_KEY_REFERRER_GBRAID] != nil) {
187+
if ([BNCPreferenceHelper sharedInstance].referrerGBRAID) {
188+
NSString *existingGbraidValue = [BNCPreferenceHelper sharedInstance].referrerGBRAID;
189+
NSTimeInterval existingGbraidValidityWindow = [BNCPreferenceHelper sharedInstance].referrerGBRAIDValidityWindow;
190+
NSDate *existingGbraidInitDate = [BNCPreferenceHelper sharedInstance].referrerGBRAIDInitDate;
191+
192+
BNCUrlQueryParameter *gbraid = [BNCUrlQueryParameter new];
193+
gbraid.name = BRANCH_REQUEST_KEY_REFERRER_GBRAID;
194+
gbraid.value = existingGbraidValue;
195+
gbraid.timestamp = existingGbraidInitDate;
196+
gbraid.validityWindow = existingGbraidValidityWindow;
197+
gbraid.isDeepLink = NO;
198+
199199
[self.urlQueryParameters setValue:gbraid forKey:BRANCH_REQUEST_KEY_REFERRER_GBRAID];
200+
200201
[BNCPreferenceHelper sharedInstance].referringURLQueryParameters = [self serializeToJson:self.urlQueryParameters];
202+
203+
[BNCPreferenceHelper sharedInstance].referrerGBRAID = nil;
204+
[BNCPreferenceHelper sharedInstance].referrerGBRAIDValidityWindow = 0;
205+
[BNCPreferenceHelper sharedInstance].referrerGBRAIDInitDate = nil;
201206
}
202207
}
203208
}

0 commit comments

Comments
 (0)