Skip to content

Commit 47ad78d

Browse files
Merge pull request #1415 from BranchMetrics/gdeluna-branch/AddTraceLogging
Add trace logging
2 parents ae6c89c + 8f53dd3 commit 47ad78d

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

Sources/BranchSDK/BNCPreferenceHelper.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,11 @@ - (NSString *)sessionParams {
388388

389389
- (void)setSessionParams:(NSString *)sessionParams {
390390
@synchronized (self) {
391+
[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Setting session params %@", sessionParams] error:nil];
391392
if (sessionParams == nil || ![_sessionParams isEqualToString:sessionParams]) {
392393
_sessionParams = sessionParams;
393394
[self writeObjectToDefaults:BRANCH_PREFS_KEY_SESSION_PARAMS value:sessionParams];
395+
[[BranchLogger shared] logVerbose:@"Params set" error:nil];
394396
}
395397
}
396398
}
@@ -845,6 +847,7 @@ - (void) clearTrackingInformation {
845847
self.userIdentity = nil;
846848
self.referringURLQueryParameters = nil;
847849
self.anonID = nil;
850+
[[BranchLogger shared] logVerbose:@"Tracking information cleared" error:nil];
848851
}
849852
}
850853

Sources/BranchSDK/BNCReferringURLUtility.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ - (void)dealloc {
4646

4747

4848
- (void)parseReferringURL:(NSURL *)url {
49+
[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Parsing URL %@", url] error:nil];
50+
4951
NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO];
5052
for (NSURLQueryItem *item in components.queryItems) {
5153
if ([self isSupportedQueryParameter:item.name]) {

Sources/BranchSDK/BNCServerInterface.m

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ - (void)postRequest:(NSDictionary *)post url:(NSString *)url key:(NSString *)key
6161

6262
- (void)postRequest:(NSDictionary *)post url:(NSString *)url retryNumber:(NSInteger)retryNumber key:(NSString *)key callback:(BNCServerCallback)callback {
6363

64+
[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"retryNumber %ld", retryNumber] error:nil];
65+
6466
// TODO: confirm it's ok to send full URL instead of with the domain trimmed off
6567
self.requestEndpoint = url;
6668
NSURLRequest *request = [self preparePostRequest:post url:url key:key retryNumber:retryNumber];
@@ -141,7 +143,8 @@ - (void)genericHTTPRequest:(NSURLRequest *)request retryNumber:(NSInteger)retryN
141143
// Drops non-linking requests when tracking is disabled
142144
if (Branch.trackingDisabled) {
143145
NSString *endpoint = request.URL.absoluteString;
144-
146+
[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Tracking is disabled, checking if %@ is linking request.", endpoint] error:nil];
147+
145148
if (![self isLinkingRelatedRequest:endpoint]) {
146149
[[BNCPreferenceHelper sharedInstance] clearTrackingInformation];
147150
NSError *error = [NSError branchErrorWithCode:BNCTrackingDisabledError];
@@ -292,6 +295,10 @@ - (BNCServerResponse *)processServerResponse:(NSURLResponse *)response data:(NSD
292295
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
293296
NSString *requestId = httpResponse.allHeaderFields[@"X-Branch-Request-Id"];
294297

298+
if ([[BranchLogger shared] shouldLog:BranchLogLevelVerbose]) {
299+
[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Processing response %@", requestId] error:nil];
300+
}
301+
295302
if (!error) {
296303
serverResponse.statusCode = @([httpResponse statusCode]);
297304
serverResponse.data = [BNCEncodingUtils decodeJsonDataToDictionary:data];

Sources/BranchSDK/Branch.m

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,8 @@ + (BOOL)trackingDisabled {
504504

505505
+ (void)setTrackingDisabled:(BOOL)disabled {
506506
@synchronized(self) {
507+
[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"setTrackingDisabled to %d", disabled] error:nil];
508+
507509
BOOL currentSetting = self.trackingDisabled;
508510
if (!!currentSetting == !!disabled)
509511
return;
@@ -515,6 +517,8 @@ + (void)setTrackingDisabled:(BOOL)disabled {
515517
Branch *branch = Branch.getInstance;
516518
[branch clearNetworkQueue];
517519
branch.initializationStatus = BNCInitStatusUninitialized;
520+
[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"initializationStatus %ld", branch.initializationStatus] error:nil];
521+
518522
[branch.linkCache clear];
519523
// Release the lock in case it's locked:
520524
[BranchOpenRequest releaseOpenResponseLock];
@@ -668,10 +672,12 @@ - (BOOL)handleDeepLink:(NSURL *)url {
668672
}
669673

670674
- (BOOL)handleDeepLink:(NSURL *)url sceneIdentifier:(NSString *)sceneIdentifier {
675+
[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Handle deep link %@", url] error:nil];
671676

672677
// we've been resetting the session on all deeplinks for quite some time
673678
// this allows foreground links to callback
674679
self.initializationStatus = BNCInitStatusUninitialized;
680+
[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"initializationStatus %ld", self.initializationStatus] error:nil];
675681

676682
//Check the referring url/uri for query parameters and save them
677683
BNCReferringURLUtility *utility = [BNCReferringURLUtility new];
@@ -702,6 +708,8 @@ - (BOOL)handleDeepLink:(NSURL *)url sceneIdentifier:(NSString *)sceneIdentifier
702708
- (BOOL)handleSchemeDeepLink_private:(NSURL*)url sceneIdentifier:(NSString *)sceneIdentifier {
703709
BOOL handled = NO;
704710
self.preferenceHelper.referringURL = nil;
711+
[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Set referringURL to %@", self.preferenceHelper.referringURL] error:nil];
712+
705713
if (url && ![url isEqual:[NSNull null]]) {
706714

707715
NSString *urlScheme = [url scheme];
@@ -712,12 +720,14 @@ - (BOOL)handleSchemeDeepLink_private:(NSURL*)url sceneIdentifier:(NSString *)sce
712720
if (urlScheme && [scheme isEqualToString:urlScheme]) {
713721
self.preferenceHelper.externalIntentURI = [url absoluteString];
714722
self.preferenceHelper.referringURL = [url absoluteString];
723+
[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Allowed scheme list, set externalIntentURI and referringURL to %@", [url absoluteString]] error:nil];
715724
break;
716725
}
717726
}
718727
} else {
719728
self.preferenceHelper.externalIntentURI = [url absoluteString];
720729
self.preferenceHelper.referringURL = [url absoluteString];
730+
[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Set externalIntentURI and referringURL to %@", [url absoluteString]] error:nil];
721731
}
722732

723733
NSString *query = [url fragment];
@@ -762,6 +772,7 @@ - (BOOL)handleUniversalDeepLink_private:(NSString*)urlString sceneIdentifier:(NS
762772
if (urlString.length) {
763773
self.preferenceHelper.universalLinkUrl = urlString;
764774
self.preferenceHelper.referringURL = urlString;
775+
[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Set universalLinkUrl and referringURL to %@", urlString] error:nil];
765776
}
766777

767778
[self initUserSessionAndCallCallback:YES sceneIdentifier:sceneIdentifier urlString:urlString];
@@ -1699,16 +1710,25 @@ - (void)applicationDidBecomeActive {
16991710
dispatch_async(self.isolationQueue, ^(){
17001711
// if necessary, creates a new organic open
17011712
BOOL installOrOpenInQueue = [self.requestQueue containsInstallOrOpen];
1713+
1714+
[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"applicationDidBecomeActive installOrOpenInQueue %d", installOrOpenInQueue] error:nil];
1715+
17021716
if (!Branch.trackingDisabled && self.initializationStatus != BNCInitStatusInitialized && !installOrOpenInQueue) {
1717+
[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"applicationDidBecomeActive trackingDisabled %d initializationStatus %d installOrOpenInQueue %d", Branch.trackingDisabled, self.initializationStatus, installOrOpenInQueue] error:nil];
1718+
17031719
[self initUserSessionAndCallCallback:YES sceneIdentifier:nil urlString:nil];
17041720
}
17051721
});
17061722
}
17071723

17081724
- (void)applicationWillResignActive {
1725+
[[BranchLogger shared] logVerbose:@"applicationWillResignActive" error:nil];
1726+
17091727
dispatch_async(self.isolationQueue, ^(){
17101728
if (!Branch.trackingDisabled) {
17111729
self.initializationStatus = BNCInitStatusUninitialized;
1730+
[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"applicationWillResignActive initializationStatus %ld", self.initializationStatus] error:nil];
1731+
17121732
[self.requestQueue persistImmediately];
17131733
[BranchOpenRequest setWaitNeededForOpenResponseLock];
17141734
}
@@ -1842,6 +1862,8 @@ - (void)processNextQueueItem {
18421862
self.networkCount = 1;
18431863
dispatch_semaphore_signal(self.processing_sema);
18441864
BNCServerRequest *req = [self.requestQueue peek];
1865+
1866+
[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Processing %@", req]error:nil];
18451867

18461868
if (req) {
18471869

@@ -2035,6 +2057,8 @@ - (void)initializeSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSS
20352057
}
20362058

20372059
self.initializationStatus = BNCInitStatusInitializing;
2060+
[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"initializationStatus %ld", self.initializationStatus] error:nil];
2061+
20382062
[self processNextQueueItem];
20392063
});
20402064
}
@@ -2044,6 +2068,8 @@ - (void)initializeSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSS
20442068
- (void)handleInitSuccessAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSString *)sceneIdentifier {
20452069

20462070
self.initializationStatus = BNCInitStatusInitialized;
2071+
[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"initializationStatus %ld", self.initializationStatus] error:nil];
2072+
20472073
NSDictionary *latestReferringParams = [self getLatestReferringParams];
20482074

20492075
if ([latestReferringParams[@"_branch_validate"] isEqualToString:@"060514"]) {
@@ -2260,6 +2286,7 @@ - (void)presentSharingViewController:(UIViewController <BranchDeepLinkingControl
22602286

22612287
- (void)handleInitFailure:(NSError *)error callCallback:(BOOL)callCallback sceneIdentifier:(NSString *)sceneIdentifier {
22622288
self.initializationStatus = BNCInitStatusUninitialized;
2289+
[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"initializationStatus %ld", self.initializationStatus] error:nil];
22632290

22642291
if (callCallback) {
22652292
if (self.sceneSessionInitWithCallback) {

0 commit comments

Comments
 (0)