Skip to content

Commit e75e0ac

Browse files
authored
Merge pull request #594 from BranchMetrics/SDK-1045/add-standard-events
[SDK-1045] Additional standard v2 events
2 parents 148549f + 2656511 commit e75e0ac

File tree

6 files changed

+135
-2
lines changed

6 files changed

+135
-2
lines changed

android/src/main/java/io/branch/rnbranch/RNBranchModule.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ public class RNBranchModule extends ReactContextBaseJavaModule {
5555
private static final String STANDARD_EVENT_ADD_PAYMENT_INFO = "STANDARD_EVENT_ADD_PAYMENT_INFO";
5656
private static final String STANDARD_EVENT_PURCHASE = "STANDARD_EVENT_PURCHASE";
5757
private static final String STANDARD_EVENT_SPEND_CREDITS = "STANDARD_EVENT_SPEND_CREDITS";
58+
private static final String STANDARD_EVENT_VIEW_AD = "STANDARD_EVENT_VIEW_AD";
59+
private static final String STANDARD_EVENT_CLICK_AD = "STANDARD_EVENT_CLICK_AD";
5860

5961
private static final String STANDARD_EVENT_SEARCH = "STANDARD_EVENT_SEARCH";
6062
private static final String STANDARD_EVENT_VIEW_ITEM = "STANDARD_EVENT_VIEW_ITEM";
@@ -66,6 +68,11 @@ public class RNBranchModule extends ReactContextBaseJavaModule {
6668
private static final String STANDARD_EVENT_COMPLETE_TUTORIAL = "STANDARD_EVENT_COMPLETE_TUTORIAL";
6769
private static final String STANDARD_EVENT_ACHIEVE_LEVEL = "STANDARD_EVENT_ACHIEVE_LEVEL";
6870
private static final String STANDARD_EVENT_UNLOCK_ACHIEVEMENT = "STANDARD_EVENT_UNLOCK_ACHIEVEMENT";
71+
private static final String STANDARD_EVENT_INVITE = "STANDARD_EVENT_INVITE";
72+
private static final String STANDARD_EVENT_LOGIN = "STANDARD_EVENT_LOGIN";
73+
private static final String STANDARD_EVENT_RESERVE = "STANDARD_EVENT_RESERVE";
74+
private static final String STANDARD_EVENT_SUBSCRIBE = "STANDARD_EVENT_SUBSCRIBE";
75+
private static final String STANDARD_EVENT_START_TRIAL = "STANDARD_EVENT_START_TRIAL";
6976

7077
private static final String IDENT_FIELD_NAME = "ident";
7178
public static final String UNIVERSAL_OBJECT_NOT_FOUND_ERROR_CODE = "RNBranch::Error::BUONotFound";
@@ -266,6 +273,8 @@ public Map<String, Object> getConstants() {
266273
constants.put(STANDARD_EVENT_ADD_PAYMENT_INFO, BRANCH_STANDARD_EVENT.ADD_PAYMENT_INFO.getName());
267274
constants.put(STANDARD_EVENT_PURCHASE, BRANCH_STANDARD_EVENT.PURCHASE.getName());
268275
constants.put(STANDARD_EVENT_SPEND_CREDITS, BRANCH_STANDARD_EVENT.SPEND_CREDITS.getName());
276+
constants.put(STANDARD_EVENT_VIEW_AD, BRANCH_STANDARD_EVENT.VIEW_AD.getName());
277+
constants.put(STANDARD_EVENT_CLICK_AD, BRANCH_STANDARD_EVENT.CLICK_AD.getName());
269278

270279
// Content Events
271280

@@ -281,6 +290,11 @@ public Map<String, Object> getConstants() {
281290
constants.put(STANDARD_EVENT_COMPLETE_TUTORIAL , BRANCH_STANDARD_EVENT.COMPLETE_TUTORIAL.getName());
282291
constants.put(STANDARD_EVENT_ACHIEVE_LEVEL, BRANCH_STANDARD_EVENT.ACHIEVE_LEVEL.getName());
283292
constants.put(STANDARD_EVENT_UNLOCK_ACHIEVEMENT, BRANCH_STANDARD_EVENT.UNLOCK_ACHIEVEMENT.getName());
293+
constants.put(STANDARD_EVENT_INVITE, BRANCH_STANDARD_EVENT.INVITE.getName());
294+
constants.put(STANDARD_EVENT_LOGIN , BRANCH_STANDARD_EVENT.LOGIN.getName());
295+
constants.put(STANDARD_EVENT_RESERVE, BRANCH_STANDARD_EVENT.RESERVE.getName());
296+
constants.put(STANDARD_EVENT_SUBSCRIBE, BRANCH_STANDARD_EVENT.SUBSCRIBE.getName());
297+
constants.put(STANDARD_EVENT_START_TRIAL, BRANCH_STANDARD_EVENT.START_TRIAL.getName());
284298

285299
return constants;
286300
}

ios/RNBranch.m

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ + (void)setupBranchInstance:(Branch *)instance
113113
@"STANDARD_EVENT_ADD_PAYMENT_INFO": BranchStandardEventAddPaymentInfo,
114114
@"STANDARD_EVENT_PURCHASE": BranchStandardEventPurchase,
115115
@"STANDARD_EVENT_SPEND_CREDITS": BranchStandardEventSpendCredits,
116+
@"STANDARD_EVENT_VIEW_AD": BranchStandardEventViewAd,
117+
@"STANDARD_EVENT_CLICK_AD": BranchStandardEventClickAd,
116118

117119
// Content Events
118120
@"STANDARD_EVENT_SEARCH": BranchStandardEventSearch,
@@ -125,7 +127,12 @@ + (void)setupBranchInstance:(Branch *)instance
125127
@"STANDARD_EVENT_COMPLETE_REGISTRATION": BranchStandardEventCompleteRegistration,
126128
@"STANDARD_EVENT_COMPLETE_TUTORIAL": BranchStandardEventCompleteTutorial,
127129
@"STANDARD_EVENT_ACHIEVE_LEVEL": BranchStandardEventAchieveLevel,
128-
@"STANDARD_EVENT_UNLOCK_ACHIEVEMENT": BranchStandardEventUnlockAchievement
130+
@"STANDARD_EVENT_UNLOCK_ACHIEVEMENT": BranchStandardEventUnlockAchievement,
131+
@"STANDARD_EVENT_INVITE": BranchStandardEventInvite,
132+
@"STANDARD_EVENT_LOGIN": BranchStandardEventLogin,
133+
@"STANDARD_EVENT_RESERVE": BranchStandardEventReserve,
134+
@"STANDARD_EVENT_SUBSCRIBE": BranchStandardEventSubscribe,
135+
@"STANDARD_EVENT_START_TRIAL": BranchStandardEventStartTrial
129136
};
130137
}
131138

native-tests/ios/NativeTestsTests/RNBranchTests.m

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ - (void)testStandardRateEventConstant
9898
ASSERT_CONSTANT(@"STANDARD_EVENT_RATE", BranchStandardEventRate);
9999
}
100100

