Skip to content

Commit 8e074f0

Browse files
committed
Added ScCid support and tests
1 parent da55b9e commit 8e074f0

File tree

4 files changed

+145
-1
lines changed

4 files changed

+145
-1
lines changed

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

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,4 +401,116 @@ - (void)verifyOldGbraidDataIsCleared {
401401
XCTAssertNil([BNCPreferenceHelper sharedInstance].referrerGBRAIDInitDate);
402402
}
403403

404+
- (void)testReferringURLWithSccid {
405+
NSURL *url = [NSURL URLWithString:@"https://bnctestbed.app.link?sccid=12345"];
406+
NSDictionary *expected = @{
407+
@"sccid": @"12345"
408+
};
409+
410+
BNCReferringURLUtility *utility = [self referringUtilityForTests];
411+
[utility parseReferringURL:url];
412+
NSDictionary *params = [utility referringURLQueryParamsForEndpoint:openEndpoint];
413+
414+
XCTAssert([expected isEqualToDictionary:params]);
415+
}
416+
417+
- (void)testReferringURLWithSccidMixedCase {
418+
NSURL *url = [NSURL URLWithString:@"https://bnctestbed.app.link?ScCiD=12345"];
419+
NSDictionary *expected = @{
420+
@"sccid": @"12345"
421+
};
422+
423+
BNCReferringURLUtility *utility = [self referringUtilityForTests];
424+
[utility parseReferringURL:url];
425+
NSDictionary *params = [utility referringURLQueryParamsForEndpoint:openEndpoint];
426+
427+
XCTAssert([expected isEqualToDictionary:params]);
428+
}
429+
430+
- (void)testReferringURLWithSccidNoValue {
431+
NSURL *url = [NSURL URLWithString:@"https://bnctestbed.app.link?sccid="];
432+
NSDictionary *expected = @{
433+
@"sccid": @""
434+
};
435+
436+
BNCReferringURLUtility *utility = [self referringUtilityForTests];
437+
[utility parseReferringURL:url];
438+
NSDictionary *params = [utility referringURLQueryParamsForEndpoint:openEndpoint];
439+
440+
XCTAssert([expected isEqualToDictionary:params]);
441+
}
442+
443+
- (void)testReferringURLWithSccidValueCasePreserved {
444+
NSURL *url = [NSURL URLWithString:@"https://bnctestbed.app.link?sccid=aAbBcC"];
445+
NSDictionary *expected = @{
446+
@"sccid": @"aAbBcC"
447+
};
448+
449+
BNCReferringURLUtility *utility = [self referringUtilityForTests];
450+
[utility parseReferringURL:url];
451+
NSDictionary *params = [utility referringURLQueryParamsForEndpoint:openEndpoint];
452+
453+
XCTAssert([expected isEqualToDictionary:params]);
454+
}
455+
456+
- (void)testReferringURLWithSccidIgnoredParam {
457+
NSURL *url = [NSURL URLWithString:@"https://bnctestbed.app.link?sccid=12345&other=abcde"];
458+
NSDictionary *expected = @{
459+
@"sccid": @"12345"
460+
};
461+
462+
BNCReferringURLUtility *utility = [self referringUtilityForTests];
463+
[utility parseReferringURL:url];
464+
NSDictionary *params = [utility referringURLQueryParamsForEndpoint:openEndpoint];
465+
466+
XCTAssert([expected isEqualToDictionary:params]);
467+
}
468+
469+
- (void)testReferringURLWithSccidFragment{
470+
NSURL *url = [NSURL URLWithString:@"https://bnctestbed.app.link?sccid=12345#header"];
471+
NSDictionary *expected = @{
472+
@"sccid": @"12345"
473+
};
474+
475+
BNCReferringURLUtility *utility = [self referringUtilityForTests];
476+
[utility parseReferringURL:url];
477+
NSDictionary *params = [utility referringURLQueryParamsForEndpoint:openEndpoint];
478+
479+
XCTAssert([expected isEqualToDictionary:params]);
480+
}
481+
482+
- (void)testReferringURLWithSccidAsFragment{
483+
NSURL *url = [NSURL URLWithString:@"https://bnctestbed.app.link?other=abcde#sccid=12345"];
484+
NSDictionary *expected = @{ };
485+
486+
BNCReferringURLUtility *utility = [self referringUtilityForTests];
487+
[utility parseReferringURL:url];
488+
NSDictionary *params = [utility referringURLQueryParamsForEndpoint:openEndpoint];
489+
490+
XCTAssert([expected isEqualToDictionary:params]);
491+
}
492+
493+
- (void)testReferringURLWithSccidOverwritesValue {
494+
NSURL *url = [NSURL URLWithString:@"https://bnctestbed.app.link?sccid=12345"];
495+
NSDictionary *expected = @{
496+
@"sccid": @"12345"
497+
};
498+
499+
NSURL *url2 = [NSURL URLWithString:@"https://bnctestbed.app.link?sccid=abcde"];
500+
NSDictionary *expected2 = @{
501+
@"sccid": @"abcde"
502+
};
503+
504+
BNCReferringURLUtility *utility = [self referringUtilityForTests];
505+
[utility parseReferringURL:url];
506+
NSDictionary *params = [utility referringURLQueryParamsForEndpoint:openEndpoint];
507+
XCTAssert([expected isEqualToDictionary:params]);
508+
509+
[utility parseReferringURL:url2];
510+
NSDictionary *params2 = [utility referringURLQueryParamsForEndpoint:openEndpoint];
511+
512+
XCTAssert([expected2 isEqualToDictionary:params2]);
513+
}
514+
515+
404516
@end

