Skip to content

Commit 734583b

Browse files
author
Aaron Lopez
authored
Merge pull request #349 from sequoiaat/support-for-v2-events
Support for v2 events
2 parents 86d8fd6 + 0818b7e commit 734583b

File tree

2 files changed

+68
-4
lines changed

2 files changed

+68
-4
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -579,9 +579,9 @@ public static BranchEvent createBranchEvent(String eventName, ReadableMap params
579579
if (params.hasKey("shipping")) event.setShipping(Double.parseDouble(params.getString("shipping")));
580580
if (params.hasKey("tax")) event.setTax(Double.parseDouble(params.getString("tax")));
581581
if (params.hasKey("coupon")) event.setCoupon(params.getString("coupon"));
582-
if (params.hasKey("affiliation")) event.setTransactionID(params.getString("affiliation"));
583-
if (params.hasKey("description")) event.setTransactionID(params.getString("description"));
584-
if (params.hasKey("searchQuery")) event.setTransactionID(params.getString("searchQuery"));
582+
if (params.hasKey("affiliation")) event.setAffiliation(params.getString("affiliation"));
583+
if (params.hasKey("description")) event.setDescription(params.getString("description"));
584+
if (params.hasKey("searchQuery")) event.setSearchQuery(params.getString("searchQuery"));
585585

586586
if (params.hasKey("customData")) {
587587
ReadableMap customData = params.getMap("customData");

examples/testbed_simple/src/BranchMethods.js

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ScrollView, StyleSheet, Text, View } from 'react-native'
33

44
import Button from './Button'
55

6-
import branch, { RegisterViewEvent } from 'react-native-branch'
6+
import branch, { RegisterViewEvent, BranchEvent } from 'react-native-branch'
77

88
const defaultBUO = {
99
title: 'wallo'
@@ -154,6 +154,68 @@ class BranchMethods extends Component {
154154
}
155155
}
156156

157+
logStandardEvent = async () => {
158+
if (!this.buo) await this.createBranchUniversalObject()
159+
try {
160+
let branchEvent = new BranchEvent(
161+
BranchEvent.Purchase,
162+
this.buo,
163+
{
164+
transactionID: '12344555',
165+
currency: 'USD',
166+
revenue: 1.5,
167+
shipping: 10.2,
168+
tax: 12.3,
169+
coupon: 'test_coupon',
170+
affiliation: 'test_affiliation',
171+
description: 'Test purchase event',
172+
searchQuery: 'test keyword',
173+
customData: {
174+
"Custom_Event_Property_Key1": "Custom_Event_Property_val1",
175+
"Custom_Event_Property_Key2": "Custom_Event_Property_val2"
176+
}
177+
}
178+
)
179+
branchEvent.logEvent()
180+
181+
this.addResult('success', 'sendStandardEvent', branchEvent)
182+
} catch (err) {
183+
console.log('sendStandardEvent err', err)
184+
this.addResult('error', 'sendStandardEvent', err.toString())
185+
}
186+
}
187+
188+
logCustomEvent = async () => {
189+
if (!this.buo) await this.createBranchUniversalObject()
190+
try {
191+
let branchEvent = new BranchEvent(
192+
'Test Custom Event Name',
193+
this.buo,
194+
{
195+
transactionID: '12344555',
196+
currency: 'USD',
197+
revenue: 1.5,
198+
shipping: 10.2,
199+
tax: 12.3,
200+
coupon: 'test_coupon',
201+
affiliation: 'test_affiliation',
202+
description: 'Test purchase event',
203+
searchQuery: 'test keyword',
204+
customData: {
205+
"Custom_Event_Property_Key1": "Custom_Event_Property_val1",
206+
"Custom_Event_Property_Key2": "Custom_Event_Property_val2"
207+
}
208+
}
209+
)
210+
branchEvent.logEvent()
211+
212+
this.addResult('success', 'sendStandardEvent', branchEvent)
213+
} catch (err) {
214+
console.log('sendStandardEvent err', err)
215+
this.addResult('error', 'sendStandardEvent', err.toString())
216+
}
217+
}
218+
157219
addResult(type, slug, payload) {
158220
let result = { type, slug, payload }
159221
this.setState({
@@ -192,6 +254,8 @@ class BranchMethods extends Component {
192254
<Button onPress={this.redeemRewards.bind(this, 'testBucket')}>redeemRewards (with bucket)</Button>
193255
<Button onPress={this.loadRewards}>loadRewards</Button>
194256
<Button onPress={this.getCreditHistory}>getCreditHistory</Button>
257+
<Button onPress={this.logStandardEvent}>BranchEvent.logEvent (Standard)</Button>
258+
<Button onPress={this.logCustomEvent}>BranchEvent.logEvent (Custom)</Button>
195259
</ScrollView>
196260
</View>
197261
)

0 commit comments

Comments
 (0)