Skip to content

Commit 29dcb79

Browse files
authored
Merge pull request #442 from BranchMetrics/Content-Discovery-2
Adding Content discovery to current staging
2 parents e70280d + 3b2fab7 commit 29dcb79

14 files changed

+674
-6
lines changed

Branch-SDK/Branch-SDK/BNCPreferenceHelper.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
@property (assign, nonatomic) NSTimeInterval retryInterval;
3636
@property (assign, nonatomic) NSTimeInterval timeout;
3737
@property (strong, nonatomic) NSString *externalIntentURI;
38+
@property (strong, nonatomic) NSMutableDictionary *savedAnalyticsData;
3839

3940
+ (BNCPreferenceHelper *)preferenceHelper;
4041

@@ -68,4 +69,10 @@
6869

6970
- (void)log:(NSString *)filename line:(int)line message:(NSString *)format, ...;
7071
- (void)logWarning:(NSString *)message;
72+
73+
- (void)saveBranchAnalyticsData:(NSDictionary *)analyticsData;
74+
- (void)clearBranchAnalyticsData;
75+
- (NSMutableDictionary *)getBranchAnalyticsData;
76+
- (NSDictionary *)getContentAnalyticsManifest;
77+
- (void)saveContentAnalyticsManifest:(NSDictionary *)cdManifest;
7178
@end

Branch-SDK/Branch-SDK/BNCPreferenceHelper.m

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
NSString * const BRANCH_PREFS_KEY_CREDIT_BASE = @"bnc_credit_base_";
4040

4141
NSString * const BRANCH_PREFS_KEY_BRANCH_VIEW_USAGE_CNT = @"bnc_branch_view_usage_cnt_";
42+
NSString * const BRANCH_PREFS_KEY_ANALYTICAL_DATA = @"bnc_branch_analytical_data";
43+
NSString * const BRANCH_PREFS_KEY_ANALYTICS_MANIFEST = @"bnc_branch_analytics_manifest";
4244

4345
// The name of this key was specified in the account-creation API integration
4446
static NSString * const BNC_BRANCH_FABRIC_APP_KEY_KEY = @"branch_key";
@@ -545,6 +547,45 @@ - (NSInteger)getBranchViewCount:(NSString *)branchViewID {
545547
return count;
546548
}
547549

550+
- (void)saveBranchAnalyticsData:(NSDictionary *)analyticsData {
551+
if (_sessionID) {
552+
if (!_savedAnalyticsData) {
553+
_savedAnalyticsData = [self getBranchAnalyticsData];
554+
}
555+
NSMutableArray *viewDataArray = [_savedAnalyticsData objectForKey:_sessionID];
556+
if (!viewDataArray) {
557+
viewDataArray = [[NSMutableArray alloc] init];
558+
[_savedAnalyticsData setObject:viewDataArray forKey:_sessionID];
559+
}
560+
[viewDataArray addObject:analyticsData];
561+
[self writeObjectToDefaults:BRANCH_PREFS_KEY_ANALYTICAL_DATA value:_savedAnalyticsData];
562+
}
563+
}
564+
565+
- (void)clearBranchAnalyticsData {
566+
[self writeObjectToDefaults:BRANCH_PREFS_KEY_ANALYTICAL_DATA value:nil];
567+
_savedAnalyticsData = nil;
568+
}
569+
570+
- (NSMutableDictionary *)getBranchAnalyticsData {
571+
NSMutableDictionary *analyticsDataObj = _savedAnalyticsData;
572+
if (!analyticsDataObj) {
573+
analyticsDataObj = (NSMutableDictionary *)[self readObjectFromDefaults:BRANCH_PREFS_KEY_ANALYTICAL_DATA];
574+
if (!analyticsDataObj) {
575+
analyticsDataObj = [[NSMutableDictionary alloc] init];
576+
}
577+
}
578+
return analyticsDataObj;
579+
}
580+
581+
- (void)saveContentAnalyticsManifest:(NSDictionary *)cdManifest {
582+
[self writeObjectToDefaults:BRANCH_PREFS_KEY_ANALYTICS_MANIFEST value:cdManifest];
583+
}
584+
585+
- (NSDictionary *)getContentAnalyticsManifest {
586+
return (NSDictionary *)[self readObjectFromDefaults:BRANCH_PREFS_KEY_ANALYTICS_MANIFEST];
587+
}
588+
548589
#pragma mark - Writing To Persistence
549590