BranchSDK/BNCReferringURLUtility.m

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#import "BranchConstants.h"
1212
#import "BNCUrlQueryParameter.h"
1313
#import "BNCLog.h"
14+
#import <UIKit/UIKit.h>
1415

1516
@interface BNCReferringURLUtility()
1617
@property (strong, readwrite, nonatomic) NSMutableDictionary<NSString *, BNCUrlQueryParameter *> *urlQueryParameters;
@@ -25,10 +26,25 @@ - (instancetype)init {
2526
self.preferenceHelper = [BNCPreferenceHelper sharedInstance];
2627
self.urlQueryParameters = [self deserializeFromJson:self.preferenceHelper.referringURLQueryParameters];
2728
[self checkForAndMigrateOldGbraid];
29+
30+
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
31+
[notificationCenter addObserver:self
32+
selector:@selector(clearSccid)
33+
name:UIApplicationDidEnterBackgroundNotification
34+
object:nil];
35+
[notificationCenter addObserver:self
36+
selector:@selector(clearSccid)
37+
name:UIApplicationWillTerminateNotification
38+
object:nil];
2839
}
2940
return self;
3041
}
3142

43+
- (void)dealloc {
44+
[[NSNotificationCenter defaultCenter] removeObserver:self];
45+
}
46+
47+
3248
- (void)parseReferringURL:(NSURL *)url {
3349
NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO];
3450
for (NSURLQueryItem *item in components.queryItems) {
@@ -107,6 +123,7 @@ - (NSDictionary *)referringURLQueryParamsForEndpoint:(NSString *)endpoint {
107123
params[BRANCH_REQUEST_KEY_META_CAMPAIGN_IDS] = [self metaCampaignIDsForEndpoint:endpoint];
108124
params[BRANCH_REQUEST_KEY_GCLID] = [self gclidValueForEndpoint:endpoint];
109125
[params addEntriesFromDictionary:[self gbraidValuesForEndpoint:endpoint]];
126+
params[BRANCH_REQUEST_KEY_SCCID] = [self sccidValueForEndpoint:endpoint];
110127

111128
return params;
112129
}
@@ -153,8 +170,15 @@ - (NSDictionary *)gbraidValuesForEndpoint:(NSString *)endpoint {
153170
return returnedParams;
154171
}
155172

173+
- (NSString *)sccidValueForEndpoint:(NSString *)endpoint {
174+
if (([endpoint containsString:@"/v2/event"]) || ([endpoint containsString:@"/v1/open"]) || ([endpoint containsString:@"/v1/install"]) ) {
175+
return self.urlQueryParameters[BRANCH_REQUEST_KEY_SCCID].value;
176+
}
177+
return nil;
178+
}
179+
156180
- (BOOL)isSupportedQueryParameter:(NSString *)param {
157-
NSArray *validURLQueryParameters = @[BRANCH_REQUEST_KEY_REFERRER_GBRAID, BRANCH_REQUEST_KEY_GCLID];
181+
NSArray *validURLQueryParameters = @[BRANCH_REQUEST_KEY_REFERRER_GBRAID, BRANCH_REQUEST_KEY_GCLID, BRANCH_REQUEST_KEY_SCCID];
158182
return [self isSupportedQueryParameter:param validParams:validURLQueryParameters];
159183
}
160184

@@ -266,4 +290,10 @@ - (void)checkForAndMigrateOldGbraid {
266290
}
267291
}
268292

293+
- (void)clearSccid {
294+
[self.urlQueryParameters removeObjectForKey:BRANCH_REQUEST_KEY_SCCID];
295+
self.preferenceHelper.referringURLQueryParameters = [self serializeToJson:self.urlQueryParameters];
296+
}
297+
298+
269299
@end

BranchSDK/BranchConstants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ extern NSString * const BRANCH_URL_QUERY_PARAMETERS_VALUE_KEY;
8989
extern NSString * const BRANCH_URL_QUERY_PARAMETERS_TIMESTAMP_KEY;
9090
extern NSString * const BRANCH_URL_QUERY_PARAMETERS_IS_DEEPLINK_KEY;
9191
extern NSString * const BRANCH_URL_QUERY_PARAMETERS_VALIDITY_WINDOW_KEY;
92+
extern NSString * const BRANCH_REQUEST_KEY_SCCID;
9293

9394
extern NSString * const BRANCH_REQUEST_ENDPOINT_SET_IDENTITY;
9495
extern NSString * const BRANCH_REQUEST_ENDPOINT_APP_LINK_SETTINGS;

BranchSDK/BranchConstants.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
NSString * const BRANCH_URL_QUERY_PARAMETERS_TIMESTAMP_KEY = @"timestamp";
8585
NSString * const BRANCH_URL_QUERY_PARAMETERS_IS_DEEPLINK_KEY = @"isDeepLink";
8686
NSString * const BRANCH_URL_QUERY_PARAMETERS_VALIDITY_WINDOW_KEY = @"validityWindow";
87+
NSString * const BRANCH_REQUEST_KEY_SCCID = @"sccid";
8788

8889
NSString * const BRANCH_REQUEST_ENDPOINT_SET_IDENTITY = @"profile";
8990
NSString * const BRANCH_REQUEST_ENDPOINT_APP_LINK_SETTINGS = @"app-link-settings";

0 commit comments

Comments
 (0)