Skip to content

Commit b9a771f

Browse files
committed
Initial commit
1 parent 296e2e6 commit b9a771f

File tree

9 files changed

+179
-2
lines changed

9 files changed

+179
-2
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// BNCReferringURLUtilityTests.m
3+
// Branch-SDK-Tests
4+
//
5+
// Created by Nipun Singh on 3/9/23.
6+
// Copyright © 2023 Branch, Inc. All rights reserved.
7+
//
8+
9+
#import <XCTest/XCTest.h>
10+
#import "BNCReferringURLUtility.h"
11+
12+
@interface BNCReferringURLUtilityTests : XCTestCase
13+
14+
@end
15+
16+
@implementation BNCReferringURLUtilityTests
17+
18+
- (void)setUp {
19+
// Put setup code here. This method is called before the invocation of each test method in the class.
20+
}
21+
22+
- (void)tearDown {
23+
// Put teardown code here. This method is called after the invocation of each test method in the class.
24+
}
25+
26+
- (void)testExample {
27+
NSURL *url = [NSURL URLWithString:@"https://www.google.com?gbraid=a123&test=456"];
28+
29+
BNCReferringURLUtility *utility = [BNCReferringURLUtility new];
30+
[utility parseReferringURL:url];
31+
}
32+
33+
@end