550591
- (void)writeIntegerToDefaults:(NSString *)key value:(NSInteger)value {

Branch-SDK/Branch-SDK/Branch.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#import "BranchInstallRequest.h"
3434
#import "BranchSpotlightUrlRequest.h"
3535
#import "BranchRegisterViewRequest.h"
36+
#import "BranchContentDiscoverer.h"
3637

3738
//Fabric
3839
#import "../Fabric/FABKitProtocol.h"
@@ -1114,6 +1115,11 @@ - (void)callClose {
11141115
if (self.isInitialized) {
11151116
self.isInitialized = NO;
11161117

1118+
BranchContentDiscoverer *contentDiscoverer = [BranchContentDiscoverer getInstance];
1119+
if (contentDiscoverer) {
1120+
[contentDiscoverer stopContentDiscoveryTask];
1121+
}
1122+
11171123
if (self.preferenceHelper.sessionID && ![self.requestQueue containsClose]) {
11181124
BranchCloseRequest *req = [[BranchCloseRequest alloc] init];
11191125
[self.requestQueue enqueue:req];

Branch-SDK/Branch-SDK/BranchConstants.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,25 @@ extern NSString * const BRANCH_LINK_DATA_KEY_CONTENT_TYPE;
104104
extern NSString * const BRANCH_LINK_DATA_KEY_EMAIL_SUBJECT;
105105

106106
extern NSString * const BRANCH_SPOTLIGHT_PREFIX;
107+
108+
extern NSString * const BRANCH_MANIFEST_VERSION_KEY;
109+
extern NSString * const BRANCH_HASH_MODE_KEY;
110+
extern NSString * const BRANCH_MANIFEST_KEY;
111+
extern NSString * const BRANCH_PATH_KEY;
112+
extern NSString * const BRANCH_FILTERED_KEYS;
113+
extern NSString * const BRANCH_MAX_TEXT_LEN_KEY;
114+
extern NSString * const BRANCH_MAX_VIEW_HISTORY_LENGTH;
115+
extern NSString * const BRANCH_MAX_PACKET_SIZE_KEY;
116+
extern NSString * const BRANCH_CONTENT_DISCOVER_KEY;
117+
extern NSString * const BRANCH_BUNDLE_IDENTIFIER;
118+
extern NSString * const BRANCH_TIME_STAMP_KEY;
119+
extern NSString * const BRANCH_TIME_STAMP_CLOSE_KEY;
120+
extern NSString * const BRANCH_NAV_PATH_KEY;
121+
extern NSString * const BRANCH_REFERRAL_LINK_KEY;
122+
extern NSString * const BRANCH_CONTENT_LINK_KEY;
123+
extern NSString * const BRANCH_CONTENT_META_DATA_KEY;
124+
extern NSString * const BRANCH_VIEW_KEY;
125+
extern NSString * const BRANCH_CONTENT_DATA_KEY;
126+
extern NSString * const BRANCH_CONTENT_KEYS_KEY;
127+
extern NSString * const BRANCH_PACKAGE_NAME_KEY;
128+
extern NSString * const BRANCH_ENTITIES_KEY;

Branch-SDK/Branch-SDK/BranchConstants.m

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,25 @@
103103
NSString * const BRANCH_LINK_DATA_KEY_EMAIL_SUBJECT = @"$email_subject";
104104

105105
NSString * const BRANCH_SPOTLIGHT_PREFIX = @"io.branch.link.v1";
106+
107+
NSString * const BRANCH_MANIFEST_VERSION_KEY = @"mv";
108+
NSString * const BRANCH_HASH_MODE_KEY = @"h";
109+
NSString * const BRANCH_MANIFEST_KEY = @"m";
110+
NSString * const BRANCH_PATH_KEY = @"p";
111+
NSString * const BRANCH_FILTERED_KEYS = @"ck";
112+
NSString * const BRANCH_MAX_TEXT_LEN_KEY = @"mtl";
113+
NSString * const BRANCH_MAX_VIEW_HISTORY_LENGTH = @"mhl";
114+
NSString * const BRANCH_MAX_PACKET_SIZE_KEY = @"mps";
115+
NSString * const BRANCH_CONTENT_DISCOVER_KEY = @"cd";
116+
NSString * const BRANCH_BUNDLE_IDENTIFIER = @"pn";
117+
NSString * const BRANCH_TIME_STAMP_KEY = @"ts";
118+
NSString * const BRANCH_TIME_STAMP_CLOSE_KEY = @"tc";
119+
NSString * const BRANCH_NAV_PATH_KEY = @"n";
120+
NSString * const BRANCH_REFERRAL_LINK_KEY = @"rl";
121+
NSString * const BRANCH_CONTENT_LINK_KEY = @"cl";
122+
NSString * const BRANCH_CONTENT_META_DATA_KEY = @"cm";
123+
NSString * const BRANCH_VIEW_KEY = @"v";
124+
NSString * const BRANCH_CONTENT_DATA_KEY = @"cd";
125+
NSString * const BRANCH_CONTENT_KEYS_KEY = @"ck";
126+
NSString * const BRANCH_PACKAGE_NAME_KEY = @"p";
127+
NSString * const BRANCH_ENTITIES_KEY = @"e";
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// ContentDiscoverer.h
3+
// Branch-TestBed
4+
//
5+
// Created by Sojan P.R. on 8/17/16.
6+
// Copyright © 2016 Branch Metrics. All rights reserved.
7+
//
8+
#import <UIKit/UIKit.h>
9+
#import "BranchContentDiscoveryManifest.h"
10+
11+
#ifndef ContentDiscoverer_h
12+
#define ContentDiscoverer_h
13+
14+
15+
#endif /* ContentDiscoverer_h */
16+
17+
@interface BranchContentDiscoverer : NSObject
18+
19+
//----------- Methods ----------------//
20+
+ (BranchContentDiscoverer *)getInstance:(BranchContentDiscoveryManifest *)manifest;
21+
+ (BranchContentDiscoverer *)getInstance;
22+
- (void)startContentDiscoveryTask;
23+
- (void)stopContentDiscoveryTask;
24+
25+
@end

0 commit comments

Comments
 (0)