Skip to content

Commit d614c7f

Browse files
authored
Merge pull request #415 from BranchMetrics/buo
Make BUO great!
2 parents a667280 + 214b051 commit d614c7f

File tree

8 files changed

+62
-4
lines changed

8 files changed

+62
-4
lines changed

Branch-SDK/Branch-SDK/Branch.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,20 @@ extern NSString * const BRANCH_INIT_KEY_PHONE_NUMBER;
103103
extern NSString * const BRANCH_INIT_KEY_IS_FIRST_SESSION;
104104
extern NSString * const BRANCH_INIT_KEY_CLICKED_BRANCH_LINK;
105105

106+
// BUO Constants
107+
extern NSString * const BNCCanonicalIdList;
108+
extern NSString * const BNCPurchaseAmount;
109+
extern NSString * const BNCPurchaseCurrency;
110+
extern NSString * const BNCCanonicalIdList;
111+
extern NSString * const BNCPurchaseAmount;
112+
extern NSString * const BNCRegisterViewEvent;
113+
extern NSString * const BNCAddToWishlistEvent;
114+
extern NSString * const BNCAddToCartEvent;
115+
extern NSString * const BNCPurchaseInitiatedEvent;
116+
extern NSString * const BNCPurchasedEvent;
117+
extern NSString * const BNCShareInitiatedEvent;
118+
extern NSString * const BNCShareCompletedEvent;
119+
106120
#pragma mark - Branch Enums
107121
typedef NS_ENUM(NSUInteger, BranchCreditHistoryOrder) {
108122
BranchMostRecentFirst,

Branch-SDK/Branch-SDK/Branch.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@
5656
NSString * const BRANCH_INIT_KEY_CLICKED_BRANCH_LINK = @"+clicked_branch_link";
5757
NSString * const BRANCH_PUSH_NOTIFICATION_PAYLOAD_KEY = @"branch";
5858

59+
NSString * const BNCCanonicalIdList = @"$canonical_identifier_list";
60+
NSString * const BNCPurchaseAmount = @"$amount";
61+
NSString * const BNCPurchaseCurrency = @"$currency";
62+
NSString * const BNCRegisterViewEvent = @"View";
63+
NSString * const BNCAddToWishlistEvent = @"Add to Wishlist";
64+
NSString * const BNCAddToCartEvent = @"Add to Cart";
65+
NSString * const BNCPurchaseInitiatedEvent = @"Purchase Started";
66+
NSString * const BNCPurchasedEvent = @"Purchased";
67+
NSString * const BNCShareInitiatedEvent = @"Share Started";
68+
NSString * const BNCShareCompletedEvent = @"Share Completed";
69+
5970
@interface Branch() <BranchDeepLinkingControllerCompletionDelegate, FABKit>
6071

6172

Branch-SDK/Branch-SDK/BranchUniversalObject.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111

1212
@class BranchLinkProperties;
1313

14-
typedef void (^callback) ();
15-
typedef void (^shareCompletion) (NSString *activityType, BOOL completed);
14+
typedef void (^shareCompletion) (NSString *_Nonnull activityType, BOOL completed);
1615

1716
typedef NS_ENUM(NSInteger, ContentIndexMode) {
1817
ContentIndexModePublic,
@@ -33,6 +32,9 @@ typedef NS_ENUM(NSInteger, ContentIndexMode) {
3332
@property (nonatomic, strong) NSArray *keywords;
3433
@property (nonatomic, strong) NSDate *expirationDate;
3534
@property (nonatomic, strong) NSString *spotlightIdentifier;
35+
@property (nonatomic, assign) CGFloat price;
36+
@property (nonatomic, strong) NSString *currency;
37+
3638

3739
- (instancetype)initWithCanonicalIdentifier:(NSString *)canonicalIdentifier;
3840
- (instancetype)initWithTitle:(NSString *)title;
@@ -42,6 +44,8 @@ typedef NS_ENUM(NSInteger, ContentIndexMode) {
4244
- (void)registerView;
4345
- (void)registerViewWithCallback:(callbackWithParams)callback;
4446

47+
- (void)userCompletedAction:(NSString *)action;
48+
4549
- (NSString *)getShortUrlWithLinkProperties:(BranchLinkProperties *)linkProperties;
4650
- (NSString *)getShortUrlWithLinkPropertiesAndIgnoreFirstClick:(BranchLinkProperties *)linkProperties;
4751
- (void)getShortUrlWithLinkProperties:(BranchLinkProperties *)linkProperties andCallback:(callbackWithUrl)callback;

Branch-SDK/Branch-SDK/BranchUniversalObject.m

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ - (void)registerViewWithCallback:(callbackWithParams)callback {
7474
[[Branch getInstance] registerViewWithParams:[self getParamsForServerRequest] andCallback:callback];
7575
}
7676

77+
- (void)userCompletedAction:(NSString *)action {
78+
NSMutableDictionary *actionPayload = [[NSMutableDictionary alloc] init];
79+
NSDictionary *linkParams = [self getParamsForServerRequest];
80+
actionPayload[BNCCanonicalIdList] = @[self.canonicalIdentifier];
81+
actionPayload[self.canonicalIdentifier] = linkParams;
82+
83+
[[Branch getInstance] userCompletedAction:action withState:actionPayload];
84+
}
85+
7786
#pragma mark - Link Creation Methods
7887

7988
- (NSString *)getShortUrlWithLinkProperties:(BranchLinkProperties *)linkProperties {
@@ -311,6 +320,12 @@ + (BranchUniversalObject *)getBranchUniversalObjectFromDictionary:(NSDictionary
311320
if (dictionary[BRANCH_LINK_DATA_KEY_KEYWORDS]) {
312321
universalObject.keywords = dictionary[BRANCH_LINK_DATA_KEY_KEYWORDS];
313322
}
323+
if (dictionary[BNCPurchaseAmount]) {
324+
universalObject.price = [dictionary[BNCPurchaseAmount] floatValue];
325+
}
326+
if (dictionary[BNCPurchaseCurrency]) {
327+
universalObject.currency = dictionary[BNCPurchaseCurrency];
328+
}
314329

315330
return universalObject;
316331
}
@@ -337,6 +352,12 @@ - (NSDictionary *)getParamsForServerRequest {
337352
[self safeSetValue:self.keywords forKey:BRANCH_LINK_DATA_KEY_KEYWORDS onDict:temp];
338353
[self safeSetValue:@(1000 * [self.expirationDate timeIntervalSince1970]) forKey:BRANCH_LINK_DATA_KEY_CONTENT_EXPIRATION_DATE onDict:temp];
339354
[self safeSetValue:self.type forKey:BRANCH_LINK_DATA_KEY_CONTENT_TYPE onDict:temp];
355+
[self safeSetValue:self.currency forKey:BNCPurchaseCurrency onDict:temp];
356+
if (self.price) {
357+
// have to add if statement because safeSetValue only accepts objects so even if self.price is not set
358+
// a valid NSNumber object will be created and the request will have amount:0 in all cases.
359+
[self safeSetValue:[NSNumber numberWithFloat:self.price] forKey:BNCPurchaseAmount onDict:temp];
360+
}
340361

341362
[temp addEntriesFromDictionary:[self.metadata copy]];
342363
return [temp copy];

Branch-SDK/Branch-SDK/Requests/BranchShortUrlRequest.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
@interface BranchShortUrlRequest : BNCServerRequest
1313

14+
@property (nonatomic, assign) BOOL isSpotlightRequest;
15+
1416
- (id)initWithTags:(NSArray *)tags alias:(NSString *)alias type:(BranchLinkType)type matchDuration:(NSInteger)duration channel:(NSString *)channel feature:(NSString *)feature stage:(NSString *)stage campaign:(NSString *)campaign params:(NSDictionary *)params linkData:(BNCLinkData *)linkData linkCache:(BNCLinkCache *)linkCache callback:(callbackWithUrl)callback;
1517

1618
@end

Branch-SDK/Branch-SDK/Requests/BranchShortUrlRequest.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ - (id)initWithTags:(NSArray *)tags alias:(NSString *)alias type:(BranchLinkType)
4444
_callback = callback;
4545
_linkCache = linkCache;
4646
_linkData = linkData;
47+
_isSpotlightRequest = NO;
4748
}
4849

4950
return self;
@@ -54,7 +55,10 @@ - (void)makeRequest:(BNCServerInterface *)serverInterface key:(NSString *)key ca
5455

5556
BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper preferenceHelper];
5657
params[BRANCH_REQUEST_KEY_DEVICE_FINGERPRINT_ID] = preferenceHelper.deviceFingerprintID;
57-
params[BRANCH_REQUEST_KEY_BRANCH_IDENTITY] = preferenceHelper.identityID;
58+
59+
if (!_isSpotlightRequest) {
60+
params[BRANCH_REQUEST_KEY_BRANCH_IDENTITY] = preferenceHelper.identityID;
61+
}
5862
params[BRANCH_REQUEST_KEY_SESSION_ID] = preferenceHelper.sessionID;
5963

6064
[serverInterface postRequest:params url:[preferenceHelper getAPIURL:BRANCH_REQUEST_ENDPOINT_GET_SHORT_URL] key:key callback:callback];

Branch-SDK/Branch-SDK/Requests/BranchSpotlightUrlRequest.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ - (id)initWithParams:(NSDictionary *)params callback:(callbackWithParams)callbac
2222
[linkData setupChannel:@"spotlight"];
2323

2424
if (self = [super initWithTags:nil alias:nil type:BranchLinkTypeUnlimitedUse matchDuration:0 channel:@"spotlight" feature:BRANCH_FEATURE_TAG_SHARE stage:nil campaign:nil params:params linkData:linkData linkCache:nil callback:nil]) {
25+
self.isSpotlightRequest = YES;
2526
_spotlightCallback = callback;
2627
}
27-
2828
return self;
2929
}
3030

Branch-TestBed/Branch-TestBed/ViewController.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ - (void)viewDidLoad {
5555
_branchUniversalObject.title = contentTitle;
5656
_branchUniversalObject.contentDescription = contentDescription;
5757
_branchUniversalObject.imageUrl = imageUrl;
58+
_branchUniversalObject.price = 1000;
59+
_branchUniversalObject.currency = @"$";
5860
[_branchUniversalObject addMetadataKey:@"deeplink_text" value:[NSString stringWithFormat:
5961
@"This text was embedded as data in a Branch link with the following characteristics:\n\n canonicalUrl: %@\n title: %@\n contentDescription: %@\n imageUrl: %@\n", canonicalUrl, contentTitle, contentDescription, imageUrl]];
6062
[self refreshRewardPoints];

0 commit comments

Comments
 (0)