@@ -3,7 +3,7 @@ import { ScrollView, StyleSheet, Text, View } from 'react-native'
33
44import Button from './Button'
55
6- import branch , { RegisterViewEvent } from 'react-native-branch'
6+ import branch , { RegisterViewEvent , BranchEvent } from 'react-native-branch'
77
88const 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