101-
- (void)testStandardRateEventShareConstant
101+
- (void)testStandardShareEventConstant
102102
{
103103
ASSERT_CONSTANT(@"STANDARD_EVENT_SHARE", BranchStandardEventShare);
104104
}
@@ -123,4 +123,39 @@ - (void)testStandardUnlockAchievementEventConstant
123123
ASSERT_CONSTANT(@"STANDARD_EVENT_UNLOCK_ACHIEVEMENT", BranchStandardEventUnlockAchievement);
124124
}
125125

126+
- (void)testStandardViewAdEventConstant
127+
{
128+
ASSERT_CONSTANT(@"STANDARD_EVENT_VIEW_AD", BranchStandardEventViewAd);
129+
}
130+
131+
- (void)testStandardClickAdEventConstant
132+
{
133+
ASSERT_CONSTANT(@"STANDARD_EVENT_CLICK_AD", BranchStandardEventClickAd);
134+
}
135+
136+
- (void)testStandardInviteEventConstant
137+
{
138+
ASSERT_CONSTANT(@"STANDARD_EVENT_INVITE", BranchStandardEventInvite);
139+
}
140+
141+
- (void)testStandardLoginEventConstant
142+
{
143+
ASSERT_CONSTANT(@"STANDARD_EVENT_LOGIN", BranchStandardEventLogin);
144+
}
145+
146+
- (void)testStandardSubscribeEventConstant
147+
{
148+
ASSERT_CONSTANT(@"STANDARD_EVENT_SUBSCRIBE", BranchStandardEventSubscribe);
149+
}
150+
151+
- (void)testStandardStartTrialEventConstant
152+
{
153+
ASSERT_CONSTANT(@"STANDARD_EVENT_START_TRIAL", BranchStandardEventStartTrial);
154+
}
155+
156+
- (void)testStandardReserveEventConstant
157+
{
158+
ASSERT_CONSTANT(@"STANDARD_EVENT_RESERVE", BranchStandardEventReserve);
159+
}
160+
126161
@end

src/BranchEvent.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,18 @@ BranchEvent.Purchase = RNBranch.STANDARD_EVENT_PURCHASE
243243
*/
244244
BranchEvent.SpendCredits = RNBranch.STANDARD_EVENT_SPEND_CREDITS
245245

246+
/**
247+
* Standard View Ad event
248+
* @type {string}
249+
*/
250+
BranchEvent.ViewAd = RNBranch.STANDARD_EVENT_VIEW_AD
251+
252+
/**
253+
* Standard Click Ad event
254+
* @type {string}
255+
*/
256+
BranchEvent.ClickAd = RNBranch.STANDARD_EVENT_CLICK_AD
257+
246258
// Content events
247259