Branch-TestBed/Branch-TestBed.xcodeproj/project.pbxproj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,10 @@
274274
C1614D56285BC8A00098946B /* LinkPresentation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C1614D55285BC8A00098946B /* LinkPresentation.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
275275
C1614D5C285BD4AF0098946B /* BranchPluginSupport.h in Headers */ = {isa = PBXBuildFile; fileRef = C1614D5A285BD4AF0098946B /* BranchPluginSupport.h */; };
276276
C1614D5D285BD4AF0098946B /* BranchPluginSupport.m in Sources */ = {isa = PBXBuildFile; fileRef = C1614D5B285BD4AF0098946B /* BranchPluginSupport.m */; };
277+
C1CC887F29BAA06600BDD2B5 /* BNCReferringURLUtility.h in Headers */ = {isa = PBXBuildFile; fileRef = C1CC887D29BAA06600BDD2B5 /* BNCReferringURLUtility.h */; };
278+
C1CC888029BAA06600BDD2B5 /* BNCReferringURLUtility.m in Sources */ = {isa = PBXBuildFile; fileRef = C1CC887E29BAA06600BDD2B5 /* BNCReferringURLUtility.m */; };
279+
C1CC888229BAAFC000BDD2B5 /* BNCReferringURLUtilityTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C1CC888129BAAFC000BDD2B5 /* BNCReferringURLUtilityTests.m */; };
280+
C1CC888529BAB10D00BDD2B5 /* BNCReferringURLUtility.m in Sources */ = {isa = PBXBuildFile; fileRef = C1CC888329BAB0C600BDD2B5 /* BNCReferringURLUtility.m */; };
277281
E2B9474A1D15D75000F2270D /* BNCCallbacks.h in Headers */ = {isa = PBXBuildFile; fileRef = E2B947491D15D73900F2270D /* BNCCallbacks.h */; settings = {ATTRIBUTES = (Public, ); }; };
278282
E72489D228E40D0200DCD8FD /* PasteControlViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E72489D128E40D0200DCD8FD /* PasteControlViewController.m */; };
279283
E729974D28E2BBFA007D91B2 /* BranchPasteControl.h in Headers */ = {isa = PBXBuildFile; fileRef = E729974B28E2BBFA007D91B2 /* BranchPasteControl.h */; };
@@ -618,6 +622,11 @@
618622
C1614D55285BC8A00098946B /* LinkPresentation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = LinkPresentation.framework; path = System/Library/Frameworks/LinkPresentation.framework; sourceTree = SDKROOT; };
619623
C1614D5A285BD4AF0098946B /* BranchPluginSupport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BranchPluginSupport.h; sourceTree = "<group>"; };
620624
C1614D5B285BD4AF0098946B /* BranchPluginSupport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BranchPluginSupport.m; sourceTree = "<group>"; };
625+
C1CC887D29BAA06600BDD2B5 /* BNCReferringURLUtility.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BNCReferringURLUtility.h; sourceTree = "<group>"; };
626+
C1CC887E29BAA06600BDD2B5 /* BNCReferringURLUtility.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BNCReferringURLUtility.m; sourceTree = "<group>"; };
627+
C1CC888129BAAFC000BDD2B5 /* BNCReferringURLUtilityTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BNCReferringURLUtilityTests.m; sourceTree = "<group>"; };
628+
C1CC888329BAB0C600BDD2B5 /* BNCReferringURLUtility.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BNCReferringURLUtility.m; sourceTree = "<group>"; };
629+
C1CC888429BAB0E300BDD2B5 /* BNCReferringURLUtility.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BNCReferringURLUtility.h; sourceTree = "<group>"; };
621630
D258D2C41A794D64004A1C90 /* BranchActivityItemProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BranchActivityItemProvider.h; sourceTree = "<group>"; };
622631
D258D2C51A794D64004A1C90 /* BranchActivityItemProvider.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BranchActivityItemProvider.m; sourceTree = "<group>"; };
623632
E2B947491D15D73900F2270D /* BNCCallbacks.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BNCCallbacks.h; sourceTree = "<group>"; };
@@ -768,6 +777,7 @@
768777
5F2035CB240DDE90004FDC3E /* BNCDisableAdNetworkCalloutsTests.m */,
769778
5FDB04F324E6156800F2F267 /* BNCSKAdNetworkTests.m */,
770779
5FDF91582581CDF4009BE5A3 /* BNCPartnerParametersTests.m */,
780+
C1CC888129BAAFC000BDD2B5 /* BNCReferringURLUtilityTests.m */,
771781
);
772782
path = "Branch-SDK-Tests";
773783
sourceTree = "<group>";
@@ -913,6 +923,8 @@
913923
670016BB1946309100A9E103 /* BranchSDK */ = {
914924
isa = PBXGroup;
915925
children = (
926+
C1CC888429BAB0E300BDD2B5 /* BNCReferringURLUtility.h */,
927+
C1CC888329BAB0C600BDD2B5 /* BNCReferringURLUtility.m */,
916928
C12320B8280E2091007771C0 /* BranchQRCode.m */,
917929
C12320B6280E2060007771C0 /* BranchQRCode.h */,
918930
C1614D5A285BD4AF0098946B /* BranchPluginSupport.h */,
@@ -1071,6 +1083,8 @@
10711083
5FDF914425818280009BE5A3 /* BNCPartnerParameters.m */,
10721084
C10C61AB28248E5A00761D7E /* BNCQRCodeCache.h */,
10731085
C10C61AC28248E5A00761D7E /* BNCQRCodeCache.m */,
1086+
C1CC887D29BAA06600BDD2B5 /* BNCReferringURLUtility.h */,
1087+
C1CC887E29BAA06600BDD2B5 /* BNCReferringURLUtility.m */,
10741088
);
10751089
name = BranchSDK;
10761090
path = ../BranchSDK;
@@ -1113,6 +1127,7 @@
11131127
4DCAC8121F426F7C00405D1D /* BranchConstants.h in Headers */,
11141128
5F38022924DCC2E800E6FAFD /* BNCNetworkServiceProtocol.h in Headers */,
11151129
5F437E3D237E03C00052064B /* BNCDeviceSystem.h in Headers */,
1130+
C1CC887F29BAA06600BDD2B5 /* BNCReferringURLUtility.h in Headers */,
11161131
C12320B7280E2060007771C0 /* BranchQRCode.h in Headers */,
11171132
4DCAC8171F426F7C00405D1D /* BranchDeepLinkingController.h in Headers */,
11181133
5F892EB92360EFE90023AEC1 /* BNCAppleSearchAds.h in Headers */,
@@ -1425,6 +1440,7 @@
14251440
isa = PBXSourcesBuildPhase;
14261441
buildActionMask = 2147483647;
14271442
files = (
1443+
C1CC888029BAA06600BDD2B5 /* BNCReferringURLUtility.m in Sources */,
14281444
C12320B9280E2091007771C0 /* BranchQRCode.m in Sources */,
14291445
5FDF914625818280009BE5A3 /* BNCPartnerParameters.m in Sources */,
14301446
5F38020F24DCC2E800E6FAFD /* BNCServerRequest.m in Sources */,
@@ -1535,6 +1551,7 @@
15351551
isa = PBXSourcesBuildPhase;
15361552
buildActionMask = 2147483647;
15371553
files = (
1554+
C1CC888529BAB10D00BDD2B5 /* BNCReferringURLUtility.m in Sources */,
15381555
5F22AFC0240600A200837CF5 /* BNCCallbackMap.m in Sources */,
15391556
4D1683B72098C902008819E3 /* BNCTestCase.m in Sources */,
15401557
4D1683B82098C902008819E3 /* BNCEncodingUtils.Test.m in Sources */,
@@ -1558,6 +1575,7 @@
15581575
4D1683CA2098C902008819E3 /* BNCPreferenceHelperTests.m in Sources */,
15591576
4AB16368239E3A2700D42931 /* DispatchToIsolationQueueTests.m in Sources */,
15601577
5F8BB66E278771890055D2DC /* BNCKeyChainTests.m in Sources */,
1578+
C1CC888229BAAFC000BDD2B5 /* BNCReferringURLUtilityTests.m in Sources */,
15611579
5F892ECE23624E0A0023AEC1 /* BNCFacebookAppLinksTests.m in Sources */,
15621580
5FE694382405FA2700E3AEE2 /* BNCCallbackMapTests.m in Sources */,
15631581
5FDB04F424E6156800F2F267 /* BNCSKAdNetworkTests.m in Sources */,

BranchSDK/BNCPreferenceHelper.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#define FILE_NAME [[NSString stringWithUTF8String:__FILE__] lastPathComponent]
1616
#define LINE_NUM __LINE__
1717

18+
19+
1820
NSURL* /* _Nonnull */ BNCURLForBranchDirectory(void);
1921

2022
@interface BNCPreferenceHelper : NSObject
@@ -71,6 +73,7 @@ NSURL* /* _Nonnull */ BNCURLForBranchDirectory(void);
7173
@property (copy, nonatomic) NSString *referrerGBRAID;
7274
@property (assign, nonatomic) NSTimeInterval referrerGBRAIDValidityWindow;
7375
@property (strong, nonatomic) NSDate *referrerGBRAIDInitDate;
76+
@property (strong, nonatomic) NSMutableDictionary *referringURLQueryParameters;
7477

7578
@property (assign, nonatomic) NSInteger skanCurrentWindow;
7679
@property (assign, nonatomic) NSInteger highestConversionValueSent;

BranchSDK/BNCPreferenceHelper.m

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,13 @@
4949
static NSString * const BRANCH_PREFS_KEY_REFERRER_GBRAID = @"bnc_referrer_gbraid";
5050
static NSString * const BRANCH_PREFS_KEY_REFERRER_GBRAID_WINDOW = @"bnc_referrer_gbraid_window";
5151
static NSString * const BRANCH_PREFS_KEY_REFERRER_GBRAID_INIT_DATE = @"bnc_referrer_gbraid_init_date";
52+
static NSString * const BRANCH_PREFS_KEY_REFERRER_GCLID = @"bnc_referrer_gclid";
5253
static NSString * const BRANCH_PREFS_KEY_SKAN_CURRENT_WINDOW = @"bnc_skan_current_window";
5354
static NSString * const BRANCH_PREFS_KEY_FIRST_APP_LAUNCH_TIME = @"bnc_first_app_launch_time";
5455
static NSString * const BRANCH_PREFS_KEY_SKAN_HIGHEST_CONV_VALUE_SENT = @"bnc_skan_send_highest_conv_value";
5556
static NSString * const BRANCH_PREFS_KEY_SKAN_INVOKE_REGISTER_APP = @"bnc_invoke_register_app";
57+
58+
static NSString * const BRANCH_PREFS_KEY_REFFERING_URL_QUERY_PARAMETERS = @"bnc_referring_url_query_parameters";
5659

5760
NSURL* /* _Nonnull */ BNCURLForBranchDirectory_Unthreaded(void);
5861

@@ -102,7 +105,8 @@ @implementation BNCPreferenceHelper
102105
referrerGBRAIDValidityWindow = _referrerGBRAIDValidityWindow,
103106
skanCurrentWindow = _skanCurrentWindow,
104107
firstAppLaunchTime = _firstAppLaunchTime,
105-
highestConversionValueSent = _highestConversionValueSent;
108+
highestConversionValueSent = _highestConversionValueSent,
109+
referringURLQueryParameters = _referringURLQueryParameters;
106110

107111
+ (BNCPreferenceHelper *)sharedInstance {
108112
static BNCPreferenceHelper *preferenceHelper;
@@ -674,6 +678,14 @@ - (void)setSendCloseRequests:(BOOL)disabled {
674678
}
675679
}
676680

681+
- (void)setReferringURLQueryParameters:(NSMutableDictionary *)parameter {
682+
683+
}
684+
685+
- (NSMutableDictionary *)referringURLQueryParameters {
686+
return (NSMutableDictionary *)[self readObjectFromDefaults:BRANCH_PREFS_KEY_REFFERING_URL_QUERY_PARAMETERS];
687+
}
688+
677689
- (NSString *) referrerGBRAID {
678690
@synchronized(self) {
679691
if (!_referrerGBRAID) {

BranchSDK/BNCReferringURLUtility.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// BNCReferringURLUtility.h
3+
// Branch
4+
//
5+
// Created by Nipun Singh on 3/9/23.
6+
// Copyright © 2023 Branch, Inc. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
NS_ASSUME_NONNULL_BEGIN
12+
13+
14+
@interface BNCReferringURLUtility : NSObject
15+
16+
//Parses the referring URL query parameters from a URL
17+
- (void)parseReferringURL:(NSURL *)url;
18+
19+
//Convert the URL parameters to dictionary
20+
- (NSDictionary *)referringURLDictionary;
21+
22+
- (NSDictionary *)getQueryParams(NSString *)event;
23+
24+
@end
25+
26+
NS_ASSUME_NONNULL_END

BranchSDK/BNCReferringURLUtility.m

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
//
2+
// BNCReferringURLUtility.m
3+
// Branch
4+
//
5+
// Created by Nipun Singh on 3/9/23.
6+
// Copyright © 2023 Branch, Inc. All rights reserved.
7+
//
8+
9+
#import "BNCReferringURLUtility.h"
10+
#import "BNCPreferenceHelper.h"
11+
12+
//@interface BNCReferringURLQueryParameter: NSObject
13+
//
14+
//@property (copy, nonatomic) NSString *name;
15+
//@property (copy, nonatomic) NSString *value;
16+
//@property (assign, nonatomic) NSTimeInterval validityWindow;
17+
//@property (strong, nonatomic) NSDate *startDate;
18+
//
19+
//@end
20+
21+
@interface BNCReferringURLUtility()
22+
23+
@property (strong, readwrite, nonatomic) NSMutableDictionary<NSString *, NSMutableDictionary *> *urlQueryParameters;
24+
25+
@end
26+
27+
@implementation BNCReferringURLUtility
28+
29+
- (instancetype)init {
30+
self = [super init];
31+
if (self) {
32+
self.urlQueryParameters = [BNCPreferenceHelper sharedInstance].referringURLQueryParameters;
33+
[self initializeURLQueryParameters];
34+
}
35+
36+
return self;
37+
}
38+
39+
- (void)initializeURLQueryParameters {
40+
self.urlQueryParameters = [NSMutableDictionary<NSString *, NSMutableDictionary *> new];
41+
42+
//Don't init if it was loaded from disc
43+
NSMutableDictionary *gbraid = [NSMutableDictionary new];
44+
gbraid[@"name"] = @"gbraid";
45+
gbraid[@"is_deeplink"] = [NSNumber numberWithBool:YES];
46+
[self.urlQueryParameters setValue: gbraid forKey:@"gbraid"];
47+
48+
NSMutableDictionary *gclid = [NSMutableDictionary new];
49+
gbraid[@"name"] = @"gclid";
50+
[self.urlQueryParameters setValue: gclid forKey:@"gclid"];
51+
52+
//Consider how to load the existing gbraid
53+
}
54+
55+
- (void)parseReferringURL:(NSURL *)url {
56+
NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO];
57+
for(NSURLQueryItem *item in components.queryItems){
58+
59+
NSMutableDictionary *param = self.urlQueryParameters[item.name];
60+
if (param != nil) {
61+
param[@"value"] = item.value;
62+
param[@"initDate"] = [NSDate date];
63+
}
64+
}
65+
66+
[BNCPreferenceHelper sharedInstance].referringURLQueryParameters = self.urlQueryParameters;
67+
}
68+
69+
- (NSDictionary *)referringURLDictionary {
70+
return [NSDictionary new];
71+
}
72+
73+
- (NSDictionary *)getQueryParams {
74+
//Get
75+
return nil;
76+
}
77+
78+
@end

BranchSDK/BNCServerInterface.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,9 @@ - (NSMutableDictionary *)prepareParamDict:(NSDictionary *)params
456456
fullParamDict[BRANCH_REQUEST_KEY_INSTRUMENTATION] = instrumentationDictionary;
457457
}
458458
}
459+
460+
//utility getQueryParams(requestEndpoint) -> [Dictionary]
461+
459462
// For DOWNSTREAM EVENTS v2/events, include referrer_gbraid in request if available
460463
if([self.requestEndpoint containsString:@"/v2/event"] || [self.requestEndpoint containsString:@"/v1/open"]){
461464
NSString *ref_gbraid = self.preferenceHelper.referrerGBRAID;
@@ -469,7 +472,7 @@ - (NSMutableDictionary *)prepareParamDict:(NSDictionary *)params
469472
if ([now compare:expirationDate] == NSOrderedAscending) {
470473
fullParamDict[BRANCH_REQUEST_KEY_REFERRER_GBRAID] = ref_gbraid;
471474
long long timestampInMilliSec = (long long)([initDate timeIntervalSince1970] * 1000.0);
472-
fullParamDict[BRANCH_REQUEST_KEY_REFERRER_GBRAID_TIMESTAMP] = [NSString stringWithFormat:@"%lld", timestampInMilliSec];
475+
//fullParamDict[BRANCH_REQUEST_KEY_REFERRER_GBRAID_TIMESTAMP] = [NSString stringWithFormat:@"%lld", timestampInMilliSec];
473476
}
474477
}
475478
}

BranchSDK/Branch.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,8 @@ - (BOOL)handleDeepLink:(NSURL *)url sceneIdentifier:(NSString *)sceneIdentifier
711711
// this allows foreground links to callback
712712
self.initializationStatus = BNCInitStatusUninitialized;
713713

714+
//ParseURL
715+
714716
//check the referring url/uri for query parameter gbraid
715717
NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO];
716718
NSString *gbraidValue = nil;

BranchSDK/BranchConstants.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@
7777
NSString * const BRANCH_REQUEST_METADATA_KEY_SCANTIME_WINDOW = @"skan_time_window";
7878
NSString * const BRANCH_REQUEST_KEY_REFERRER_GBRAID = @"gbraid";
7979
NSString * const BRANCH_REQUEST_KEY_REFERRER_GBRAID_TIMESTAMP = @"gbraid_timestamp";
80+
NSString * const BRANCH_REQUEST_KEY_GCLID = @"gclid";
81+
NSString * const BRANCH_REQUEST_KEY_IS_DEEPLINK_GBRAID = @"is_deeplink_gbraid";
8082

8183
NSString * const BRANCH_REQUEST_ENDPOINT_SET_IDENTITY = @"profile";
8284
NSString * const BRANCH_REQUEST_ENDPOINT_APP_LINK_SETTINGS = @"app-link-settings";

0 commit comments

Comments
 (0)