248260
/**
@@ -300,3 +312,33 @@ BranchEvent.AchieveLevel = RNBranch.STANDARD_EVENT_ACHIEVE_LEVEL
300312
* @type {string}
301313
*/
302314
BranchEvent.UnlockAchievement = RNBranch.STANDARD_EVENT_UNLOCK_ACHIEVEMENT
315+
316+
/**
317+
* Standard Invite event
318+
* @type {string}
319+
*/
320+
BranchEvent.Invite = RNBranch.STANDARD_EVENT_INVITE
321+
322+
/**
323+
* Standard Login event
324+
* @type {string}
325+
*/
326+
BranchEvent.Login = RNBranch.STANDARD_EVENT_LOGIN
327+
328+
/**
329+
* Standard Reserve event
330+
* @type {string}
331+
*/
332+
BranchEvent.Reserve = RNBranch.STANDARD_EVENT_RESERVE
333+
334+
/**
335+
* Standard Subscribe event
336+
* @type {string}
337+
*/
338+
BranchEvent.Subscribe = RNBranch.STANDARD_EVENT_SUBSCRIBE
339+
340+
/**
341+
* Standard Start Trial event
342+
* @type {string}
343+
*/
344+
BranchEvent.StartTrial = RNBranch.STANDARD_EVENT_START_TRIAL

test/BranchEvent.test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,34 @@ test('UnlockAchievement is correct', () => {
6868
expect(BranchEvent.UnlockAchievement).toBe(RNBranch.STANDARD_EVENT_UNLOCK_ACHIEVEMENT)
6969
})
7070

71+
test('ViewAd is correct', () => {
72+
expect(BranchEvent.ViewAd).toBe(RNBranch.STANDARD_EVENT_VIEW_AD)
73+
})
74+
75+
test('ClickAd is correct', () => {
76+
expect(BranchEvent.ClickAd).toBe(RNBranch.STANDARD_EVENT_CLICK_AD)
77+
})
78+
79+
test('Invite is correct', () => {
80+
expect(BranchEvent.Invite).toBe(RNBranch.STANDARD_EVENT_INVITE)
81+
})
82+
83+
test('Login is correct', () => {
84+
expect(BranchEvent.Login).toBe(RNBranch.STANDARD_EVENT_LOGIN)
85+
})
86+
87+
test('Reserve is correct', () => {
88+
expect(BranchEvent.Reserve).toBe(RNBranch.STANDARD_EVENT_RESERVE)
89+
})
90+
91+
test('Subscribe is correct', () => {
92+
expect(BranchEvent.Subscribe).toBe(RNBranch.STANDARD_EVENT_SUBSCRIBE)
93+
})
94+
95+
test('StartTrial is correct', () => {
96+
expect(BranchEvent.StartTrial).toBe(RNBranch.STANDARD_EVENT_START_TRIAL)
97+
})
98+
7199
// --- Field mapping
72100

73101
test('Name mapping is correct', () => {

test/RNBranchMock.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ NativeModules.RNBranch = {
1212
STANDARD_EVENT_ADD_PAYMENT_INFO: 'ADD_PAYMENT_INFO',
1313
STANDARD_EVENT_PURCHASE: 'PURCHASE',
1414
STANDARD_EVENT_SPEND_CREDITS: 'SPEND_CREDITS',
15+
STANDARD_EVENT_VIEW_AD: 'VIEW_AD',
16+
STANDARD_EVENT_CLICK_AD: 'CLICK_AD',
1517

1618
STANDARD_EVENT_SEARCH: 'SEARCH',
1719
STANDARD_EVENT_VIEW_ITEM: 'VIEW_ITEM',
@@ -23,6 +25,11 @@ NativeModules.RNBranch = {
2325
STANDARD_EVENT_COMPLETE_TUTORIAL: 'COMPLETE_TUTORIAL',
2426
STANDARD_EVENT_ACHIEVE_LEVEL: 'ACHIEVE_LEVEL',
2527
STANDARD_EVENT_UNLOCK_ACHIEVEMENT: 'UNLOCK_ACHIEVEMENT',
28+
STANDARD_EVENT_INVITE: 'INVITE',
29+
STANDARD_EVENT_LOGIN: 'LOGIN',
30+
STANDARD_EVENT_RESERVE: 'RESERVE',
31+
STANDARD_EVENT_SUBSCRIBE: 'SUBSCRIBE',
32+
STANDARD_EVENT_START_TRIAL: 'START_TRIAL',
2633

2734
redeemInitSessionResult: jest.fn(() => Promise.resolve({
2835
params: {

0 commit comments

Comments
 (0)